// Splash Page script - Carsten Germer
// Based on the script of http://www.dynamicdrive.com/
// Rewritten to work in Typo3 with Extension jq_lightbox 0.1.1
// Created: September 5th, 2010

var splashpage={
// Splash Page Script Activation (1=enabled, 0=completely disabled!)
splashenabled: 1,

//1) URL to file on your server to display as the splashpage
splashpageurl: "not used",

//2) Enable frequency control? (1=yes, 0=no)
enablefrequency: 1,

//3) display freqency: "sessiononly" or "x days" (string value). Only applicable if 3) above is enabled
displayfrequency: "sessiononly",

//4) HTML for the header bar portion of the Splash Page
// WE DONT USE THIS

//5) cookie setting: ["cookie_name", "cookie_path"]
cookiename: ["dewist-splash-popup-cookie", "path=/"],

//6) Auto hide Splash Page after x seconds (Integer value, 0=no)?
autohidetimer: 0,

////No need to edit beyond here//////////////////////////////////
//// Edited anyway :P für Deutsche Wildtier Stiftung, Carsten Germer, 5.09.2010 ////

launch:false,
browserdetectstr: (window.opera&&window.getSelection) || (!window.opera && window.XMLHttpRequest), //current browser detect string to limit the script to be run in (Opera9 and other "modern" browsers)

output:function(){
  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
    if(document.documentElement.clientWidth){
      windowWidth = document.documentElement.clientWidth;
      }
    else {
      windowWidth = self.innerWidth;
      }
    windowHeight = self.innerHeight;
    }
  else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
    }
  else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
    }
  var string;
  $("#overlay").hide().css({width: '100%', height: windowHeight+'px', opacity : 0.5}).fadeIn();
  $("#hoverNav").hide();
  $("#loading").hide();
  $("#outerImageContainer").width(660).height(370);
  $("#imageDataContainer").width(660);
  $('#lightbox').css({top: '150px'});
  $('#lightboxImage').attr('src', 'fileadmin/templates/dewist/images/promopics/110818_nne_layer.jpg');
  $("#outerImageContainer").css("cursor", "pointer");
  $("#outerImageContainer").click(function(){ window.location='http://www.deutschewildtierstiftung.de/de/schuetzen/wildtierland-schaffen/'; return false; });

  $("#lightbox").fadeIn();

},

closeit:function(){
/* nop */
},

init:function(){
	if (this.enablefrequency==1){ //if frequency control turned on
		if (/sessiononly/i.test(this.displayfrequency)){ //if session only control
			if (this.getCookie(this.cookiename[0]+"_s")==null){ //if session cookie is empty
				this.setCookie(this.cookiename[0]+"_s", "loaded")
				this.launch=true
			}
		}
		else if (/day/i.test(this.displayfrequency)){ //if persistence control in days
			if (this.getCookie(this.cookiename[0])==null || parseInt(this.getCookie(this.cookiename[0]))!=parseInt(this.displayfrequency)){ //if persistent cookie is empty or admin has changed number of days to persist from that of the stored value (meaning, reset it)
				this.setCookie(this.cookiename[0], parseInt(this.displayfrequency), parseInt(this.displayfrequency))
				this.launch=true
			} 
		}
	}
	else //else if enablefrequency is off
		this.launch=true
	if (this.launch){
		this.output()
		if (parseInt(this.autohidetimer)>0)
			setTimeout("splashpage.closeit()", parseInt(this.autohidetimer)*1000)
	}
},

getCookie:function(Name){
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value, days){
	var expireDate = new Date()
	//set "expstring" to either an explicit date (past or future)
	if (typeof days!="undefined"){ //if set persistent cookie
		var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
		document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; "+splashpage.cookiename[1] //last portion sets cookie path
	}
else //else if this is a session only cookie setting
	document.cookie = name+"="+value+"; "+splashpage.cookiename[1] //last portion sets cookie path
}

}

// Changes here to init splash after everything is loaded
function popload() {
  if (splashpage.splashenabled==1)
    splashpage.init();
  }
window.onload=popload;

