//function popupTimer()
function lightboxTimer(obj, height, width, textFont, textColor, backColor, borderColor, borderStyle, borderWidth, text, closeButton, guid, time, alertTime, backImage, backdropImage)
{
        //predefined variables
	this.myGlide = null;
	this.glideIdName = '_jh_light_float_box';
	this.timerLabel = '_jh_light_time_label';
	this.cookieShowLabel = 'jh_light_show_label_';

	//user defined variables
	this.objName = obj;
	if (navigator.appName.indexOf("Microsoft")!=-1)
	{
		if(detectDoctype() == null)
		{
			this.top = parseInt((document.body.clientHeight - height) / 2);
			this.left = parseInt((document.body.clientWidth - width) / 2);
		}
		else
		{
			this.top = parseInt((document.documentElement.clientHeight - height) / 2);
			this.left = parseInt((document.documentElement.clientWidth - width) / 2);
		}
	}
	else
	{
		this.top = parseInt((window.innerHeight - height) / 2);
		this.left = parseInt((window.innerWidth - width) / 2);
	}
	this.height = height;
	this.width = width;
	this.textFont = textFont;
	this.textColor = textColor;
	this.backColor = backColor;
	this.borderColor = borderColor;
	this.borderStyle = borderStyle;
	this.borderWidth = borderWidth;
	this.text = text;
	this.closeButton = closeButton;
	this.guid = guid;
	this.timeLimit = time * 60000;
	this.alertTime = alertTime * 60000;
	this.backgroundImage = backImage;
	this.backdropImage = backdropImage;
	
	//class variables
	this.floatPopup = false;  //allows float box to glide, disabled
	this.lastSec = null;
	this.currentTime = null;
	this.intervalUpdateTime = null;
	this.isIE6 = false;
	this.alertShowTime = true;
	this.alertTimeHolder = 0;
	this.oldOverflow = null;
	this.oldScroll=null;
	var arVersion = navigator.appVersion.split("MSIE")
  	var version = parseFloat(arVersion[1])
	if (navigator.appVersion.indexOf("MSIE") != -1 && (version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		this.isIE6 = true;
	}
	//initialization functions
	if(this.checkShowPopup())
	{
		this.startTime = this.getTime();
		this.updateTime();
		this.makeGliderHolder();
		if(this.floatPopup)
		{
			this.setGliding();
		}
		this.intervalUpdateTime = setInterval(this.objName + ".updateTime()",100);
	}
}

lightboxTimer.prototype.makeCloseButton = function(parent)
{
	var newdiv = document.createElement('div');

	newdiv.setAttribute('id',this.glideIdName + "_close");
	newdiv.innerHTML = "<a style='color:" + this.closeButton + ";' href='javascript:" + this.objName + ".destroyGliderHolder();'>[close]</a>";
	newdiv.style.position = 'absolute';
	newdiv.style.zIndex = 5001;
	newdiv.style.right = '2px';
	newdiv.style.top = '2px';
	newdiv.style.fontFamily = "arial";
	newdiv.style.fontSize = "10px";
	newdiv.style.borderStyle = "none";
	parent.appendChild(newdiv);
	
}

lightboxTimer.prototype.checkShowPopup = function()
{
	if(readCookie(this.cookieShowLabel + this.guid) == null)
	{
		createCookie(this.cookieShowLabel + this.guid, "jh", 1825) 
		return true;
	}
	return false;
}

lightboxTimer.prototype.updateTime = function()
{
	var curTime = this.getTime();
	var deltaTime = curTime - this.startTime;
	var timeLeft = this.timeLimit - deltaTime;
	var count = 0;
	
	window.scrollTo( 0, 0 );
	if(deltaTime < 0)
	{
		timeLeft = 0;
	}
        if(timeLeft > 0)
        {
        	var hr = getHrFromTime(timeLeft);
        	var min = getMinFromTime(timeLeft);
        	var sec = getSecFromTime(timeLeft);
        	this.currentTime = this.makeTimeString(hr,min,sec);
        	var labelArray = document.getElementsByTagName("label");
        	var count = 0;
        	var updateLabels = false;
        	
        	if(timeLeft < this.alertTime)
		{
			var modTime = timeLeft % 250;
			if(modTime > this.alertTimeHolder)
			{
				this.alertTimeHolder = modTime;
			}
			else
			{
				this.alertTimeHolder = 0;
				this.alertShowTime = !this.alertShowTime;
				updateLabels = true;
			}
		}
		else if(this.lastSec != sec )
        	{
        		updateLabels = true;
        	}
		if (updateLabels)
		{
        		this.lastSec = sec;
			while(count < labelArray.length)
			{
				if(labelArray[count].id == this.timerLabel)
				{
					if (this.alertShowTime)
					{
						labelArray[count].innerHTML = this.currentTime;
					}
					else
					{
						labelArray[count].innerHTML = "";
					}
				}
				count++;
			}
		}
	}
	else
	{
		this.destroyGliderHolder();
		clearInterval(this.intervalUpdateTime);
	}
}

lightboxTimer.prototype.makeTimeString = function(hr, min, sec)
{
	var outHr = hr.toString();
	var outMin = min.toString();
	var outSec = "";

	if (sec < 10)
	{
		outSec = "0" + sec.toString();
	}
	else
	{
		outSec = sec.toString();
	}
	if(hr > 0)
	{
		if (min < 10)
		{
			outMin = "0" + min.toString();
		}
		return outHr + ":" + outMin + ":" + outSec;
	}
	return outMin + ":" + outSec;
}

lightboxTimer.prototype.getTime = function()
{	
	var dateObj = new Date();
	return dateObj.getTime();
}

lightboxTimer.prototype.setGliding = function()
{
	this.myGlide = new Glider(this.glideIdName,this.left, this.top, null, null, 700,-1);
	this.myGlide.show();
}

lightboxTimer.prototype.makeGliderHolder = function()
{
        //make new div
	var newdiv = document.createElement('div');
	
	//set div attributes
	newdiv.setAttribute('id',this.glideIdName);
	newdiv.innerHTML = this.text;
	newdiv.style.height = this.height + "px";
	newdiv.style.width = this.width + "px";
	newdiv.style.position = 'absolute';
	newdiv.style.zIndex = 5000;
	newdiv.style.backgroundColor = this.backColor;
	newdiv.style.fontFamily = this.textFont;
	newdiv.style.color = this.textColor;
	newdiv.style.borderColor = this.borderColor;
	newdiv.style.borderStyle = this.borderStyle;
	newdiv.style.borderWidth = this.borderWidth + "px";
	if(!this.floatPopup)
	{
		newdiv.style.top = this.top + "px";
		newdiv.style.left = this.left + "px";
	}
	if(this.backgroundImage.length > 0)
	{
		newdiv.style.backgroundImage = "url('" + this.backgroundImage + "')";
	}
	//update clocks
	var labels = newdiv.getElementsByTagName("label");
	var count = 0;
	while(count < labels.length)
	{
		if(labels[count].id == this.timerLabel)
		{
			labels[count].innerHTML = this.currentTime;
		}
		count++;
	}
	//write to html
	if(this.closeButton != false)
	{
		this.makeCloseButton(newdiv);
	}
	var cover = document.createElement('div');
	cover.setAttribute('id',this.glideIdName+"_cover");
	cover.style.position = 'absolute';
	cover.style.zIndex = 4999;
	if (document.documentElement && document.documentElement.scrollTop)
	{
		coverHeight = document.documentElement.scrollHeight;
	}
	else if (document.body)
	{
		coverHeight = document.body.scrollHeight
	}
	else
	{
		//Do netscape stuff
	}

	cover.style.height = (coverHeight + 100) + "px";
	cover.style.width = "105%";
	cover.style.top = "0px";
	cover.style.left = "0px";
	if (this.isIE6) 
  	{
  	  cover.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + this.backdropImage + "\', sizingMethod='scale');";
  	  var iframe = document.createElement('IFRAME');
  	  iframe.setAttribute('id',this.glideIdName+'_iFrame');
  	  iframe.style.height = cover.style.height;
	  iframe.style.width = cover.style.width;
	  iframe.style.top = "0px";
	  iframe.style.left = "0px";
	  iframe.style.position = 'absolute';
	  iframe.style.display = 'inline';
	  iframe.style.zIndex=1000;
	  iframe.frameBorder="0";
	  iframe.scrolling="no";
	  iframe.marginwidth="0";
	  iframe.marginheight="0";
	  iframe.allowtransparency="true"
	  iframe.style.filter='chroma(color="#FFFFFF")';
	  document.body.appendChild(iframe);
	}
	else
	{
	  cover.style.background = "url(" + this.backdropImage + ")";
	}
	
	document.body.appendChild(newdiv);
        document.body.appendChild(cover);
        if (navigator.appName.indexOf("Microsoft")!=-1 && detectDoctype() == null)
        {
        	this.oldScroll = document.body.scroll;
        	document.body.scroll = "no";
        }
        else
        {
        	this.oldOverflow = document.documentElement.style.overflow;
	        document.documentElement.style.overflow="hidden";
	}

}

lightboxTimer.prototype.destroyGliderHolder = function()
{
	var regEx = /^\[object/;
	var glideHolder = document.getElementById(this.glideIdName);
	
	if(regEx.test(glideHolder))
	{
		var closeBtn=document.getElementById(this.glideIdName + "_close");
		if(regEx.test(closeBtn))
		{
			closeBtn.parentNode.removeChild(closeBtn);
		}
		glideHolder.parentNode.removeChild(glideHolder);
	}
	coverHolder = document.getElementById(this.glideIdName+"_cover");
	if(regEx.test(coverHolder))
	{
	        coverHolder.parentNode.removeChild(coverHolder);
	}
	iFrameHolder = document.getElementById(this.glideIdName+"_iFrame");
	if(regEx.test(iFrameHolder))
	{
	        iFrameHolder.parentNode.removeChild(iFrameHolder);
	}
	if(this.myGlide != null)
	{
		this.myGlide.id = "";
		delete this.myGlide.baseObj
		delete this.myGlide;
		this.myGlide = null;
	}
	if(this.intervalUpdateTime != null)
	{
		clearInterval(this.intervalUpdateTime);
		this.intervalUpdateTime = null;
	}
	if(this.oldOverflow != null)
	{
		document.documentElement.style.overflow = this.oldOverflow;
	}
	if(this.oldScroll != null)
	{
		document.body.scroll = this.oldScroll;
	}
}

//==============================================================
//==============================================================
function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ')
		{
			c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}

function getHrFromTime(time)
{
	return parseInt(time / 3600000);
}
function getMinFromTime(time)
{
	time %= 3600000;
	return parseInt(time / 60000);
}
function getSecFromTime(time)
{
	time %= 1440000;
	time %= 60000;
	return parseInt(time / 1000);
}

function versionInfo() 
{ 
	this.xhtml=""; 
	this.version=""; 
	this.importance=""; 
} 

function detectDoctype()
{
	var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi; 
	var myversionInfo=new versionInfo(); 
	
	/********************************************* 
	Just check for internet explorer. 
	**********************************************/ 
	if(typeof document.namespaces != "undefined")
	{
		if(document.all[0].nodeType==8) 
			re.exec(document.all[0].nodeValue); 
		else 
			return null; 
	}
	else
	{
		if(document.doctype != null) 
			re.exec(document.doctype.publicId); 
		else 
			return null; 
	} 
	myversionInfo.xhtml=RegExp.$1; 
	myversionInfo.version=RegExp.$2; 
	myversionInfo.importance=RegExp.$3; 
	return myversionInfo; 
}