var elh;
var ely;
var eltop;
var elmargin;
var elposition;
var elptop;
var gExY = cExY = 25;
var elback = 0;

function invertFloatEnable()
{
	if (GetCookie("Float")=="1")
	{	

		SetCookie("Float","0",null,"/");
	}
	else
	{	

		SetCookie("Float","1",null,"/");		
	}
};


function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function SetCookie (name,value,expires,path,domain,secure) 
{
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


function elLayer() {
	var ELH = 0;
	var EDH = 0;
	var EY   = 0;
	var EY1  = 0;
	var EY2  = 0;
	var EDY   = 0;

	EDH = elh.offsetHeight;

	if (oBw.ie6s) {
		ELH = document.documentElement.clientHeight;
	} else if (oBw.ns6 || oBw.op6) {
		ELH = innerHeight;
	} else if (oBw.bw5) {
		ELH = document.body.clientHeight;
	} else {
		ELH = 0;
	}

	if (oBw.ie6s) {
		EY = document.documentElement.scrollTop;
	} else if (oBw.bw5) {
		EY = document.body.scrollTop;
	} else if (oBw.ns6 || oBw.op6) {
		EY = window.pageYOffset;
	} else {
		EY = 0;
	}

	if (ELH >= eltop + EDH + elmargin) {
		EY = Math.max(EY + eltop, elptop);
	} else {
		EY1 = Math.max(EY + eltop, elptop);
		EY2 = Math.max(EY - (EDH + elmargin - ELH), elptop);
		if (EY1 > elposition && EY2 < elposition) {
			EY = elposition;
		} else if (EY2 < elposition) {
			EY = Math.max(EY1, EY2);
		} else {
			EY = Math.min(EY1, EY2);
		}
	}
	EY += gExY;

	if (EY != elposition) {
		EDY = (EY - elposition) * 0.20;
		if (Math.abs(EDY) < 1 || (Math.abs(EY - elposition) <= cExY && elback == 1)) {
			EDY = (EDY > 0) ? 1 : (EDY < 0) ? -1 : 0;
		}
		elposition   += Math.round(EDY);
		ely.top =  elposition + 'px';
		if (Math.abs(EY - elposition) <= cExY && elback == 1) {
			gExY  = 0;
		} else {
			gExY  = (EDY > 0) ? cExY : (EDY < 0) ? -cExY : 0;
			elback = 0;
		}
	} else {
		if (elback == 0) {
			elback = 1;
			gExY  = 0;
		} else {
			elback = 2;
		}
	}

	setTimeout('elLayer()', 2);
}

function Initial(id, mt, mb, tp) 
{
	//if (GetCookie("Float")==null || GetCookie("Float")=="0")
	if (GetCookie("Float")=="1")
	{

	}
	else
	{
		oBw = new fCheckBrowser;
		if (oBw.bw) 
		{
			elh         = oBw.bw5 ? document.all(id) : oBw.bw6 ? document.getElementById(id) : 0;
			ely          = elh.style;
			ely.position = 'absolute';
			eltop          = mt ? mt : 0;
			elmargin          = mb ? mb : 0;
			elposition = elptop = tp ? tp : elh.offsetTop;
			elLayer();
		}
	}
}

function fCheckBrowser() {
	this.ver   = navigator.appVersion;
	this.agent = navigator.userAgent;
	this.dom   = document.getElementById ? 1 : 0;
	this.mac   = (this.agent.indexOf("Mac") > -1) ? 1 : 0;
	this.op6   = ((this.agent.indexOf("Opera 6") > -1) && this.dom) ? 1 : 0;
	this.ie5   = ((this.ver.indexOf("MSIE 5") > -1) && this.dom && !this.op6) ? 1 : 0;
	this.ie6r  = ((this.ver.indexOf("MSIE 6") > -1) && this.dom && (document.compatMode == "BackCompat")) ? 1 : 0;
	this.ie6s  = ((this.ver.indexOf("MSIE 6") > -1) && this.dom && (document.compatMode == "CSS1Compat")) ? 1 : 0;
	this.ie4   = (document.all && !this.dom) ? 1 : 0;
	this.ie    = (this.ie4 || this.ie5 || this.ie6r || this.ie6s) ? 1 : 0;
	this.ns6   = (this.dom && (parseInt(this.ver) >= 5)) ? 1 : 0;
	this.ns4   = (document.layers && !this.dom) ? 1 : 0;
	this.ns    = (this.ns4 || this.ns6) ? 1 : 0;
	this.bw5   = (this.ie5 || this.ie6r) ? 1 : 0;
	this.bw6   = (this.ie6s || this.ns6 || this.op6) ? 1 : 0;
	this.bw    = (this.ie6r || this.ie6s || this.ie5 || this.ns6 || this.op6) ? 1 : 0;
	return this;
}
