var timer;
var t;
var obj;

var h = -450;		// set this to the same value of the top property for the faw div in the style sheet
var dist = 260;		// set this to the actual pixel distance from the top where you want the pa div to be at the end of the descent



function setCookie(c_name, value, exdays){
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
	document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name){
	var i, x, y, ARRcookies = document.cookie.split(";");
	for (i = 0; i < ARRcookies.length; i++){
		x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
		x = x.replace(/^\s+|\s+$/g, "");
		if (x == c_name){
			return unescape(y);
		}
	}
}

function checkLayerAd(){
	var c = getCookie("szm_layer_ad");
	if (c != null && c != "")	{
//		alert("Welcome again " + c);
	} else {
		c = "szm_layer_ad_cookie";
		if (c != null && c != "")	{
			setCookie("szm_layer_ad", c, 1);
			showFrame();
		}
	}
}



function showFrame(){
	obj = getObj();
	setLeft();
	show(true);
	t = 0;
//	setTimer();
	slide();
}

function hideFrame(){
	show(false);
	return false;
}

function setTimer(){
	timer = setInterval("fade()", 16.6666);
}

function fade(){
	var amt = Math.abs(t += 5);
	if(amt == 0 || amt == 100) clearInterval(timer);
	amt = (amt == 100) ? 99.999 : amt;
	
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt / 100;
	obj.style.MozOpacity = amt / 100;
	obj.style.opacity = amt / 100;
	
	if(amt == 0) show(false);
}

function getObj(){
	if(document.getElementById) return document.getElementById("faw");
	else if(document.all) return document.all.faw;
	else if(document.layers) return document.layers.faw;
}

function setLeft(){
	// set this to 1/2 the width of the faw div defined in the style sheet
	// there is no reliable way to retrieve an element's width via javascript
	var w = 200;
	var l = (document.body.innerWidth) ? document.body.innerWidth / 2 : document.body.offsetWidth / 2;
	
	obj.style.left = (l - w) + 'px';
}

function show(bool){
	(bool) ? obj.className = 'show' : obj.className = '';
}

function slide(){ 
	state=typeof tPos;
	if(state == 'undefined') tPos = h;
	if(tPos < dist) { 
		tPos += 20;
		if (document.layers) document.layers.faw.top = tPos+"px";
		else if (document.all) document.all.faw.style.top = tPos+"px";
		else if (document.getElementById) document.getElementById("faw").style.top = tPos+"px";
	} else {
		setTimeout("hideFrame()", 5000);
	}
	
//	obj.style.filter = "alpha(opacity:100)";
//	obj.style.KHTMLOpacity = 100;
//	obj.style.MozOpacity = 100;
//	obj.style.opacity = 100;
	
	if(timer!=null) clearInterval(timer);
	timer = setTimeout("slide()", 16.6666);
}
