var gpath =  "/graphics/prayer-ropes/";
var act = "/cgi-bin/action.pl";
// ---------

document.cookie = "tIntro" + "=" + "1" + ";expires=Wed, 01-Jan-2020 00:00:00 GMT;" + "path=/";
function readtCookie() {
  var nameEQ = "tIntro" + "=";
  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);
  }
  return null;
}
function readlCookie() {
  var nameEQ = "lIntro" + "=";
  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);
  }
  return null;
}
var tCookie = readtCookie();
var lCookie = readlCookie();

// ---------

loadImageCH33A = new Image(); loadImageCH33A.src = gpath + "/CH33A-ov.gif"; staticImageCH33A = new Image(); staticImageCH33A.src = gpath + "/CH33A-th.jpg";
loadImageCH33B = new Image(); loadImageCH33B.src = gpath + "/CH33B-ov.gif"; staticImageCH33B = new Image(); staticImageCH33B.src = gpath + "/CH33B-th.jpg";
loadImageCH50 = new Image(); loadImageCH50.src = gpath + "/CH50-ov.gif"; staticImageCH50 = new Image(); staticImageCH50.src = gpath + "/CH50-th.jpg";
loadImageCH100 = new Image(); loadImageCH100.src = gpath + "/CH100-ov.gif"; staticImageCH100 = new Image(); staticImageCH100.src = gpath + "/CH100-th.jpg";
loadImageCH150 = new Image(); loadImageCH150.src = gpath + "/CH150-ov.gif"; staticImageCH150 = new Image(); staticImageCH150.src = gpath + "/CH150-th.jpg";
loadImageCH300 = new Image(); loadImageCH300.src = gpath + "/CH300-ov.gif"; staticImageCH300 = new Image(); staticImageCH300.src = gpath + "/CH300-th.jpg";

// ---------

// TESTING
// ON: 1, OFF: 0
var t = "0";
var dont_check_cookie = "0";

var w = screen.height;
if(w < 900)  { int_w = int_w_under_900; int_h = int_h_under_900; } 
if(w == 900) { int_w = int_w_900; int_h = int_h_900; }
if(w > 900)  { int_w = int_w_above_900; int_h = int_h_above_900; }

length_showintroimage = show_intro_image.length;
source = show_intro_image;

komb = "no";
uri = document.location.href;
ref = document.referrer;
check_komboskini_uri = uri.indexOf("komboskini");
check_komboskini_ref = ref.indexOf("komboskini");
if (check_komboskini_uri > 10 || check_komboskini_ref > 10 ) {
  komb = "komboskini";
}

$(document).ready(function() {
  if (length_showintroimage == 2 ) {
    if (t==1) { alert("Not showing the intro!"); }
  } else {
    if (t==1) { alert("AAA: Step 1/3: Trying to show the intro..."); }
    if (tCookie == 1) { // 'tCookie == 1' should be used here!
      if (t==1) { alert("BBB: Step 2/3: Testing cookie accepted"); }
      if (lCookie != 1 || dont_check_cookie == "1") {
        if (t==1) { alert("CCC: Step 3/3: Now showing intro, since a previous load intro cookie was not found! # + lCookie\n\nDOM URL: http://localhost/cgi-bin/content.pl?page=/" + preview_file_path + "/preview&komb=" + komb + "&language=en&source=" + source + "&resolution=" + screen.width + "x" + screen.height + "&intro=yes"); }
        $.colorbox({initialWidth: "0px", initialHeight: "0px", scrolling:false, transition: "fade", speed: 600, opacity: 0.8, close: "", innerWidth: int_w, innerHeight: int_h, href:"/cgi-bin/content.pl?page=/" + preview_file_path + "/preview&komb=" + komb + "&language=en&source=" + source + "&resolution=" + screen.width + "x" + screen.height + "&intro=yes"});
        var nocache_random=Math.floor(Math.random()*100000);
        $.get(act + '?nocache=' + nocache_random + '&source=intro&resolution=' + screen.width + 'x' + screen.height + '&ID=' + source);
        document.cookie = "lIntro" + "=" + "1" + ";expires=Wed, 01-Jan-2020 00:00:00 GMT;" + "path=/";
      } else { 
        if (t==1) { alert("DDD: Step 3/3: Not showing intro, since a previous load intro cookie was found!"); }
      }
    } else { 
      if (t==1) { alert("EEE: Step 2/3: Cookies disabled, testing cookie NOT accepted! Process aborted!"); }
      var nocache_random=Math.floor(Math.random()*100000);
      $.get(act + "?nocache=" + nocache_random + "&source=intro&action=C");
    }
  }
});

// ---------

function onUnload() { $.colorbox.close(); }
function previewImage() { 
  $.colorbox.close(); var nocache_random=Math.floor(Math.random()*100000); $.get(act + "?nocache=" + nocache_random + "&source=intro&action=image&ID=" + source); 
}
function previewLearn() { 
  $.colorbox.close(); var nocache_random=Math.floor(Math.random()*100000); $.get(act + "?nocache=" + nocache_random + "&source=intro&action=learn&ID=" + source); 
}
function previewSkip() { 
  $.colorbox.close(); var nocache_random=Math.floor(Math.random()*100000); $.get(act + "?nocache=" + nocache_random + "&source=intro&action=skip&ID=" + source); 
}
function previewClose() { 
  $.colorbox.close(); var nocache_random=Math.floor(Math.random()*100000); $.get(act + "?nocache=" + nocache_random + "&source=intro&action=close&ID=" + source); 
}
