
var read_cookie;

function putCookie(cookie_name,cookie_value){
  document.cookie=cookie_name+"="+cookie_value+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
}

// reads cookie CookieName and writes value into read_cookie

function getCookie (CookieName,EmptyValue) {

  var CookieSet = document.cookie.split (';');
  var CookiePieces
  
// value read_cookie will have if CookieName dontīt exist

  if (EmptyValue!=undefined) read_cookie = EmptyValue; else read_cookie = "0";

  for (var i = 0; i < CookieSet.length; i++) {
    CookiePieces = CookieSet[i].split ('=');
    if (CookiePieces[0].substring (0,1) == ' ') {
      CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
    }
    if (CookiePieces[0] == CookieName) {
      read_cookie = eval(CookiePieces[1]);
    }
  }
}

var img_class;

function get_img_res(img_no,preset,res2,res3,res4,res5,res6,res7,res8,res9,res10,res11,res12){

  if (preset=="width"){
    res1=res2=res3=res4=2048; res5=1536; res6=res7=res8=1600; res9=1200; res10=res11=1280; res12=960;}
  else{if (preset=="height"){
      res1=1536; res2=1365; res3=1200; res4=1000; res5=2048; res6=1200; res7=1067; res8=938; res9=1600; res10=960; res11=853; res12=1280;}
    else res1=preset;} 

  for(var i = 0; i <= res_640x480.length-1; i++) if (res_640x480[i] == img_no) img_class = res1;
  for(var i = 0; i <= res_720x480.length-1; i++) if (res_720x480[i] == img_no) img_class = res2;
  for(var i = 0; i <= res_819x480.length-1; i++) if (res_819x480[i] == img_no) img_class = res3;
  for(var i = 0; i <= res_983x480.length-1; i++) if (res_983x480[i] == img_no) img_class = res4;
  for(var i = 0; i <= res_360x480.length-1; i++) if (res_360x480[i] == img_no) img_class = res5;

// Should be deactivated, kept for downward compatibility

  for(var i = 0; i <= res_1600x1200.length-1; i++) if (res_1600x1200[i] == img_no) img_class = res6;
  for(var i = 0; i <= res_1600x1067.length-1; i++) if (res_1600x1067[i] == img_no) img_class = res7;
  for(var i = 0; i <= res_1600x938.length-1; i++) if (res_1600x938[i] == img_no) img_class = res8;
  for(var i = 0; i <= res_1200x1600.length-1; i++) if (res_1200x1600[i] == img_no) img_class = res9;
  for(var i = 0; i <= res_1280x960.length-1; i++)  if (res_1280x960[i] == img_no) img_class = res10;
  for(var i = 0; i <= res_1280x853.length-1; i++)  if (res_1280x853[i] == img_no) img_class = res11;
  for(var i = 0; i <= res_960x1280.length-1; i++)  if (res_960x1280[i] == img_no) img_class = res12;
//img_class = res1;
}

var path_no;

function get_hi_res_path(img_no){

// variables.js must be loaded!

  init0(); path_no = 1;
  for(var i = 5; i >= 1; i--) if (path_last_image[i] != "") if (img_no <= path_last_image[i]) path_no=i;
}


function select_subseries(subseries_no){

  putCookie("current_subseries",subseries_no);
  putCookie("current_img",0);
  parent.thumbs_parent.thumbs.location.href="thumbs.htm";
}

function get_subseries_range(subseries_no){

// variables.js must be loaded! init0 must be executed!

  if (subseries_no==0) {subseries_begin=1; subseries_end=total_images}
  else {if (subseries_no==1) {subseries_begin=1} else {subseries_begin=subseries_last_image[subseries_no-1];subseries_begin++};
  subseries_end=subseries_last_image[subseries_no]}
}

function hide_preview(){
  getCookie("current_img"); 
  top.location.href="../refer-viceversa.htm?" + read_cookie;
}




function show_preview(){
  getCookie("current_img"); 
  top.location.href="../refer-viceversa.htm?" + read_cookie;
}

var th_offset;

function get_thumbnail_offset(){
  getCookie("current_thumbnail_page");
  if (read_cookie<=20) th_offset = 0;
  if ((read_cookie>20) && (read_cookie<=40)) th_offset = 20; 
  if ((read_cookie>40) && (read_cookie<=60)) th_offset = 40;
  if ((read_cookie>60) && (read_cookie<=80)) th_offset = 60; 
  if ((read_cookie>80) && (read_cookie<=100)) th_offset = 80;
}

function prev_page(){
  getCookie('current_thumbnail_page');
  if(read_cookie<=20) read_cookie=21; 
  putCookie('current_thumbnail_page',read_cookie-20);
  parent.location.href='noprev_thumbs_parent.htm';
}

function next_page(){
  getCookie('current_thumbnail_page');
  if(read_cookie>total_images-20) read_cookie=total_images-20;
  putCookie('current_thumbnail_page',read_cookie+20); 
  parent.location.href='noprev_thumbs_parent.htm';
}

function load_image(img_no){
  putCookie("current_img",img_no);
  parent.location.href="noprev_image_parent.htm";
}

function prev_load_image(img_no){
  putCookie("current_img",img_no);
  parent.location.href="image_parent.htm";
}

function toggle_image_size(){
  getCookie("show_large_version");
  if (read_cookie==0) putCookie("show_large_version",1);
  else putCookie("show_large_version",0);
  parent.location.href="noprev_image_parent.htm";
}

function prev_toggle_image_size(){
  getCookie("show_large_version");
  if (read_cookie==0) putCookie("show_large_version",1);
  else putCookie("show_large_version",0);
  parent.location.href="image_parent.htm";
}


// ------------------------------ OUT OF COMMISSION ---------------------------


// function directory_listing_hi_res(){

// // variables.js must be loaded!

//   init0();
//   if (path[1]!="") parent.parent.viewer.location.href="ftpsources.htm";
//   else alert("There are no high resolution versions of these images available.");
// }


// function full_screen(){

// // variables.js must be loaded!

//   getCookie("show_hi-res");
//   if (read_cookie==0) top.location.href = "viewer.htm";
//   else {getCookie("current_img"); get_hi_res_path(read_cookie);
//     if (path[path_no]!="") top.location.href=path[path_no] + "/refer-img_index.htm?" + read_cookie;
//     else top.location.href = "viewer.htm";}
// }

// ------------------------------ FROM OLD VIEWER -----------------------------

// function show_hi_res(){

// // variables.js must be loaded!

//   getCookie("current_img"); get_hi_res_path(read_cookie);

//   if (path[path_no]!="") {putCookie("show_hi-res",1);
//     top.location.href=path[path_no] + "/refer-img_index.htm?" + read_cookie;}
//   else alert("There's no high resolution version of this image available.");
// }

// function show_lo_res(){

// // variables.js must be loaded!

//   init0();
//   if (path[0]!=""){getCookie("current_img"); top.location.href=path[0] +"/refer-img_viewer.htm?" + read_cookie}
//   else alert("These images are not part of an album. You may only view them one by one.");
// }

// function leave_to_album(){

// // variables.js must be loaded!

//   getCookie("show_hi-res","empty");
//   if (read_cookie!="empty") top.location.href="index.htm";
//   else {init0();
//     if (path[0]!=""){getCookie("current_img"); top.location.href=path[0] +"/refer-img_index.htm?" + read_cookie}
//     else alert("These images are not part of an album. You may only view them one by one.");}
// }

// function show_first_image(){
//   putCookie("current_img",1); self.location.href="viewer.htm";
// }
