/*

This javascript contains methods that allow you to create a floating layer
on html pages.

INSTRUCTIONS:
1.  On the HTML page, please make sure you load this Javascript.  

This can be done by putting <SCRIPT SRC="filename.js"></SCRIPT> inside the
<HEAD>....</HEAD> tag.

2.  In the <BODY> tag please add the method placeIt() to the 'onLoad' 
javascript function to load up the floating layer, or else it would 
not work.  

This can be done by putting <BODY onLoad(placeIt('floatName',y-coordinate));>

works in conjunction with common.js
without it, this set of javascript would not work.

*/

//write the start tag of the floating layer element

function writeStartTag(floatName,left_value,top_value,width_value,visibility_boolean) {

	if ((IE4)||(IE4_UP)||(NS6))
	{
		//check the visibility?
		if (visibility_boolean) {
			visibility_value = "visible"; 
		}
		else {
			visibility_value = "hidden";
		}

		document.write("<DIV id='"+floatName+"' style='position:absolute; left:"+left_value+"; top:"+top_value+"; width:"+width_value+"; visibility:"+visibility_value+";'>");

	}
	else if (NS4)
	{
		if (visibility_boolean)
		{
			visibility_value = "show";
		}
		else {
			visibility_value = "hide";
		}

		document.write("<LAYER NAME='"+floatName+"' LEFT='"+left_value+"' TOP='"+top_value+"' WIDTH='"+width_value+"' VISIBILITY='"+visibility_value+"'>");

	}

}

//write the end tag of the floating layer element

function writeEndTag() {

	if ((IE4)||(IE4_UP)||(NS6))
	{
		document.write("</DIV>");
	}
	else if (NS4)
	{
		document.write("</LAYER>");
	}

}

//hide the float layer

function hideLayer(floatName) {

	if ((IE4_UP)||(NS6))
	{
		document.getElementById(floatName).style.visibility='hidden';
	}
	else if (IE4) {
		document.all[floatName].style.visibility='hidden';
	}
	else if (NS4) {
		document.layers[floatName].visibility='hide';
	}

}

//show the float layer

function showLayer(floatName) {

	if ((IE4_UP)||(NS6)) {
		document.getElementById(floatName).style.visibility='visible';
	}
	else if (IE4) {
		document.all[floatName].style.visibility='visible';
	}
	else if (NS4) {
		document.layers[floatName].visibility='show';
	}

}

//check the visibility of the float layer

function checkVisible(floatName) {

	var visible;

	if ((IE4_UP)||(NS6)) {
		visible_text = document.getElementById(floatName).style.visibility;
		
		if (visible_text=="visible")
		{
			visible=true;
		}
		else if (visible_text=="hidden")
		{
			visible=false;
		}
		else {
			visible=false;
		}
	}
	else if (IE4) {
		visible_text = document.all[floatName].style.visibility;
		
		if (visible_text=="visible")
		{
			visible=true;
		}
		else if (visible_text=="hidden")
		{
			visible=false;
		}
		else {
			visible=false;
		}
	}
	else if (NS4) {
		visible_text = document.layers[floatName].visibility;

		if (visible_text=="show")
		{
			visible=true;
		}
		else if (visible_text=="hide")
		{
			visible=false;
		}
		else {
			visible=false;
		}
	}

	return visible;
}

// change the (y1 value) on the left to adjust the Y co-ordinate

function placeLayer(floatName,y1) {

	if ((IE4_UP)||(NS6)) {
		document.getElementById(floatName).style.top = document.body.scrollTop + (document.body.clientHeight - (document.body.clientHeight-y1));
	}
	else if (IE4) {
		document.all[floatName].style.top = document.body.scrollTop + (document.body.clientHeight - (document.body.clientHeight-y1));	
	}
	else if (NS4) {
		document.layers[floatName].top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))
	}
	
	window.setTimeout("placeLayer('" + floatName +"',"+ y1 +")", 10);

 }

function automatedFloatLayer(floatName) {

	var appear;
	var wait=15000; //wait for 15 seconds
	var after; 

	check_visibility = checkVisible(floatName);

	//make sure floating layer is hidden.
	if (check_visibility) {
		hideIt(floatName);
	}
	
	//pick random time, to make float layer appear (max 10 seconds)
	appear = Math.round(Math.random()*10)*1000;
	
	//if 0 seconds, make it 1 second
	if (appear==0)
	{
		appear=1000;
	}

	after = appear + wait; //seconds before appear time + wait time

	window.setTimeout("showIt('" + floatName +"')",appear);
	window.setTimeout("hideIt('" + floatName +"')",after);

	//probably would not be used
	//window.setTimeout("automatedFloatLayer('" + floatName +"')", 5000);
}
