var timer;
var h = -450;	// set this to the same value of the top property for the pa div in the style sheet
var w = 250;	// set this to the same value of the width property for the pa div in the style sheet, smaller to move it to the right, larger to move it to the left
var t = 100;	// set this to the actual pixel distance from the top where you want the pa div to be at the end of the descent

// Day of week function to call a different image depending on value...
function dayOfWeek() { 

var dailyImage = new Image(); 

// Load image based on day of week, Sun = 0, Mon = 1, etc...
	var d= new Date();
	theDay = d.getDay();
	switch (theDay) {
		 /* case 1: // Test Case - Delete before publishing...
			document.write("<img src='img/3200253.jpg' />"); 
			break;
		*/	
		/*case 2: // Tuesday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break;
		case 3: // Wednesday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break;
		case 4: // Thursday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break;
		case 5: // Friday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break; */
		default: // Sat, Sun, Mon
			//document.write("<img src='/popup/img/cyber-monday.jpg' usemap='#m_cybermonday' />"); 
			document.write("<img src='/popup/img/will-be-back.png' />"); 
	}
}

// End day of week function

// Day of week function to call a different image depending on value...
function dailyDeal() { 

var dailyImage = new Image(); 

// Load image based on day of week, Sun = 0, Mon = 1, etc...
	var d= new Date();
	theDay = d.getDay();
	switch (theDay) {
		/*case 2: // Tuesday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break;
		case 3: // Wednesday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break;
		case 4: // Thursday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break;
		case 5: // Friday
			document.write("<img src='/popup/img/will-be-back.png' />"); 
			break; */
		default: // Sat, Sun, Mon
			//document.write("<img src='/popup/img/cyber-monday.jpg' usemap='#m_cybermonday' />"); 
			document.write("<img src='/popup/img/will-be-back.png' />"); 
	}
}


function startAp() {
	setLeft();
	showAp();
	scriptTimer();
	setTheDivStyle();
}

function hideAp() { 
	if (document.layers) document.layers.pa.visibility = 'hide';
	else if (document.all) document.all.pa.style.visibility = 'hidden';
	else if (document.getElementById) document.getElementById("pa").style.visibility = 'hidden';
}

function showAp() { 
	state=typeof tPos;
	if(state=='undefined') tPos = h;
	if(tPos < t) { 
		tPos+=25;
		if (document.layers) document.layers.pa.top = tPos+"px";
		else if (document.all) document.all.pa.style.top = tPos+"px";
		else if (document.getElementById) document.getElementById("pa").style.top = tPos+"px";
	}

	if(timer!=null) clearInterval(timer);
	timer = setTimeout("showAp()",10);
}

function getoPos() {
	if (document.layers) alert(document.layers.pa.top);
	else if (document.all) alert(document.all.pa.style.top);
	else if (document.getElementById) alert(document.getElementById("pa").style.top);
}

function setLeft() {
	if (document.layers) document.layers.pa.left = ((window.innerWidth / 2) - (w / 2))+"px";
	else if (document.all) document.all.pa.style.left = ((document.body.offsetWidth / 2) - (w / 2))+"px";
	else if (document.getElementById) document.getElementById("pa").style.left = ((window.innerWidth / 2) - (w / 2))+"px";
}

// Time to display script
function scriptTimer() { 
		
	// Assign the command to execute and the number of seconds to wait
	var strCmd = "document.getElementById('pa').style.display = 'none'";
	var waitseconds = 7200;

	// Calculate time out period then execute the command
	var timeOutPeriod = waitseconds * 1000;
	var hideTimer = setTimeout(strCmd, timeOutPeriod);
}
	
// Script for cookie creation.

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 setTheDivStyle() {
	if(!readCookie('wroteIt')) {
		// if cookie not found display the div and create the cookie
		document.getElementById("pa").style.display="block";
		createCookie('wroteIt', 'wroteIt', 1);  // 1 day = 24 hours persistence
	}
	else {
		// if cookie found hide the div
		document.getElementById("pa").style.display="none";
	}
}

// -> Begin manual popup
function getBrowserHeight() {
	var intH = 0;
	var intW = 0;
			
	if(typeof window.innerWidth == 'number' ) {
		intH = window.innerHeight;
		intW = window.innerWidth;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		intH = document.documentElement.clientHeight;
		intW = document.documentElement.clientWidth;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		intH = document.body.clientHeight;
		intW = document.body.clientWidth;
	}
	return { width: parseInt(intW), height: parseInt(intH) };
}
			
function setLayerPosition() {
	var shadow = document.getElementById('shadow');
	var question = document.getElementById('popup');
			
	var bws = getBrowserHeight();
		shadow.style.width = bws.width + 'px';
		shadow.style.height = bws.height + 'px';
		question.style.left = parseInt((bws.width - 350) / 2)+ 'px';
		question.style.top = parseInt((bws.height - 200) / 2)+ 'px';
		shadow = null;
		question = null;
}
			
function showLayer() {
	setLayerPosition();
			
	var shadow = document.getElementById('shadow');
	var question = document.getElementById('popup');
			
	shadow.style.display = 'block';
	question.style.display = 'block';
			
	shadow = null;
	question = null;
}
			
function hideLayer() {
	var shadow = document.getElementById('shadow');
	var popup = document.getElementById('popup');
			
	shadow.style.display = 'none';
	popup.style.display = 'none';
			
	shadow = null;
	popup = null;
}
window.onresize = setLayerPosition;

// -> End manual popup 
