var layer_in_motion = false;
var last_movement=0;

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 monitor_movement(){
	if (last_movement>0) last_movement = last_movement - 1;
	if (last_movement>5) last_movement = 5;
//	window.status = "Motion ["+last_movement+"] + [" + layer_in_motion + "]";
	if (last_movement==0) layer_motion(false);
	setTimeout("monitor_movement()",50);
}

function move_div(d,x,y){
	var odiv  = document.getElementById(d);
	// alert("move_div "+d+","+x+","+y);
	odiv.style.top  = odiv.style.top  = y;
	odiv.style.left = odiv.style.left = x;
	last_movement = last_movement + 1;
}

function layer_motion(state){
	layer_in_motion = state;
}

function hover_div(d,w,last_top,last_left){
	var odiv  = document.getElementById(d);
	var width = document.body.clientWidth - w;
	var left  = width - (width/2) + document.body.scrollLeft;
	var top	  = document.body.scrollTop+50;
	var l = last_left;
	var delay, inc;

	if (layer_in_motion == true) {
		setTimeout("hover_div('"+d+"',"+w+","+top+","+left+")",5000);
		return;
	} 
	// alert("hover_div(" +d+ "," +w+ "," +top+" ("+last_top+ ")," + left + "("+ last_left+");");
    t = last_top;
	if (t < top){
		layer_motion(true);
		delay = 20;
		while (t<=top){
			delta = top - last_top;
			prc = 100-((top-t)/delta)*100;
			ang = (prc*1.8);
			rad = ang * (Math.PI/180);
			inc = 1 - (Math.sin(rad));
			inc = inc * 25;	if (inc<3) inc = 3;
			// alert("ang " + ang + " prc " + prc + " delay " + inc);
			delay = delay + inc;
			setTimeout("move_div('"+d+"',"+last_left+","+t+");",delay); t = t + 5;
		}
	} 
    t = last_top;
	if (t > top){
		layer_motion(true);
		delay = 20;
		while (t>=top){ 
			delta = top - last_top;
			prc = 100-((top-t)/delta)*100;
			ang = (prc*1.8);
			rad = ang * (Math.PI/180);
			inc = 1 - (Math.sin(rad));
			inc = inc * 25;	if (inc<3) inc = 3;
			delay = delay + inc; 	
			setTimeout("move_div('"+d+"',"+last_left+","+t+");",delay); t = t - 5;	
		}
	}
	if (l < left){
		delay = 1;
		while (l<=left){ setTimeout("move_div('"+d+"',"+l+","+top+");",delay); delay = delay + 1; l = l = 5; }
	}
	if (l > left){
		delay = 1;
		while (l>=left){ setTimeout("move_div('"+d+"',"+l+","+top+");",delay); delay = delay + 1; l = l - 5; }
	}
	setTimeout("hover_div('"+d+"',"+w+","+top+","+left+")",500);
}

function div_fadeOut(d,dur) {
	var oDiv = document.getElementById(d);
	oDiv.style.filter="blendTrans(duration="+dur+")";
    // Make sure the filter is not playing.
    if (oDiv.filters && oDiv.filters.blendTrans.status != 2) {
        oDiv.filters.blendTrans.apply();
        oDiv.style.visibility="hidden";
        oDiv.filters.blendTrans.play();
    }
    oDiv.style.visibility="hidden";
}

function div_fadeIn(d,dur) {
	var oDiv = document.getElementById(d);
    oDiv.style.filter="blendTrans(duration="+dur+")";
    // Make sure the filter is not playing.
    if (oDiv.filters && oDiv.filters.blendTrans.status != 2) {
        oDiv.filters.blendTrans.apply();
        oDiv.style.visibility="visible";
        oDiv.filters.blendTrans.play();
    }
    oDiv.style.visibility="visible";
}

function display_advert(d,w){
	var odiv  = document.getElementById(d);
	var width = document.body.clientWidth - w;
	var left  = width - (width/2) + document.body.scrollLeft;
	var top	  = document.body.scrollTop+50;
	odiv.style.top  = odiv.style.top  = top;
	odiv.style.left = odiv.style.left = left;
	hover_div('advert',w,top,left);
	div_fadeIn('advert',0.25);
	showlayer('advert');
	monitor_movement();
}

function init_floating_layer(d,startup,width,use_cookies){
	if (use_cookies==1 && readCookie(d)) return;
	else {
		if (use_cookies) createCookie(d,1,1);
		setTimeout("display_advert('"+d+"',"+width+")",startup);
	}
}

// layer show and hide

var timer = null;
var last_menu = null;
var delay = 0;
var layer_name = null;
db = 0;

function flipBox(who) {
	var tmp;
	if (document.images['b_' + who].src.indexOf('_on') == -1) {
		tmp = document.images['b_' + who].src.replace('_off', '_on');
		document.getElementById('box_' + who).style.display = 'none';
		document.images['b_' + who].src = tmp;
	} else {
		tmp = document.images['b_' + who].src.replace('_on', '_off');
		document.getElementById('box_' + who).style.display = 'block';
		document.images['b_' + who].src = tmp;
	}
}

function popup(URL,w,h) {
	aWindow=window.open(URL, "thewindow", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=yes, resize=no, menubars=no");
}

function popup_full(URL,w,h) {
	aWindow=window.open(URL, "thewindow", "toolbar=no, width="+w+", height="+h+", status=yes, scrollbars=yes, resize=yes, menubars=no");
}

function popup_clean(URL,w,h) {
	aWindow=window.open(URL, "", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=no, resize=no, menubars=no");
}

function popup_scroll(URL,w,h) {
	aWindow=window.open(URL, "", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=yes, resize=no, menubars=no");
}

function loadframe(id,page) {
if (ns4) { eval("document."+id+"_frame.src = page"); }
else if (ie4) eval(id+"_frame.document.location = page");
}

function find_obj(id){
	if (this.document.all) return this.document.all[''+id+''];
	else if (this.document.getElementById) return this.document.getElementById(''+id+'');
}

function showlayer(id){
	if (db==2) alert('show '+id);
	if (id==null){
		if (layer_name!=null){
			id=layer_name;
			alert("Default ["+layer_name+"]");
		}else{
			alert("No layer specified to show");
		}
	}
	if (this.document.layers) this.document.layers[''+id+''].visibility = "show"
	else if (this.document.all) this.document.all[''+id+''].style.visibility = "visible"
	else if (this.document.getElementById) this.document.getElementById(''+id+'').style.visibility = "visible"
	if (delay>0) timer = setTimeout("hidelayer()", delay);
	last_menu=id;
}

function initlayer(id){
	if (db==2) alert('show '+id);
	if (id==null){
		if (layer_name!=null){
			id=layer_name;
			alert("Default ["+layer_name+"]");
		}else{
			alert("No layer specified to show");
		}
	}
	if (this.document.layers) this.document.layers[''+id+''].visibility = "show"
	else if (this.document.all) this.document.all[''+id+''].style.visibility = "visible"
	else if (this.document.getElementById) this.document.getElementById(''+id+'').style.visibility = "visible"
}

function hidelayer(id){
	if (db==2) alert('hide '+id);
	if (timer!=null){
		clearTimeout(timer);
	}
	if (id!=null){
		if (this.document.layers)
			this.document.layers[''+id+''].visibility = "hide"
			else if (this.document.all) this.document.all[''+id+''].style.visibility = "hidden"
			else if (this.document.getElementById) this.document.getElementById(''+id+'').style.visibility = "hidden"
	}else{
		if (last_menu!=null){
			hidelayer(last_menu);
			last_menu=null;
		}
	}
}

function movelayer(id,y,x){
	if (db==2) alert('move '+id+' '+x+','+y);
	if (this.document.all){
		o = this.document.all[id];
	} else if (this.document.getElementById){
		o = this.document.getElementById(''+id+'');
	}
	o.style.top = x;
	o.style.left = y;
}

function showmouse(){
	window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
}

function writelayer(ID,parentID,sText) { 
	if (document.layers) { 
		var oLayer; 
		if(parentID){ 
			oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
		}else{ 
			oLayer = document.layers[ID].document; 
		} 
		oLayer.open(); 
		oLayer.write(sText); 
		oLayer.close(); 
	} 
	else if (parseInt(navigator.appVersion)>=5&&navigator. 
		appName=="Netscape") { 
		document.getElementById(ID).innerHTML = sText; 
	} 
	else if (document.all) document.all[ID].innerHTML = sText 
}