// JavaScript Document

var animation = false;
var orWdt = 650;
var orHgt = 300;
var delta;
var popup;

var winW;
var winH;

var scroll_top;
//alert(typeof(window.innerWidth));
if(typeof(window.innerWidth) == 'number') 
{
	//Non-IE
	winW = window.screen.width;
	winH = window.screen.height;
}
else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
{
	//IE 6+ in 'standards compliant mode'
	winW = document.documentElement.clientWidth;
	winH = document.documentElement.clientHeight;
}
else if(document.body && (document.body.clientWidth || document.body.clientHeight)) 
{
	//IE 4 compatible
	winW = document.body.clientWidth;
	winH = document.body.clientHeight;
}

function subMenu(menu, obj, flag)
{
	var div = document.getElementById(menu);
	popup = div;
	
	/*var lPos = winW / 2 - orWdt / 2;
	var tPos = winH / 2 - orHgt / 2;
	
	//alert(winW + "\n" + orWdt);
	
	scroll_top = getScrollingPosition()[1];*/
	
	//var wdt = 1;
	//var hgt = 1;
	
	if(flag)
	{
		div.style.display = "block";
		div.style.position = "absolute";
		
		orWdt = div.clientWidth;
		orHgt = div.clientHeight;
		
	//	alert(winW + "\n" + orWdt);
		
		var lPos = parseInt(winW / 2 - orWdt / 2);
		var tPos = parseInt(winH / 2 - orHgt / 2);
		
		scroll_top = getScrollingPosition()[1];
		
		div.style.left = lPos + "px";
		div.style.top = (tPos + scroll_top) + "px";
		
		/*if(!animation)
		{
			delta = (orWdt > orHgt) ? (orWdt / orHgt) : (orHgt / orWdt);
			
			div.style.width = wdt + "px";
			div.style.height = hgt + "px";
			
			animation = true;
			
			openId = window.setInterval(openMenu, 2);
		}*/
	}
	else
	{
		//div.style.width = wdt + "px";
		//div.style.height = hgt + "px";
		div.style.display = "none";
	}
}

function custom_display(menu, obj, flag,top_px,left_px)
{
	var div = document.getElementById(menu);
	popup = div;
	
	/*var lPos = winW / 2 - orWdt / 2;
	var tPos = winH / 2 - orHgt / 2;
	
	//alert(winW + "\n" + orWdt);
	
	scroll_top = getScrollingPosition()[1];*/
	
	//var wdt = 1;
	//var hgt = 1;
	
	if(flag)
	{
		div.style.display = "block";
		div.style.position = "absolute";
		
		orWdt = div.clientWidth;
		orHgt = div.clientHeight;
		
	//	alert(winW + "\n" + orWdt);
		
		var lPos = parseInt(winW / 2 - orWdt / 2);
		var tPos = parseInt(winH / 2 - orHgt / 2);
		var fleft;
		var ftop;
		//alert(lPos);
		scroll_top = getScrollingPosition()[1];
		//alert(lPos + left_px + "px");
		fleft = parseInt(lPos) + parseInt(left_px); 
		ftop  = parseInt(tPos) + parseInt(scroll_top) +parseInt(top_px);
		
		//alert(fleft);
		//alert(ftop);
		
		div.style.left = fleft + "px";
		div.style.top  = ftop  + "px";
		
		/*if(!animation)
		{
			delta = (orWdt > orHgt) ? (orWdt / orHgt) : (orHgt / orWdt);
			
			div.style.width = wdt + "px";
			div.style.height = hgt + "px";
			
			animation = true;
			
			openId = window.setInterval(openMenu, 2);
		}*/
	}
	else
	{
		//div.style.width = wdt + "px";
		//div.style.height = hgt + "px";
		div.style.display = "none";
	}
}


function openMenu()
{
	if(parseInt(popup.clientWidth) >= orWdt)
	{
		animation = false;
		clearInterval(openId);
	}
	
	if(orWdt > orHgt)
	{
		popup.style.width = parseInt(popup.clientWidth) + 20 * delta + "px";
		popup.style.height = parseInt(popup.clientHeight) + 20 * 1 + "px";
		
		popup.style.left = winW / 2 - ((parseInt(popup.clientWidth) + 20 * delta) / 2) + "px";
		popup.style.top = winH / 2 - ((parseInt(popup.clientHeight) + 20 * 1) / 2) + scroll_top + "px";
	}
	else
	{
		popup.style.width = parseInt(popup.style.width) + 20 * 1 + "px";
		popup.style.height = parseInt(popup.style.height) + 20 * delta + "px";
		
		popup.style.left = winW / 2 - ((parseInt(popup.clientWidth) + 20 * 1) / 2) + "px";
		popup.style.top = winH / 2 - ((parseInt(popup.clientHeight) + 20 * delta) / 2 + scroll_top) + "px";
	}
}

function getScrollingPosition()
{
	var position = [0, 0];
	
	if (typeof window.pageYOffset != 'undefined')
	{
		position = [
		window.pageXOffset,
		window.pageYOffset
		];
	}
	
	else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0)
	{
		position = [
		document.documentElement.scrollLeft,
		document.documentElement.scrollTop
		];
	}
	else if (typeof document.body.scrollTop != 'undefined')
	{
		position = [
		   document.body.scrollLeft,
		   document.body.scrollTop
		];
	}

	return position;
}
function preloadImages()
{
	var img = new Array();
	
	for(var i = 0; i < arguments.length; i++)
	{
		img[img.length] = new Image;
		img[img.length - 1].src = arguments[i];
	}
}
function getIEVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}