// open centered popup window
var popupWindows = new Array();

function popupWindow(href, name, width, height) 
{
	for (var i = 0; i < popupWindows.length; i++)
	{
		if (popupWindows[i][0] == name && popupWindows[i][1].closed == false) 
		{
			popupWindows[i][1].focus();
			return false;
		}
	}
	
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var windowFeatures = "width=" + width + ",height=" + height + ",status=0,resizable=0,location=0,menubar=0,scrollbars=1, titlebar=0, toolbar=0,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
	
	var index = popupWindows.length;
	popupWindows[index] = new Array();
		
	popupWindows[index][0] = name;
	popupWindows[index][1] = window.open(href, name, windowFeatures);
}

// open centered image window
var imgWindows = new Array();
function openCenteredWindow(dir, name, title, width, height) 
{
	for (var i = 0; i < imgWindows.length; i++)
	{
		if (imgWindows[i][0] == name && imgWindows[i][1].closed == false) 
		{
			imgWindows[i][1].focus();
			return false;
		}
	}
				
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var windowFeatures = "width=" + width + ",height=" + height + ",status=0,resizable=0,location=0,menubar=0,scrollbars=0, titlebar=0, toolbar=0,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
	
	var index = imgWindows.length;
	imgWindows[index] = new Array();

	imgWindows[index][0] = name;
	
	var win_name = name.split(".");
	win_name = win_name[0].toString();
	win_name = win_name.replace("[", "_");
	win_name = win_name.replace("]", "");
	win_name = win_name.replace("-", "_");
	
	imgWindows[index][1] = window.open('', win_name, windowFeatures);
	
	imgWindows[index][1].document.write("<TITLE>" + title + "</TITLE><style>body{margin:0px;padding:0px}</style>");
	imgWindows[index][1].document.write("<BODY><TABLE border=0 width=100% height=100% cellPadding=0 cellSpacing=0><TR><TD align='center' valign='middle'><img border='0' src='"+ dir + "/" + name +"'></TD></TR></TABLE></BODY>");
	imgWindows[index][1].document.close();
}


// FADE
var s, c1, c2, r1, g1, b1, r2, g2, b2;
var fTimeout, fObj, fSteps = 25, fDelay = 10;

function Fade(obj, color1, color2) 
{
	if (fTimeout) 
	{
		clearTimeout(fTimeout);
		if (fObj)
		{
			fObj.style.color = "#" + c2;
			//fObj.style.color = "#F0F";
		}
	}
	fObj = obj; c1 = color1; c2 = color2;
	r1 = eval('0x' + c1.substring(0,2));
	g1 = eval('0x' + c1.substring(2,4));
	b1 = eval('0x' + c1.substring(4,6));
	r2 = eval('0x' + c2.substring(0,2));
	g2 = eval('0x' + c2.substring(2,4));
	b2 = eval('0x' + c2.substring(4,6));
	s = 0;
	DoFade();
}

function DoFade() 
{
	var d = s/fSteps, m = 1 - d;
	fObj.style.color = "#" +
	Dec2Hex(r1 * m + r2 * d) +
	Dec2Hex(g1 * m + g2 * d) +
	Dec2Hex(b1 * m + b2 * d);
	if (s < fSteps) fTimeout = setTimeout('DoFade()', fDelay);
	s++;
}

function Dec2Hex(Dec) 
{
	var hexChars = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
	var a = parseInt(Dec) % 16, b = (parseInt(Dec) - a)/16;
	var hex = "" + hexChars[b] + hexChars[a];
	return hex;
}