var FloaterUpperRight = 1;
var FloaterLowerRight = 2;

function FloatingAds_Initialize (strFlashFile, nPosition)
{
	if(nPosition == FloaterUpperRight || nPosition == FloaterLowerRight)
	{
		document.writeln('<DIV ID="FloatingAds" STYLE="position:absolute; width:320px; height:320px; left:0px; top:0px; display:none">');
		document.writeln('<TABLE WIDTH=100% HEIGHT=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>');
		document.writeln('<TD COLSPAN=3><IMG SRC="/images/floating_top.gif"></TD>');
		document.writeln('</TR><TR>');
		document.writeln('<TD><IMG SRC="/images/floating_left.gif"></TD>');
		document.writeln('<TD WIDTH=300 HEIGHT=300>');
		document.writeln('<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" WIDTH=300 HEIGHT=300 CODEBASE="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">');
		document.writeln('<PARAM NAME="movie" VALUE="' + strFlashFile + '">');
		document.writeln('<PARAM NAME="play" VALUE="true">');
		document.writeln('<PARAM NAME="loop" VALUE="true">');
		document.writeln('<PARAM NAME="quality" VALUE="high">');
		document.writeln('<EMBED SRC="' + strFlashFile + '" WIDTH=300 HEIGHT=300 play="true” loop="true" quality="high" pluginspage="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
		document.writeln('</EMBED>');
		document.writeln('</OBJECT>');
		document.writeln('</TD>');
		document.writeln('<TD><IMG SRC="/images/floating_right.gif"></TD>');
		document.writeln('</TR><TR>');
		document.writeln('<TD COLSPAN=3><IMG SRC="/images/floating_bottom.gif"></TD>');
		document.writeln('</TR></TABLE>');
		document.writeln('</DIV>');

		g_oFloatingAds = document.getElementById('FloatingAds');

		g_xFloating = document.body.offsetWidth - parseInt(g_oFloatingAds.style.width) - 30;

		if(nPosition == FloaterUpperRight)
			g_yFloating = 10;
		else
			g_yFloating = document.body.offsetHeight - parseInt(g_oFloatingAds.style.height) - 10;

		g_oFloatingAds.style.left = g_xFloating;
		g_oFloatingAds.style.top = g_yFloating;
		g_oFloatingAds.style.display = '';
		g_oFloatingAds.onmousedown = FloatingAds_onMouseDown;

		g_fnOldWindowScroll = document.onscroll;
		window.onscroll = FloatingAds_onScroll;
	}
}

function FloatingAds_onMouseDown ()
{
	if(!g_fDraggingFloatingAds)
	{
		g_fnOldDocumentMouseUp = document.onmouseup;
		document.onmouseup = FloatingAds_onMouseUp;
		g_fnOldDocumentMouseMove = document.onmousemove;
		document.onmousemove = FloatingAds_onDrag;
		g_fDraggingFloatingAds = true;
	}
	g_xFloatingDrag = event.clientX - parseInt(document.body.scrollLeft);
	g_yFloatingDrag = event.clientY - parseInt(document.body.scrollTop);
	return false;
}

function FloatingAds_onMouseUp ()
{
	if(g_fDraggingFloatingAds)
	{
		document.onmousemove = g_fnOldDocumentMouseMove;
		g_fnOldDocumentMouseMove = null;
		document.onmouseup = g_fnOldDocumentMouseUp;
		g_fnOldDocumentMouseUp = null;
		g_fDraggingFloatingAds = false;
	}
	return false;
}

function FloatingAds_onDrag ()
{
	var xScroll = parseInt(document.body.scrollLeft);
	var yScroll = parseInt(document.body.scrollTop);
	var x = event.clientX - xScroll;
	var y = event.clientY - yScroll;
	var xDiff = g_xFloatingDrag - x;
	var yDiff = g_yFloatingDrag - y;

	g_xFloating -= xDiff;
	g_yFloating -= yDiff;
	g_oFloatingAds.style.left = g_xFloating + xScroll;
	g_oFloatingAds.style.top = g_yFloating + yScroll;

	g_xFloatingDrag = x;
	g_yFloatingDrag = y;

	return false;
}

function FloatingAds_onScroll ()
{
	var xScroll = parseInt(document.body.scrollLeft);
	var yScroll = parseInt(document.body.scrollTop);

	g_oFloatingAds.style.left = g_xFloating + xScroll;
	g_oFloatingAds.style.top = g_yFloating + yScroll;

	if(g_fnOldWindowScroll)
	{
		g_fnOldWindowScroll();
	}
}

var g_fnOldWindowScroll = null;
var g_fnOldDocumentMouseMove = null;
var g_fnOldDocumentMouseUp = null;
var g_fDraggingFloatingAds = false;
var g_xFloating, g_yFloating, g_xFloatingDrag, g_yFloatingDrag;
var g_oFloatingAds = null;