// funkce pro zobrazovani interstitialu misto pozadovane stranky

function interstitial() {
  
  this.from = '27 November 2009 00:00:00';
  
  this.to = '28 November 2009 23:59:59';
  
  this.interstitial_page = 'http://www.hokej.cz/interstitial.html';
  
  this.display_time = 10;
  
  this.cookie_name = 'interstitial';
  
  this.cookie_value = '1';
  
  this.default_referer = 'http://www.hokej.cz';
  
  interstitial.prototype.cookiesEnabled = function() {
    document.cookie = "cookiesenabled=yes";
    if (document.cookie.indexOf("cookiesenabled=") == -1) return false;
    else return true;
  }
   
  interstitial.prototype.createCookie = function() {
    var date = new Date();
  	var ms_in_day = 24*60*60*1000;
  	var next_midnight = (((date.getTime()/ms_in_day) | 0)+1)*ms_in_day;
  	
    date.setTime(next_midnight);
  	var expires = "; expires="+date.toGMTString();
  	
  	document.cookie = this.cookie_name+"="+this.cookie_value+expires+"; path=/";
  }
  
  interstitial.prototype.cookieExists = function() {
  	var nameEQ = this.cookie_name+"=";
  	var ca = document.cookie.split(';');
  	for(var i=0;i < ca.length;i++) {
  		var c = ca[i];
  		while (c.charAt(0)==' ') c = c.substring(1,c.length);
  		if (c.indexOf(nameEQ) == 0) return (c.substring(nameEQ.length,c.length) == this.cookie_value);
  	}
  	return null;
  }
  
  interstitial.prototype.getReferer = function() {
      return this.default_referer;
  }
  
  interstitial.prototype.load = function() {
    // pokud nejsou povoleny cookies nebo uz byl interstitial zobrazen, nedelame nic
    if(!this.cookiesEnabled() || this.cookieExists()) return false;
    
    window.location=this.interstitial_page;    
  }
  
  interstitial.prototype.show = function() {
    this.createCookie();
    interstitial_countdown(this.display_time);
  }
  
  interstitial.prototype.redirect = function() {
    //var referer = this.getReferer();
    //if(referer) {
      //window.location=referer;
    //} else {
      window.location=this.default_referer;
    //}
  }
}

function interstitial_countdown(current) {
  if(current-1 < 0) {
    var i = new interstitial();
    i.redirect();
  } else {
    var counter = getObj('counter');
    if(counter) {
      var count_str = ""+current+"";
      counter.obj.innerHTML = count_str;
    }
    setTimeout("interstitial_countdown("+(current-1)+")", 1000);
  }
}

function interstitial_show() {
  var an_interstitial = new interstitial();
  an_interstitial.show();  
}

function load_interstitial() {
  var an_interstitial = new interstitial();
  var date = new Date();
  if(date.getTime() > Date.parse(an_interstitial.from) && date.getTime() < Date.parse(an_interstitial.to)) {
    an_interstitial.load();
  }
}