/*
   This script is copyright (c) Henrik Petersen, NetKontoret
   Feel free to use this script on your own pages as long as you do not change it.
   It is illegal to distribute the script as part of a tutorial / script archive.
   Updated version available at: http://www.echoecho.com/toolfloatinglayer.htm
   This comment and the 4 lines above may not be removed from the code.
*/

/*
   Modified by Christian Fecteau for modern browsers in Standards Mode:
   http://forum.echoechoplus.com/showthread.php?s=&postid=46626#post46626

   Code for "Obtaining the browser window size and scrolling offset in both
   Standards and Quirks mode" comes from howtocreate.co.uk:
   http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16
*/

// This script must be called from within the BODY (for Opera compatibility)


/* --------------------------
// START variables to edit
-------------------------- */

// "ee_menu" holds the HTML for your floating layer.
// Type it all on one line, no carriage returns, no line breaks,
// and no single quotes (unless you escpae them like this: \'
//ee_menu = '<div style="border:1px solid black;font-size:15px;font-family:verdana"><ul><li>test1</li><li>test2</li><li>test3</li><li>test4</li><li>test5</li><li>test6</li><li>test7</li><li>test8</li><li>test9</li><li>test10</li><li>test11</li><li>test12</li><li>test13</li><li>test14</li><li>test15</li><li>test16</li></ul></div>';
ee_menu = '<a href="#"><img src="/images/logos/'+ filename +'" alt="Top of the page" border="0" height="90" width="150"></a>'

ee_floatX = 0; // this number is the distance in pixels from the right and left edges of the browser's window
ee_floatY = 0; // this number is the distance in pixels from the top and bottom edges of the browser's window
ee_layerwidth = 160; // this number is the width in pixels for the layer
ee_layerheight = 100; // this number is the height in pixels for the layer
ee_halign = 'right'; // this value is the horizontal position of the layer (left, center, or right)
ee_valign = 'bottom'; // this value is the vertical position of the layer (top, middle, or bottom)
ee_delayspeed = 1; // this value is the speed at which the layer must float (0, 1, or 3)

/* --------------------------
// END variables to edit
-------------------------- */


//
// Don't chnange anything below
//

function ee_adjust()
{

	  /* ////////////
	 //  assign   //
	//////////// */

	var ee_xs = 0, ee_ys = 0;
	if (typeof(window.pageYOffset) == 'number')
	{
		ee_ys = window.pageYOffset;
		ee_xs = window.pageXOffset;
	}
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
	{
		ee_ys = document.body.scrollTop;
		ee_xs = document.body.scrollLeft;
	}
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		ee_ys = document.documentElement.scrollTop;
		ee_xs = document.documentElement.scrollLeft;
	}

	  /* ///////////////
	 //  calculate   //
	/////////////// */

	if ((ee_lastX == -1) || (ee_delayspeed == 0))
	{
		ee_lastX = ee_xs + ee_floatX;
		ee_lastY = ee_ys + ee_floatY;
	}
	else
	{
		var ee_dx = Math.abs(ee_xs + ee_floatX - ee_lastX);
		var ee_dy = Math.abs(ee_ys + ee_floatY - ee_lastY);
		var ee_d = Math.sqrt((ee_dx * ee_dx) + (ee_dy * ee_dy));
		var ee_c = Math.round(ee_d / 10);
		if (ee_xs + ee_floatX > ee_lastX) { ee_lastX = ee_lastX + ee_delayspeed + ee_c; }
		if (ee_xs + ee_floatX < ee_lastX) { ee_lastX = ee_lastX - ee_delayspeed - ee_c; }
		if (ee_ys + ee_floatY > ee_lastY) { ee_lastY = ee_lastY + ee_delayspeed + ee_c; }
		if (ee_ys + ee_floatY < ee_lastY) { ee_lastY = ee_lastY - ee_delayspeed - ee_c; }
	}

	  /* ///////////////
	 //     move     //
	/////////////// */

	document.getElementById('ee_floatlayer').style.left = ee_lastX + 'px';
	document.getElementById('ee_floatlayer').style.top = ee_lastY + 'px';

	// do it again
	window.setTimeout('ee_adjust()',50);
}


function ee_define()
{
	if (ee_old_resize)
	{
		ee_old_resize();
	}

	var ee_wo, ee_ho;

	ee_lastX = -1;

	if (typeof(window.innerWidth) == 'number')
	{
		ee_wo = window.innerWidth;
		ee_ho = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		ee_wo = document.documentElement.clientWidth;
		ee_ho = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		ee_wo = document.body.clientWidth;
		ee_ho = document.body.clientHeight;
	}

	if (ee_halign == 'left')   { ee_floatX = ee_ifloatX; }
	if (ee_halign == 'right')  { ee_floatX = ee_wo - ee_ifloatX - ee_layerwidth - ee_r_edge; }
	if (ee_halign == 'center') { ee_floatX = Math.round(ee_wo / 2) - Math.round(ee_layerwidth / 2); }

	if (ee_valign == 'top')    { ee_floatY = ee_ifloatY; }
	if (ee_valign == 'bottom') { ee_floatY = ee_ho - ee_ifloatY - ee_layerheight - ee_b_edge; }
	if (ee_valign == 'middle') { ee_floatY = Math.round(ee_ho / 2) - Math.round(ee_layerheight / 2); }
}

function ee_write_layer()
{
	ee_body = document.getElementsByTagName("BODY")[0];
	ee_body.insertBefore(ee_container,null);

	ee_old_resize = window.onresize;
	window.onresize = ee_define;

	ee_define();
	ee_adjust();
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

if (W3CDOM)
{
	ee_container = document.createElement("DIV");
	ee_container.id = 'ee_floatlayer'; 
	ee_container.style.position = 'absolute';
	ee_container.style.left = ee_floatX + 'px';
	ee_container.style.top = ee_floatY + 'px';
	ee_container.style.width = ee_layerwidth + 'px';
	ee_container.style.height = ee_layerheight + 'px';
	ee_container.style.marginTop = '0px';
	ee_container.style.marginRight = '0px';
	ee_container.style.marginBottom = '0px';
	ee_container.style.marginLeft = '0px';
	ee_container.style.paddingTop = '0px';
	ee_container.style.paddingRight = '0px';
	ee_container.style.paddingBottom = '0px';
	ee_container.style.paddingLeft = '0px';
	ee_container.style.borderTop = '0';
	ee_container.style.borderRight = '0';
	ee_container.style.borderBottom = '0';
	ee_container.style.borderLeft = '0';
	if (window.ActiveXObject)
	{
		ee_container.style.overflowX = 'auto';
		ee_container.style.overflowY = 'auto';
	}
	else
	{
		ee_container.style.overflow = 'auto';
	}
	ee_container.innerHTML = ee_menu;

	window.ActiveXObject ? ee_r_edge = 0 : ee_r_edge = 20;
	window.ActiveXObject ? ee_b_edge = 0 : ee_b_edge = 20;
	ee_ifloatX = ee_floatX;
	ee_ifloatY = ee_floatY;
	ee_lastX = -1;
	ee_lastY = -1;

	window.setTimeout('ee_write_layer()',1000);
}

