

function gs_GetDocumentSize() 
{
	var s = new Object();

	s.clientWidth = 0;
	s.clientHeight = 0;
	s.scrollX = 0;
	s.scrollY = 0;

	if( typeof( window.innerWidth ) == 'number' ) 
	{
		s.clientWidth = window.innerWidth - (window.scrollMaxX > 0 ? 18 : 0);
		s.clientHeight = window.innerHeight - (window.scrollMaxY > 0 ? 18 : 0);
	} 
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
	{
		s.clientWidth = document.documentElement.clientWidth;
		s.clientHeight = document.documentElement.clientHeight;
	} 
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
	{
		s.clientWidth = document.body.clientWidth;
		s.clientHeight = document.body.clientHeight;
	}

	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		s.scrollX = window.pageXOffset;
		s.scrollY = window.pageYOffset;
	} 
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
	{
		s.scrollX = document.body.scrollLeft;
		s.scrollY = document.body.scrollTop;
	} 
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		s.scrollX = document.documentElement.scrollLeft;
		s.scrollY = document.documentElement.scrollTop;
	}

	s.visX1 = s.scrollX;
	s.visY1 = s.scrollY;
	s.visX2 = s.scrollX + s.clientWidth;
	s.visY2 = s.scrollY + s.clientHeight;

	return s;
}

var fr = null;
var cl = null;
var lastW = -1;
var lastH = -1;
var lastScrollX = -1;
var lastScrollY = -1;

var rollH = 220;
var rollCurr = 1;
var rollS = 5;

function SetLocation()
{
	var w = 300;
	var h = 220;
	var loc = 'lb';

	var d = fr;
	//d.style.visibility = 'visible';

	var p = gs_GetDocumentSize();

	var hOffs = rollH - rollCurr;

	if (rollCurr < rollH || p.clientWidth != lastW || p.clientHeight != lastH || p.scrollX != lastScrollX || p.scrollY != lastScrollY)
	{
		lastW = p.clientWidth;
		lastH = p.clientHeight;
		
		lastScrollX = p.scrollX;
		lastScrollY = p.scrollY;
	
		if (loc=='c')
		{
			//alert(hOffs);
			//fr.style.position = 'absolute';
			fr.style.left = ((p.clientWidth - w) / 2 + p.visX1) + 'px';
			fr.style.top = ((p.clientHeight - h) / 2 + hOffs + p.visY1 + 14) + 'px';
			fr.style.width = w + 'px';
			fr.style.height = (h - hOffs) + 'px';
			
			cl.style.left = fr.style.left;
			cl.style.top = ((p.clientHeight - h) / 2 + hOffs + p.visY1) + 'px';
		}
		else if (loc=='lt')
		{
			//fr.style.position = 'absolute';
			fr.style.left = (p.visX1 + 1)+'px';
			fr.style.top = (p.visY1 + 1 + 14)+'px';
			fr.style.width = w + 'px';
			fr.style.height = (h - hOffs) + 'px';

			cl.style.left = fr.style.left;
			cl.style.top = (p.visY1 + 1)+'px';
		}
		else if (loc=='rt')
		{
			//fr.style.position = 'absolute';
			fr.style.left = (p.visX2 - w - 21)+'px';
			fr.style.top = (p.visY1 + 1 + 14)+'px';
			fr.style.width = w + 'px';
			fr.style.height = (h - hOffs) + 'px';

			cl.style.left = fr.style.left;
			cl.style.top = (p.visY1 + 1)+'px';
		}
		else if (loc=='lb')
		{
			//fr.style.position = 'absolute';
			fr.style.left = (p.visX1 + 1)+'px';
			fr.style.top = (p.visY2 + hOffs - h - 3)+'px';
			fr.style.width = w + 'px';
			fr.style.height = (h - hOffs) + 'px';

			cl.style.left = fr.style.left;
			cl.style.top = (p.visY2 + hOffs - h - 3 - 14)+'px';
		}
		else if (loc=='rb')
		{
			//fr.style.position = 'absolute';
			fr.style.left = (p.visX2 - w - 21)+'px';
			fr.style.top = (p.visY2 + hOffs - h - 3)+'px';
			fr.style.width = w + 'px';
			fr.style.height = (h - hOffs) + 'px';

			cl.style.left = fr.style.left;
			cl.style.top = (p.visY2 + hOffs - h - 3 - 14)+'px';
		}
	}

	setTimeout(SetLocation, 10);
}

function CreateFrame()
{
	var w = 300;
	var d = document.createElement('DIV');

	d.style.position = 'absolute';
	d.style.zIndex = 10000;
	d.style.overflow = 'auto';
	d.style.visibility = 'hidden';
	//d.style.border = '1px gray solid';
	d.id = 'sliced_torrentino';
	
	fr = d;

	d.innerHTML = '<iframe id="slicef_torrentino" src="/vote/vote.php" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" style="height:100%;width:100%;"></iframe>';
	document.body.appendChild(fr);
	
	var c = document.createElement('DIV');

	c.style.position = 'absolute';
	c.style.zIndex = 10000;
	//c.style.overflow = 'auto';
	c.style.width = w + 'px';
	c.style.visibility = 'hidden';
	c.id = 'slicec_torrentino';
	c.style.textAlign = 'right';
	
	c.innerHTML = '<div  style="font-family:arial;font-size:11px;font-weight:bold;cursor:pointer; background-color: white;" onclick="return slice_Close(\'torrentino\')">Закрыть&nbsp;&nbsp;</div>';
	
	cl = c;
	document.body.appendChild(cl);

	SetLocation();
}

function slice_Close(d)
{
	try
	{
		//alert('slicec_' + d);
		document.body.removeChild(document.getElementById('sliced_' + d));
		document.body.removeChild(document.getElementById('slicec_' + d));
	
	}
	catch(e)
	{
	}
}

function RollOut()
{
	fr.style.visibility = 'visible';
	cl.style.visibility = 'visible';

	rollCurr += rollS;
	if (rollCurr > rollH)
		rollCurr = rollH;

	if (rollCurr < rollH)
		setTimeout(RollOut, 50);
}

function slice_Disappear()
{
	slice_Close('torrentino');
}

function gs_OnLoad()
{
	CreateFrame();
	setTimeout(RollOut, 500);
		setTimeout(slice_Disappear, 30000);
	}



if (navigator.userAgent.indexOf('MSIE') != -1)
{
//	window.attachEvent("onload", gs_OnLoad);
}
else
{
//	window.addEventListener("load", gs_OnLoad, false);
}



