//var hm_buttons = new Array('hm_portal', 'hm_forum', 'hm_encyclopedia', 'hm_phones');
var hm_buttons= new Array('hm_portal','hm_forum','hm_phones');
var search_defvalue = 'szukany tekst';
var spacer_image = 'http://www.pasjagsm.pl/smarty/templates/img/spacer.gif';
var old_write;

function btnOver(what)
{
	el = $(what);
	el.src = spacer_image;
}

function btnOut(what)
{
	el = $(what);
	el.src = el.org_src;
}

// <a href=...><img id="button"></a>
function btnPrepare(button)
{
	img = $(button);
	img.parentNode.style.display = 'block';
	img.parentNode.style.width = img.clientWidth + 'px';
	img.parentNode.style.height = img.clientHeight + 'px';
	img.style.width = img.clientWidth + 'px';
	img.style.height = img.clientHeight + 'px';
	img.org_src = img.src;
	img.style.background = 'url(' + img.src.replace('_std', '_hl') + ')';
	Event.observe(img, 'mouseover', function(){btnOver(button)}, false);
	Event.observe(img, 'mouseout', function(){btnOut(button)}, false);
}

function pasjaInit()
{
	layoutRedraw();
	for (i = 0; i < hm_buttons.length; i++)
		btnPrepare(hm_buttons[i]);

	searchf = $('head_search_field');
	if (searchf.value == '' || searchf.value == search_defvalue)
	{
		searchf.value = search_defvalue;
	}
	Event.observe(searchf, 'focus', function(){
		// long live stupid IE which gives incorrect this object
		field = $('head_search_field');
		if (field.value == search_defvalue)
			field.value = '';
		field.style.background = '#FDFACC';
		}, false);
	Event.observe(searchf, 'blur', function(){
		field = $('head_search_field');
		if (field.value == '')
			field.value = search_defvalue;
		field.style.background = '';
		}, false);
	if ($('nick'))
	{
		Event.observe($('nick'), 'keyup', nick_keyup, false);
		opinion_keyup();
		Event.observe($('opinion'), 'keyup', opinion_keyup, false);
	}
}

function layoutRedraw()
{
	c_left = $('col_left');
	c_mid = $('col_mid');
	c_blocks = $('col_blocks');

	maxh = c_left.offsetHeight;

	if (maxh < c_left.offsetHeight)
		maxh = c_left.offsetHeight;
	if (c_mid && maxh < c_mid.offsetHeight)
		maxh = c_mid.offsetHeight;
	if (c_blocks && maxh < c_blocks.offsetHeight)
		maxh = c_blocks.offsetHeight;

	$('contents').style.height = maxh+'px';
}

function write_replace(write_target)
{
	old_write = document.write;
	document.write = function (s) {
		$(write_target).innerHTML = $(write_target).innerHTML + s;
	}
}

function write_restore()
{
	document.write = old_write;
}

Event.observe(window, 'load', pasjaInit, false);

