if(!document.getElementById)
{
	if(document.all)
	{
		accessObj = function()
		{
			if(typeof document.all[arguments[0]]!="undefined")
			return document.all[arguments[0]]
			else
			return null
		}
	}
	else if(document.layers)
	{
		accessObj = function()
		{
			if(typeof document[arguments[0]]!="undefined")
			return document[arguments[0]]
			else
			return null
		}
	}
}
else
{
	accessObj = function()
	{
		return document.getElementById(arguments[0]);
	}
}

function setOpacity(objname, o)
{
	var obj = accessObj(objname);
	var per = o / 100;
	if (o < 0)
	{
		o = 0;
		per = 0;
	}
	if (o>100)
	{
		o = 100;
		per = 1;
	}
    obj.style.opacity = (per);
    obj.style.MozOpacity = (per);
    obj.style.KhtmlOpacity = (per);
    obj.style.filter = 'alpha(opacity=' + o + ')';
}

function openDiv(name)
{
	var obj = accessObj(name);
	if (!isNull(obj))
		obj.style.display = "block";
}

function closeDiv(name)
{
	var obj = accessObj(name);
	if (!isNull(obj))
		obj.style.display = "none";
}

function isNull(val)
{
	return(val==null);
}


var start_w = 100;
var start_h = 100;
var start_t = 0;
var current_w = 0;
var current_h = 0;
var current_t = 0;
var step_w = 1;
var step_h = 1;
var step_t = 1;
var final_w = 0;
var final_h = 0;
var final_t = 0;
var myInterval;
var intDelay = 1;
var step = 35;
var current_link = "";
var win_inside;
var win_header;
var win_top;
var win_footer;
var win_cHolder;
/*var win_iframe;*/
var win_open = false;


function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight + 150];
	}




function openLayer(link, width, height)
{
	/*if (link.substring(link.length-3) == "swf")
		link = "swf.php?url="+link;*/

	var main = accessObj("win");
	arrayPageSize = this.getPageSize();
	$('background').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	openDiv("background");
	setOpacity("background", 85);

	if (!win_inside)
		win_inside = accessObj("wininside");
	if (!win_header)
		win_header = accessObj("winheader");
	if (!win_footer)
		win_footer = accessObj("winfooter");
	if (!win_top)
		win_top = accessObj("wintop");

	if (!win_cHolder)
		win_cHolder = accessObj("wintop");

	/*if (!win_iframe)
	{
		win_iframe = accessObj("iframe");
		win_iframe.style.display = "none";
	}*/

	// width += 34;

	current_link = link;

	main.style.display = "block";

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	// alert(myHeight +" "+height)

	if (myHeight - 50 < height)
		height = myHeight - 50;

	if (myWidth - 50 < width)
		width = myWidth - 50;

	var topPad = (myHeight - height - 40) / 2;
	if (topPad < 0)
		topPad = 0;
	var startTopPad = (myHeight - start_h - 40) / 2;
	if (startTopPad < 0)
		startTopPad = 0;

	current_w = start_w;
	current_h = start_h;
	current_t = startTopPad;

	final_w = width;
	final_h = height;
	final_t = topPad;

	step_w = (current_w < final_w) ? step : -1 * step;
	step_h = (current_h < final_h) ? step : -1 * step;
	step_t = (current_t < final_t) ? step / 2 : -0.5 * step;

	win_header.style.width = current_w+"px";
	win_header.style.paddingTop = current_t+"px";

	win_inside.style.width = current_w+"px";
	win_inside.style.height = current_h+"px";
	

	var t_current_w = current_w + 36;

	win_footer.style.width = t_current_w+"px";
	win_top.style.width = t_current_w+"px";
	win_cHolder.style.width = t_current_w+"px";

	/*win_iframe.style.width = current_w+"px";
	win_iframe.style.height = current_h+"px";*/

	myInterval = setInterval("animateFrame_step1()", intDelay);
}

function animateFrame_step1()
{
	if (current_w != final_w)
	{
		current_w = current_w + step_w;
		if (current_w > final_w)
			current_w = final_w;
	}

	var t_current_w = current_w + 36;

	win_header.style.width = t_current_w+"px";
	win_inside.style.width = current_w+"px";
	win_footer.style.width = t_current_w+"px";
	win_top.style.width = t_current_w+"px";
	win_cHolder.style.width = t_current_w+"px";

	if (current_w == final_w)
	{
		clearInterval(myInterval);
		myInterval = setInterval("animateFrame_step2()", intDelay);
	}
}

function animateFrame_step2()
{
	if (current_h != final_h)
	{
		current_h = current_h + step_h;
		if (current_h > final_h)
			current_h = final_h;
	}

	if (current_t != final_t)
	{
		current_t = current_t + step_t;
		if ((current_t > final_t && step_t > 0) || (current_t < final_t && step_t < 0))
			current_t = final_t;
	}

	win_inside.style.height = current_h+"px";
	win_header.style.paddingTop = current_t+"px";

	if (current_h == final_h && current_t == final_t)
	{
		/*win_iframe.style.width = current_w+"px";
		win_iframe.style.height = current_h+"px";
		win_iframe.src = current_link;
		win_iframe.style.display = "block";*/
		win_inside.innerHTML="<img src=\""+current_link+"\">"; 
		win_open = true;
		clearInterval(myInterval);
	}

}

function accessSWF(movieName)
{
	if (navigator.appName.indexOf ("Microsoft") !=-1)
		return window[movieName];
	else
		return document[movieName];
}

function closeLayer()
{
	var main = accessObj("win");
	main.style.display = "none";
	main = accessObj("background");
	main.style.display = "none";
	clearInterval(myInterval);
	win_inside.innerHTML="";
	
	/*win_iframe.src = "empty.html";
	win_iframe.style.display = "none";*/
	//accessSWF("Ellipsis_Media").SetVariable("popupClosed", true);
	try {
	    accessSWF("Ellipsis_Media").SetVariable("allowMove", true);
	} catch (err) { }

	win_open = false;
}

function resizePopup() {
	if (win_open)
	{
		
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' )
		{
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}

		// alert(myHeight +" "+height)

		if (myHeight - 50 < final_h)
			final_h = myHeight - 50;

		if (myWidth - 50 < final_w)
			final_w = myWidth - 50;

		var topPad = (myHeight - final_h - 40) / 2;
		if (topPad < 0)
			topPad = 0;

		var t_final_w = final_w + 36;

		win_header.style.width = t_final_w+"px";
		win_inside.style.width = final_w+"px";
		win_inside.style.height = final_h+"px";
		win_footer.style.width = t_final_w+"px";
		win_cHolder.style.width = t_final_w+"px";
		win_top.style.width = t_final_w+"px";
		win_header.style.paddingTop = topPad+"px";
		/*win_iframe.style.width = final_w+"px";*/
		/*win_iframe.style.height = final_h+"px";*/
	}
}
