var lb = null;
var closeTimer=null;
function fSendToLightBox(link, width, height)
{			  
	 if(lb ==  null)
		lb = new  DLightBox(width, height);
	lb.show_box(link);
	lb.frame.style.overflow = "hidden";	
}

function fSendToLightBoxFrameOverFlowY(link, width, height)
{	
	if(lb ==  null)
	    lb = new  DLightBox(width, height);
	lb.show_box(link);
	lb.frame.style.overflow = "hidden";	
}

function fHideLightBox()
{
	 if(lb ==  null)
		return;
	lb.hide_box();
	myd_checkCookieUserName();
}

function DLightBox_WindowSize()
{
	if (navigator.appName=="Netscape")
	{
		var winW = window.innerWidth;
		var winH = window.innerHeight;
	}
	else
	{
		var winW = document.body.offsetWidth;
		var winH = document.body.offsetHeight;
	}
	return [winW,winH];
}

function DLightBox_Size(width, height)
{
	this.contentDiv = document.getElementById("lightBoxContent");		
	this.contentDiv.style.width = width +"px";
	this.contentDiv.style.height = height +"px";
	var DLightBox_windowSize = DLightBox_WindowSize();
	this.contentDiv.style.left = ((DLightBox_windowSize[0] - width)/2) + 'px';
	var top = ((DLightBox_windowSize[1] - height)/2)
	this.contentDiv.style.top = (top > 0)?  top : 0 + 'px';
}

function DLightBox(width, height)
{
	this.contentDiv = document.getElementById("lightBoxContent");		
	this.bDiv = document.getElementById("lightBox");
	this.frame = document.getElementById("lightBoxFrame");
	DLightBox_Size(width, height);
	this.selectInputs = document.getElementsByTagName("SELECT");
	this.timer=null;
}

DLightBox.prototype.show_box = function(link)
{	
	this.bDiv.style.display = "block";
	this.frame.src = link;
	this.contentDiv.style.display = "block";
	slc = this.selectInputs;
	var i=0;
	for(i=0;i<slc.length;i++)
	{
		slc[i].style.visibility="hidden";
	}
	this.contentDiv.innerHTML = '';
	this.contentDiv.appendChild(this.frame);
	
	 
}
DLightBox.prototype.hide_box = function()
{	 
	 this.bDiv.style.display = "none";
	 this.contentDiv.style.display = "none";
	 slc = this.selectInputs;
	 var i=0;
	 var oThis = this;
	 for(i=0;i<slc.length;i++)
	{
		slc[i].style.visibility="visible";
	}
}
 DLightBox.prototype.close_tmp = function()
 {
	var box = 	lb.contentDiv;
	box.filters[0].apply();
	box.innerHTML ="<div class='fltt'></div>";
	//alert(lb.frame);	
	box.filters[0].play(3);
	timer = setInterval(lb.close_box,8);   
	
	
 }
 DLightBox.prototype.close_box = function()
 {
	 var box = 	lb.contentDiv;
	 if(box.offsetHeight>20)
	 {
			box.style.height = (box.offsetHeight - 20) + 'px';
	 }
	 else
	 {
		 
		lb.hide_box();
		clearInterval(timer);
		timer = null;
		box.style.height = '450px';
	 }
 }

 var timer = null;
 function close_box()
 {
	// timer = setInterval(lb.close_box,2);
	lb.close_tmp();
	myd_checkCookieUserName();
 }

function lightBox_checkCookie(link, width, height)
{
	if (myd_getCookie("loginUserName"))
	{
		fSendToLightBox(link, width, height);
	}
	else
	{
		fSendToLightBox('/?page=Addon-MyD-Login', width, height);
	}
}
