// Xander Zerge web site engine script. Copyright 2004-2006 by Xander Zerge. All rights reserved.
// Usage of any kind of this source code without written permission from Xander Zerge is strictly prohibited.

var leftblockscount = 0, rightblockscount = 0;

function equalizeBlocks()
{
	var lefth = 0, righth = 0, i;
	for( i = 0; i < leftblockscount; i++ )
	{	
		lefth += document.getElementById( "leftblock" + i + "x" ).offsetHeight;
	}
	for( i = 0; i < rightblockscount; i++ )
	{
		righth += document.getElementById( "rightblock" + i + "x" ).offsetHeight;
	}
	var q = 1, cnt = -1, nm = "", tgt = 0;
	if( lefth > righth )
	{
		q = lefth / righth;
		cnt = rightblockscount - 1;
		nm = "rightblock";
		tgt = lefth;
	}
	else if( lefth < righth )
	{
		q = righth / lefth;
		cnt = leftblockscount - 1;
		nm = "leftblock";
		tgt = righth;
	}
	if( cnt >= 0 )
	{
		var h, hh, nh, act = 0;
		for( i = 0; i <= cnt; i++ )
		{
			h = document.getElementById( nm + i + "x" ).offsetHeight;
			hh = document.getElementById( nm + i ).offsetHeight;
			nh = i < cnt ? Math.floor( h * q + 0.5 ) : tgt - act;
			act += nh;
			document.getElementById( nm + i ).style.height = ( hh + nh - h ) + "px";
		}
	}
}

// show popup image for screenshot
function openPopup(addr,w,h) {
	open(addr,'_blank','height='+h+',width='+w+',location=no,menubar=no,resizable=no,scrollbars=no,status=0,toolbar=no,left=50,top=50');
}

var butname = "";
var butcount = 0;

// register buttons
function registerButtons( name )
{
	butname	= name;
	butcount	= document.images.length;
}

// revert all buttons to normal state
function buttonRevert()
{
	var i;
	for( i = 0; i < butcount; i++ )
	{
		var img = document.images[i];
		if( img.name == butname )
		{
			img.className = "normal";
		}
	}
}

// process button event onMouseOver
function buttonOver( img )
{
	buttonRevert();
	img.className = "hover";
}

// process button event onMouseOut
function buttonOut( img )
{
	img.className = img.className == "hover" ? "normal" : "down";
}

// process button event onMouseDown
function buttonDown( imgsrc )
{
	buttonRevert();
	imgsrc.className = "active";
}

// process button event onMouseUp
function buttonUp( img )
{
	buttonRevert();
	img.className = "active";
}
