var toogles = Array();

var show = function(id)
{
	document.getElementById(id).style.display = 'inline-block';
	toogles[id] = true;
}

var hide = function(id)
{
	document.getElementById(id).style.display = 'none';
	toogles[id] = false;
}

var toogle = function(id,bel)
{
	if (toogles[id] == null)
	{
		toogles[id] = true;
		if (bel)
		{
			ob(bel,function(){omo(id,function(){hide(id);})});
		}
	}
	else
	{
		toogles[id] = (!toogles[id]);
	}
	
	if(toogles[id])
	{
		show(id);
	}
	else
	{
		hide(id);
	}
}

var backs = Array();
var backgroundToogle = function(id,img)
{
	el = document.getElementById(id);
	if (backs[id] == null)
	{
		backs[id] = Array();
		backs[id]['def'] = el.style.backgroundImage;
		backs[id]['new'] = true;
	}
	else
	{
		backs[id]['new'] = !backs[id]['new'];
	}
	if (backs[id]['new'])
	{
		el.style.backgroundImage = 'url(/images/' + img + ')';
	}
	else
	{
		el.style.backgroundImage = backs[id]['def'];
	}
}

var blocks = Array();
var textReplacer = function(id,text,style)
{
	var color = '#333';
	var element = document.getElementById(id);
	element.value = text;
	
	if (blocks[id] == null)
	{
		blocks[id] = element.style.color;
	}
	
	element.onfocus = function()
	{
		if (element.value == text)
		{
			element.value = '';
			if (color != null)
			{
				element.style.color = color;
			}
			if (style != null)
			{
				element.style.fontStyle = 'normal';
			}
		}
	}
	element.onblur = function()
	{
		if (element.value == '')
		{
			element.value = text;
			element.style.color = blocks[id];
			if (style != null)
			{
				element.style.fontStyle = 'italic';
			}
		}
	}
}

var oc = function(id,func)
{
	document.getElementById(id).onclick = func;
}

var oce = function(id,func)
{
	document.getElementById(id).onchange = func;
}

var ob = function(id,func)
{
	document.getElementById(id).onblur = func;
}

var omo = function(id,func)
{
	document.getElementById(id).onmouseout = func;
}

var oku = function(id,func)
{
	document.getElementById(id).onkeyup = func;
}

var searchReplacer = function()
{
	textReplacer('search','(Поиск в портфолио)',true);
}

window.onload = function()
{
	searchReplacer();
}