function videoOverlay()
{
	var target;

	var flashDiv;
	// timer vars
	var timerID;
	var timeInterval;
	var timer;
	var tryCount;
	var flashIsCreated;

	window._videoOverlay = this;

	function init()
	{
		tryCount = 0;
		timerID = 0;
		timeInterval = 10 + Math.round(35 * Math.random());
		// start the timer and allow the page to load
		// this should be called from onload ideally
		startTimer(2);
		//alert(timeInterval);
	}

	function hideVideoOverlay()
	{
		// hide the div
		var overlay = document.getElementById('videoOverlayContainer');
		overlay.style.visibility = "hidden";
		// start the timer again
		resetTimer();
	}


	function showVideoOverlay()
	{
		// show the div
		var overlay = document.getElementById('videoOverlayContainer');
		var foot = document.getElementById("footer");
		var offsetObj = get_abs_pos_from_elm(foot);

		overlay.style.top = (offsetObj.y-400)+"px";
		overlay.style.left = offsetObj.x+"px";
		overlay.style.visibility = "visible";

		// call the flash to start the next video
		tryCount++;
		try
		{
			thisMovie("videoOverlaySWF").sendToActionScript();
			tryCount = 0;
		}
		catch(e)
		{
			if(tryCount < 255)
			{
				showVideoOverlay();
			}
			else
			{
				tryCount = 0;
				//alert('try limit reached');
			}
		}


	}

	// get the flash object
	function thisMovie(movieName) {
	    if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
	    } else {
	        return document[movieName];
	    }
	}

	function startTimer(time)
	{
 		timerID = setTimeout("_videoOverlay.onTimerComplete();", (time*1000));
	}

	function stopTimer()
	{
		// clear the timeout and therefor stop the timer
		clearTimeout(timerID);
	}

	function resetTimer()
	{
		startTimer(timeInterval);
	}

	function onTimerComplete()
	{
		// if the flash div isn't there create it
		if(!flashIsCreated)
		{
			// create the div and flash object
			createVideoOverlay();
			// reset the timer to wait for flash to init
			startTimer(5);
			return;
		}
		// once the div and flash are done, show the next video
		
		showVideoOverlay();
		
		timeInterval = 10 + Math.round(35 * Math.random());
	}

	function createVideoOverlay()
	{
		flashIsCreated = true;
		// create div to hold the flash
		// create the flash object
		var foot = document.getElementById("footer");
		//foot.style.color = "#ff0000";
		target = foot.parentNode;
		var offsetObj = get_abs_pos_from_elm(foot);
		flashDiv = document.createElement("div");
		flashDiv.id ="videoOverlayContainer";
		flashDiv.style.position = "absolute";
		flashDiv.style.width = "1000px";
		flashDiv.style.height = "400px";
		flashDiv.style.top = (offsetObj.y-400)+"px";
		flashDiv.style.left = offsetObj.x+"px";
		flashDiv.style.visibility = "hidden";

		//flashDiv.style.border = "1px solid #00ff00";

		target.appendChild(flashDiv);

		var so = new SWFObject("/swf/prod_video_overlay.swf", "videoOverlaySWF"	, 1000, 400, "9", "#000000");
		//so.useExpressInstall("prod_video_overlay.swf");
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess", "always");
		so.write("videoOverlayContainer");
		
	}


	function get_abs_pos_from_elm(el)
	{
		var SL = 0, ST = 0;
		var is_div = /^div$/i.test(el.tagName);
		if (is_div && el.scrollLeft)
			SL = el.scrollLeft;
		if (is_div && el.scrollTop)
			ST = el.scrollTop;
		var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
		if (el.offsetParent) {
			var tmp = get_abs_pos_from_elm(el.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	}


	this.init 					= init;
	this.startTimer 			= startTimer;
	this.stopTimer 				= stopTimer;
	this.resetTimer 			= resetTimer;
	this.onTimerComplete 		= onTimerComplete;
	this.createVideoOverlay 	= createVideoOverlay;

	this.hideVideoOverlay		= hideVideoOverlay;
}