/*global YAHOO document window swfobject */

var rf_overlay = {
	Dom:YAHOO.util.Dom, /* Dom is an object from the Yahoo library that contains functions to interact with the dom model */
	overlayTrigger: "flashOverlayTrigger", /* This is the ID of the flash movie in the content */
	overlayName: "overlayContainer", /* This will be the ID of the flash overlay */
	
	overlaySwfFolder: "./Content/Flash/", /* This the the folder the swf's are */
	
	//overlaySwfFolder: "http://intranet.rijkswaterstaat.nl/rws/corporate-intranet/", /* This the the folder the swf's are */		
	
	overlaySwf: "IntranetIntroduction.swf", /* This is the name of the overlay swf */
	flashvars: {xOffset: 0, yOffset: 0, scrolled: false}, /* These are parameters that are passed on to the overlay video, by default these are set to zero and false. The init function will change these to the correct values */
	init: function () /* The flashvars will be set here  */
	{
		var region, scrolled;
		this.trigger = this.Dom.get(this.overlayTrigger); /* This is the flash video in the content */
		movieRegion = this.Dom.getRegion(this.trigger); /* movieRegion is a collection of variables containing the position of the flash video */
		containerRegion = this.Dom.getRegion("container"); /* containerRegion is a collection of variables containing the position of the main container */
		scrolled = this.Dom.getDocumentScrollTop(); /* This is the number of pixels the window is scrolled calculated from the top */
		if (scrolled > 0)
		{
			this.flashvars.scrolled = true;	/* If the page is scrolled the flashvar scrolled is set to: true */
		}
		this.flashvars.xOffset = (movieRegion.left - containerRegion.left); /* The flashvar containing the left offset is set, by taking the movieRegion.left minus the containerRegion.left */
		this.flashvars.yOffset = movieRegion.top; /* The flashvar containing the top offset is set */
		this.getBodyTag();
	},
	getBodyTag: function () /* The body tag is found here */
	{
		var items;
		items = document.getElementsByTagName("BODY");
		if (items.length === 1)
		{
			this.body = items[0];
			/* This could also be solved in the stylesheet by setting the border attribute to zero on the HTML tag, that would probably be better */
			/* If the border is not set to zero IE6 will not calculate the x and y Offset in the right way */
			this.Dom.setStyle(this.body.parentNode, "border", "0px");
			this.insertOverlay();
		}
	},
	insertOverlay: function () /* The overlay container will be placed in the body as a first child */
	{
		var newNode, params;
		window.scrollTo(0, 0); /* If the page is scrolled this will bring it back to the top */
		newNode = document.createElement("div"); /* A new node is made to function as the overlay */
		newNode.id = this.overlayName; /* It's given an id */
		this.Dom.insertBefore(newNode, this.Dom.getFirstChild(this.body)); /* The new node is placed in the body as a first child */
		params = {"wmode": "transparent", "allowScriptAccess": "always"}; /* Parameters are set for the overlay swf */
		this.Dom.setStyle(this.trigger, "visibility", "hidden"); /* The flash video in the content is set to hidden, so it cannot interfere with the overlay */
		swfobject.embedSWF(this.overlaySwfFolder + this.overlaySwf, this.overlayName, "100%", "100%", "8.0.0", this.overlaySwfFolder + "expressInstall.swf", this.flashvars, params); /* The newly made overlay div is converted in a flash object using swfobject. Also the flashvars and the parameters are given to the object */
		this.Dom.setStyle(this.overlayName, "position", "absolute"); /* --- These are some style to set the overlay to cover the entire page */
		this.Dom.setStyle(this.overlayName, "margin", "0px auto");
		this.Dom.setStyle(this.overlayName, "top", "0px");
		this.Dom.setStyle(this.overlayName, "height", "1000px");
		this.Dom.setStyle(this.overlayName, "width", "956px");
		this.Dom.setStyle(this.overlayName, "z-index", "99");
		this.overlayNode = this.Dom.get(this.overlayName);
	},
	removeOverlayNode: function (e, o) /* This function will remove the overlay from the body, and make the content flash video visible again */
	{
		this.Dom.setStyle(this.trigger, "visibility", "visible");
		this.body.removeChild(this.overlayNode);
	}
};

function rf_closeOverlay() /* The overlay video can call to this function to close the overlay */
{
	rf_overlay.removeOverlayNode();
}

function rf_openIntroduction() /* The content flash video can call this function to open the overlay */
{
	rf_overlay.init();
}
