lastScrollY = 0;
IE = (document.all) ? 1 : 0;
var floaterToMove = false;
var floaterOldX = -1;
var floaterOldY = -1;
var objOldX = -1;
var objOldY = -1;

function getElement(id)
{
	return document.getElementById(id);
}

function blablabla()
{
	y=0;
	if(document.all) {
		if(window.document.body && window.document.body.scrollTop) y = window.document.body.scrollTop;
		if(window.document.scrollTop) y = window.document.scrollTop;
		if(window.scrollTop) y = window.scrollTop;
		if(window.document.documentElement.scrollTop) y = window.document.documentElement.scrollTop;
	}
	if(document.getElementById) {
		if(window.document.body && window.document.body.pageYOffset) y = window.document.body.pageYOffset;
		if(window.document.pageYOffset) y = window.document.pageYOffset;
		if(window.pageYOffset) y = window.pageYOffset;
		if(window.document.documentElement.pageYOffset) y = window.document.documentElement.pageYOffset;
	}
	return y;
}

function turn_on( e )
{
	if(document.getElementById('pseudo_popup')!=null)
	{
		diffY = blablabla();

		if( diffY != lastScrollY )
		{
			percent = .1 * ( diffY - lastScrollY );

			if( percent > 0 )
				percent = Math.ceil( percent );
			else
				percent = Math.floor( percent );

			if( IE )
			{
				getElement('pseudo_popup').style.pixelTop += percent;
			}
			else
			{
				object = getElement('pseudo_popup');
				top = object.offsetTop + percent;
				if(top<0)top=0;
				object.style.top = top+'px';
			}

			lastScrollY = lastScrollY + percent;
		}
		_checkPosition();
	}
}

window.setInterval( 'turn_on()' , 25 );

document.onmousemove = moveFloater;
document.onmouseup = releaseFloater;

function _setFloaterToMove( value )
{
	floaterToMove = value;

	floaterOldX = -1;
	floaterOldY = -1;
}

function _checkPosition()
{
	object = document.getElementById('pseudo_popup');

	if(document.defaultView)
	{
		iLeft = document.defaultView.getComputedStyle(object,null).left;
		iLeft = parseInt(iLeft.substring(0,iLeft.indexOf('px')));
		iRight = document.defaultView.getComputedStyle(object,null).right;
		iRight = parseInt(iRight.substring(0,iRight.indexOf('px')));
		iTop = document.defaultView.getComputedStyle(object,null).top;
		iTop = parseInt(iTop.substring(0,iTop.indexOf('px')));
		iBottom = document.defaultView.getComputedStyle(object,null).bottom;
		iBottom = parseInt(iBottom.substring(0,iBottom.indexOf('px')));
	}
	else
	{
		iLeft = object.style.left;
		iLeft = parseInt(iLeft.substring(0,iLeft.indexOf('px')));
		iRight = document.body.clientWidth - object.offsetWidth - iLeft;
		iTop = object.currentStyle.top;
		iTop = parseInt(iTop.substring(0,iTop.indexOf('px')));
		iBottom = document.body.clientHeight + document.body.scrollTop - object.offsetHeight - iTop;
	}

	if( object.offsetLeft < 0 ) object.style.left = '0px';
	if( iRight < 0 ) object.style.left = iLeft + iRight + 'px';
	if( object.offsetTop < 0 ) object.style.top = '0px';
	if( iBottom < 0 ) object.style.top = (object.offsetTop + iBottom) + 'px';
}

function releaseFloater( e )
{
	_setFloaterToMove( false );
}

function setFloaterToMove( e )
{
	_setFloaterToMove( true );
}

function moveFloater( e )
{
	if( floaterToMove )
	{
		var object;
		var x, y;

		object = document.getElementById('pseudo_popup');
		if( IE )
		{
			x = event.clientX + document.body.scrollLeft;
			y = event.clientY + document.body.scrollTop;
		}
		else
		{
			x = e.pageX;
			y = e.pageY;
		}

		if( floaterOldX > -1 )
		{
			object.style.left = object.offsetLeft + x - floaterOldX + 'px';
			object.style.top = object.offsetTop + y - floaterOldY + 'px';
		}

		floaterOldX = x;
		floaterOldY = y;

		_checkPosition();

		return false;
	}
}

function showPseudoPopup( content, country )
{
	if(document.getElementById('pseudo_popup')==null)
	{
		oTABLE = document.createElement('table');
		oTABLE.setAttribute('style','');
		oTABLE.id = 'pseudo_popup';
		oTABLE.cellSpacing = 0;
		oTABLE.cellPadding = 0;
		oTABLE.border = 0;
		oTBODY = document.createElement('tbody');
		oTABLE.appendChild(oTBODY);

		oTBODY.insertRow(0);
		oTBODY.rows[0].insertCell(0);
		oTBODY.rows[0].cells[0].id = 'pp_header';
		oTBODY.rows[0].cells[0].onmousedown = setFloaterToMove;
		oTBODY.rows[0].cells[0].onmouseup = releaseFloater;
		oTBODY.rows[0].cells[0].onmousemove = moveFloater;
//		oDIV = document.createElement('div');
//		oDIV.id = 'close';
//		oDIV.onclick = hidePseudoPopup;
//		oTBODY.rows[0].cells[0].appendChild(oDIV);

		oTBODY.insertRow(1);
		oTBODY.rows[1].insertCell(0);
		oTBODY.rows[1].cells[0].id = 'pseudo_popup_content';

		document.body.appendChild(oTABLE);
	}
	if(country==null){country="";}
	document.getElementById( 'pp_header' ).innerHTML = "<span id=\"title\">"+country+"</span><span id=\"close\" onclick=\"hidePseudoPopup();\"></span>";
	document.getElementById( 'pseudo_popup_content' ).innerHTML = content;
	
	if(objOldX!=-1 && objOldY!=-1)
	{
		oDIV = document.getElementById('pseudo_popup');
		oDIV.style.left = objOldX;
		oDIV.style.top = objOldY;
	}	
}

function showImageOnPseudoPopup( path , country)
{
	showPseudoPopup( '<img src="pseudopopup/path.htm" alt="" border="0">', country );
	if(objOldX!=-1 && objOldY!=-1)
	{
		oDIV = document.getElementById('pseudo_popup');
		oDIV.style.left = objOldX;
		oDIV.style.top = objOldY;
	}
}

function hidePseudoPopup()
{
	oDIV = document.getElementById('pseudo_popup');
	if(oDIV != null)
	{
		objOldX = oDIV.style.left;
		objOldY = oDIV.style.top;
		document.body.removeChild(oDIV);
	}
}