/* 

SplashScreen, Popup methode


USAGE: 
window.GR_Splashscreen = new GR_Splashscreen ( { 
	filePath:"../popup.html", 	// The value of the object / Default: popup
	fileType:"iframe", 			// File type / Default: iframe - FileTypes: img, swf, flv, qt, wmp, iframe, html
	fileTitle:"Mededeling",		// The title to use for the object / Default: empty
	fileWidth:"600", 			// The width of the object / Default: max 964px
	fileHeight:"400" 			// The height of the object / Default: Height window
} );

SYNTAX images: 
window.GR_Splashscreen = new GR_Splashscreen ( { filePath:"../nvm_mrt2010_1.jpg", fileType:"img", fileTitle:"Mededeling" } );

*/

//**************************************************************
GR_Splashscreen = function( options ) {
	this.glbSplashCookieName = "SplashCookieName";
	this.arrOptions = [];

	if( !this.getCookie( this.glbSplashCookieName ) && typeof Shadowbox != "undefined" ) {

		this.filePath = "popup.html";
		this.fileType = "iframe";
		this.fileTitle = "";
		this.fileWidth = "964";

		if( typeof options["filePath"] != "undefined" )
			this.filePath = options["filePath"];
		if( typeof options["fileType"] != "undefined" )
			this.fileType = options["fileType"];
		if( typeof options["fileTitle"] != "undefined" )
			this.fileTitle = options["fileTitle"];
		if( typeof options["fileWidth"] != "undefined" )
			this.fileWidth = options["fileWidth"];

		this.arrOptions = { content:this.filePath,player:this.fileType,title:this.fileTitle,width:this.fileWidth };
 
		if( typeof options["fileHeight"] != "undefined" )
			this.arrOptions.height = options["fileHeight"]; 

		if( window.XMLHttpRequest )
			var xhttp = new XMLHttpRequest()
		else
			var xhttp = new ActiveXObject("Microsoft.XMLHTTP")

		xhttp.open("HEAD",this.filePath,true);
		xhttp.send("");

		xhttp.onreadystatechange = function() {
			if (xhttp.readyState == 4) {
				if (xhttp.status==200) {			
					window.GR_Splashscreen.showPopup();
				} else if (xhttp.status==404)
					window.GR_Splashscreen.setCookie( window.GR_Splashscreen.glbSplashCookieName, "splashscreen", 1 );
			}
		} 
	}		 	
}

//**************************************************************
GR_Splashscreen.prototype.showPopup = function() {
	if(typeof Shadowbox != "undefined") {
		Shadowbox.open( this.arrOptions  );
		this.setCookie( this.glbSplashCookieName, "splashscreen", 1 );
	} else {
		this.setCookie( this.glbSplashCookieName, "splashscreen", 1 );
	}
};

// getCookie
// SYNTAX: getCookies( naam );
//**************************************************************
GR_Splashscreen.prototype.getCookie = function( c_name ) {
	if( document.cookie.length <= 0 )
		return "";

	if( ( startPos = document.cookie.indexOf( c_name + "=" ) ) !== -1 ) {
		startPos = startPos + c_name.length + 1;
		endPos = document.cookie.indexOf( ";", startPos );
		
		if( endPos == -1 )
			endPos = document.cookie.length;
			
		return unescape( document.cookie.substring( startPos, endPos ) );
	}
};

// setCookie
// SYNTAX: setCookie( name, waarde, dagen tot dat het cookie vergaat)
// -1 als expiredays verwijdert het cookie.
//**************************************************************
GR_Splashscreen.prototype.setCookie = function( c_name, value, expiredays ) {
	var exdate = new Date();
//	exdate.setDate( exdate.getDate()+ expiredays ); gewijzigd voor een cookie van 3 uur
	exdate.setTime( exdate.getTime()+ (expiredays/8*24*60*60*1000) );
	document.cookie = c_name+ "=" + escape( value ) + ( ( expiredays==null ) ? "" : ";expires=" + exdate.toGMTString() );
};
