/////////////////////// start global variables /////////////////////////////// 
// empty frame
var nothing 	= "<HTML><BODY BGCOLOR=" + page_color + "></BODY></HTML>"; 
if (myHeight > 0)
 img_page_max = parseInt(myHeight / 155) + 1;
var page_num 	= 1;
var page_next	= 1;
var page_prev	= 1;
var img_end 	= img_start + img_max - 1;
var page_max 	= parseInt(img_max / img_page_max); 
var page_max1 	= img_max / img_page_max; 
if (page_max1 > page_max || img_start > 1)
 page_max++;

// java_debug("page max = " + page_max)
// debugObj(top.top.document, "top.document");

var l_img_max 	= img_start + img_page_max - 1;
var l_img_start = img_start;
var current_idx = img_start;
var redraw	= 1;
var timerid	= null;

var l_img_server = img_server;
if (l_img_server == "" && IS_SAFARI) 
 // Safari wants the complete path
 l_img_server = top.document.URL;

// customizable text per page
if (cust_text == null)
 var cust_text	= new Array(img_max);

var DO_OPEN	= 1;
if (IS_NETSCAPE_3)
 DO_OPEN 	= 0;

var TIMEOUT_HACK 	= 0;
if ((IS_MICROSOFT && IS_MAC) || IS_SAFARI) {
 // HACK for IE on Mac
 TIMEOUT_HACK = 1;
}

if (IS_UNIX)
 top_nav_style  = 1; // buttons

var sp		= "&nbsp";
var sp2		= sp + sp;
var sp5		= sp2 + sp2 + sp;
var sp10	= sp5 + sp5;

var lgoto_r    	= "Next Image";
var lgoto_l    	= "Previous Image";
var bgoto_r    	= "next >>";
var bgoto_l    	= "<< back";
var gbase 	= "http://www.giamma.com/images/";
var ggoto_r 	= gbase + "gotor.gif";
var ggoto_l 	= gbase + "gotol.gif";
var gslides 	= gbase + "slides.gif";

var spre	= "pg";
var lshow	= "<B><I>Slides Show</I></B>";
var bshow	= "Slides Show";

var image_txt1  = "There are " + img_max + " images";
var image_txt2  = " divided in " + page_max + " pages";
var image_txt   = image_txt1 + image_txt2;

/////////////////////// start global functions /////////////////////////////// 

function doc_open(doc) {
 doc.clear();

 if (DO_OPEN) 
  junk = doc.open();

 doc.write("<HTML><HEAD>");
 doc.write("<STYLE TYPE='text/css'> ");
 doc.write(" BODY { " + page_style + " } ");
 doc.write("--> </STYLE>");
 doc.write("</HEAD><BODY ");

 if (page_img != "")
  doc.write(" BACKGROUND='" + page_img + "' ");
 else
  doc.write(" BGCOLOR='" + page_color + "' ");

 doc.write("LINK='" + page_link + "' VLINK='" + page_link + "' ALINK='" + page_link + "' >");

}

function doc_close(doc) {
 doc.write("</BODY></HTML>");
 if (DO_OPEN) 
  doc.close();
}

function java_debug(msg) {
 java.lang.System.err.println(msg);
}


function debugObj(obj, objName) {
 var msg = "";

 for (var i in obj)
  msg += objName + "." + i + " = " + obj[i] + "\n";	 

 alert(msg);

}

function w(msg) {
 this.document.write(msg);
}

function none() {
}

function help() {
 alert(sel_txt + "\n" + image_txt);
}


/////////////////////// end global functions ////////////////////////////////// 

var wi = null;
function window_image(image) {
 // alert(image);
 l1=screen.width - W - 10;
 t1=0;
 if (!wi || wi.closed) {
  wi = window.open(image, "Giamma", "scrollbars=no, width="+W+", height="+W+", top="+t1+", left="+l1+", toolbar=no, menubar=no, location=no, resizable=no, status=no, directories=no"); 
 }
 else { 
  wi.location = image; 
  wi.focus(); 
 } 
}

function click_image() {
 stop_slide();

 if (open_image) {
  // open new window with big image
  window_image(name_image(current_idx));
 }
}

function go_image(idx) {
 current_idx = idx;
 display_image(0);
}

function update_status() {
 window.status = "page #" + page_num + " image #" + current_idx;
}

function update_image_num() {
 var d = top.big.document;
 // can't make it bold
 d.all.image_num.innerText = "Image #" + current_idx;
}

function display_image(idx) {
 stop_slide();
 var d = top.big.document;

 current_idx += idx;
 if (current_idx > img_end)
  current_idx = img_start;

 if (current_idx < img_start)
  current_idx = img_end;

 doc_open(d);

 var img_n = name_image(current_idx);
 var div = sp10;
 redraw = 0;

 d.write("<CENTER><FONT SIZE=-1 COLOR='" + page_font + "'>");
 if (pre_txt != null & pre_txt != "") {
  d.write(pre_txt);
 }
 d.write("<SPAN ID=image_num NAME=image_num>");
 d.write("Image #" + current_idx);
 d.write("</SPAN>");
 d.write("</FONT></CENTER>");

 if (top_nav) {
  d.write("<CENTER><TABLE CELLPADDING=0 CELLSPACING=0 ><TR>");

  d.write("<TD ALIGN=LEFT>");
  if (top_nav_style == 0) {
   d.write("<FONT SIZE=-1 >");
   d.write("<A HREF='javascript:parent.display_image(-1)' >");
   d.write(lgoto_l + "</A>" + div + "</FONT>");
  }
  else if (top_nav_style == 1) {
   d.write("<INPUT TYPE=BUTTON onClick='javascript:parent.display_image(-1)' VALUE='" + bgoto_l + "' >");
  }
  else if (top_nav_style == 2) {
   d.write("<IMG SRC='" + ggoto_l + "' onClick='javascript:parent.display_image(-1)' >");
  }
  d.write("</TD>");
 
  if (SLIDE_SHOW) {
   d.write("<TD ALIGN=CENTER>");
   if (top_nav_style == 0) {
    d.write("<A HREF='javascript:parent.run_slide(\"big\")'>" + lshow + "</A>");
   }
   else if (top_nav_style == 1) {
    d.write("<INPUT TYPE=BUTTON onClick='javascript:parent.run_slide(\"big\")' VALUE='" + bshow + "' >");
   }
   else if (top_nav_style == 2) {
    d.write("<IMG SRC='" + gslides + "' onClick='javascript:parent.run_slide(\"big\")' >");
   }
   d.write("</TD>");
  }
  else
   d.write("<TD ALIGN=CENTER>" + sp + "</TD>");
 
  d.write("<TD ALIGN=LEFT>");
  if (top_nav_style == 0) {
   d.write("<FONT SIZE=-1 >");
   d.write(div + "<A HREF='javascript:parent.display_image(1)' >");
   d.write(lgoto_r + "</A></FONT>");
  } 
  else if (top_nav_style == 1) {
   d.write("<INPUT TYPE=BUTTON onClick='javascript:parent.display_image(1)' VALUE='" + bgoto_r + "' >");
  }
  else if (top_nav_style == 2) {
   d.write("<IMG SRC='" + ggoto_r + "' onClick='javascript:parent.display_image(1)' >");
  }
 
  d.write("</TD></TR>");
  d.write("</TABLE></CENTER>");
 }
 else {
  d.write("<BR>");
 }

 d.write("<CENTER><TABLE CELLPADDING=0 CELLSPACING=0 ><TR>");
 d.write("<TR><TH ALIGN=CENTER COLSPAN=4>");

 if (open_image) 
  d.write("<A HREF='javascript:parent.none()'>");

 d.write("<IMG NAME='img' SRC='" + img_n + "' ");

 if (!open_image)
  d.write(" BORDER=" + img_border + " "); 

 // add onClick event handler
 d.write(" onClick='javascript:parent.click_image()' "); 

 if (img_res) {
  if (img_flip.indexOf("-" + current_idx + "-") == -1) 
   d.write(" HEIGTH=" + img_h + " WIDTH=" + img_w + " >"); 
  else
   d.write(" HEIGTH=" + img_w + " WIDTH=" + img_h + " >"); 
 }
 else
   d.write(" >");

 if (open_image) 
  d.write("</A>");

 d.write("</TH></TR>");

 if (cust_text[current_idx-1] != null) {
  d.write("<TR><TH ALIGN=CENTER COLSPAN=4>");
  d.write("<FONT SIZE=-1 COLOR='" + page_font + "'>");
  d.write(cust_text[current_idx-1] + "<BR>");
  d.write("</FONT>");
  d.write("</TH></TR>");
 }

 d.write("<TR><TH ALIGN=CENTER COLSPAN=4>");
 d.write("<FONT SIZE=-1 COLOR='" + page_font + "'>");
 if (page_links && page_max != 1)
  d.write("Pages: ");
 do_page_links(d);

 if (post_txt != null & post_txt != "")
   d.write(post_txt);

 d.write("<BR><BR>" + page_txt + "<BR>");
 d.write("</FONT>");
 d.write("</TH></TR>");

 d.write("</TABLE></CENTER>");

 doc_close(d);

 update_status();

 if (TIMEOUT_HACK) {
  setTimeout("fix_big()", 50);
 }
}

function fix_big() {
 top.big.document.img.src = name_image(current_idx);
}

function run_slide(what) {
 // make sure no other timeout is running
 stop_slide();

 // move to next
 current_idx++;

 if (current_idx > img_end)
  current_idx = img_start;

 update_status();
 update_image_num();

 if (what == "small") {
  top.small.document["img" + l_img_start].src = name_thumb(current_idx); 
  timeout = small_timeout;
 }
 else {
  top.big.document.img.src = name_image(current_idx); 
  timeout = big_timeout;
 }

 timerid = setTimeout("run_slide(\"" + what + "\")", timeout);

}

function stop_slide() {
 if (SLIDE_SHOW && timerid != null) {
  clearTimeout(timerid);
  fix_small();
 }
}

function over_image(idx) {
 if (cust_text[idx-1] != null) 
  // top.small.document["img" + idx].TBD = cust_text[idx-1];
 // debugObj(top.small.document["img" + idx], "IMG");

 if (mouse_over)
  for (var i = l_img_start ; i <= l_img_max ; i++) 
   if (i != idx)
    top.small.document["img" + i].src = name_thumb(idx); 
}

function out_image(idx) {
 if (mouse_over)
  fix_small();
}

function name_thumb(idx) {

 if (thumb_exist) {
  var name = l_img_server + img_dir + thumb_dir + img_prefix + "0" + idx + "." + thumb_type; 

  if (idx >= 10)
   name = l_img_server + img_dir + thumb_dir + img_prefix + idx + "." + thumb_type; 

  return (name);
 }
 else
  return(name_image(idx));

}

function name_image(idx) {
 var name = l_img_server + img_dir + img_prefix + "0" + idx + "." + img_type; 

 if (idx >= 10)
  name = l_img_server + img_dir + img_prefix + idx + "." + img_type; 

 return (name);
}

function go_page(pnum) {
 stop_slide();
 // keep in consideration the fact that img_start could be different than 1
 l_img_start = ((pnum - 1) * img_page_max) + img_start;
 l_img_max = pnum * img_page_max + img_start - 1;
 if (l_img_max > img_end)
  l_img_max 	= img_end;

 page_num = pnum;

 load_all();
}

function go_prev() {
 stop_slide();

 if (page_num == 1) {
  l_img_max 	= img_end;
  l_img_start 	= img_start + img_page_max * (page_max - 1); 

  page_num 	= page_max;
 }
 else {
  if (page_num == page_max)
   l_img_max 	= l_img_start - 1; 
  else
   l_img_max 	-= img_page_max;
 
  l_img_start 	-= img_page_max;

  page_num--;
 }

 load_all();
}

function go_next() {
 stop_slide();

 if (page_num == page_max) {
  l_img_max 	= img_page_max + img_start - 1;
  l_img_start 	= img_start;

  page_num 	= 1;
 }
 else {
  l_img_max 	+= img_page_max;
  if (l_img_max > img_end)
   l_img_max 	= img_end;
 
  l_img_start 	+= img_page_max;
 
  page_num++;
 }

 load_all();
}

function load_all() {
 if (DO_OPEN) {
  load_small();
  load_big();
 }
 else {
  setTimeout("load_small()", 0);
  setTimeout("load_big()", 0);
 }
}

function load_big() {
 if (redraw) {
  var d = top.big.document;
  doc_open(d);
  d.write("<FONT COLOR='" + page_font + "'><CENTER>"); 

  d.write("<BR><H2>" + page_name + "</H2>"); 
  if (pre_txt != null & pre_txt != "")
   d.write(pre_txt + "<BR>");
  d.write(image_txt1);
 
  if (page_links && page_max != 1)
   d.write(image_txt2 + ":");

  d.write("<BR>");
  do_page_links(d);

  if (post_txt != null & post_txt != "")
   d.write(post_txt);

  d.write("<BR><BR>" + prod_txt + "<BR>");
  d.write(help_txt + "<BR>");

  d.write("</CENTER></FONT>");
  doc_close(d);
  redraw = 0;
 }
}

function do_page_links(d) {
 if (page_links && page_max != 1) {
  d.write("<B>");
  d.write("<A HREF='javascript:parent.go_prev()'><-</A>" + sp);
  d.write(sp + " " + spre + " " + sp);
  d.write("<A HREF='javascript:parent.go_next()'>-></A>" + sp);
  d.write(sp2);
  for (var i = 1; i <= page_max ; i++) { 
   if ((i % 26) == 0) d.write("<BR>");
   d.write("<A HREF='javascript:parent.go_page(" + i + ")'>" + i + "</A>" + sp);
  }
  d.write("</B><BR>");
 }
}

function load_small() {
 var d = top.small.document;

 doc_open(d);

 d.write("<CENTER><TABLE CELLSPACING=1 CELLPADDING=1 ");
 if (thumb_pos == "left" || thumb_pos == "right") 
  d.write("WIDTH=150 ");

 d.write("><TR>");

 d.write("<TD ALIGN=LEFT>"); 
 // if (thumb_pos == "left" || thumb_pos == "right")
  // d.write(sp);

 if (page_max != 1) {
  d.write("<FONT SIZE=-1 >"); 
  if (page_num == 1) 
   page_prev = page_max;
  else
   page_prev = page_num - 1;
  d.write("<A HREF='javascript:parent.go_prev()'>" + spre + page_prev + "</A>");
  d.write("</FONT>");

 }

 update_status();

 if (thumb_pos == "left" || thumb_pos == "right") {
  // d.write(sp2);
  d.write("</TD><TD ALIGN=CENTER>");
  // d.write(sp2);
 }
 else
  d.write("<BR>");

 l_text = "<B><FONT SIZE=-1>" + spre + page_num + "/" + page_max + "</FONT></B>";
 if (SLIDE_SHOW == 2)
  d.write("<A HREF='javascript:parent.run_slide(\"small\")'>" + l_text + "</A>");
 else
  d.write("<FONT COLOR='" + page_font + "'>" + l_text);

 if (thumb_pos == "left" || thumb_pos == "right") {
  // d.write(sp2);
  d.write("</TD><TD ALIGN=RIGHT>"); 
  // d.write(sp2);
  d.write("<FONT SIZE=-1 >"); 
 }
 else {
  d.write("<BR>");
  d.write("<FONT SIZE=-1 >"); 
 }

 if (page_max != 1) {
  if (l_img_max == img_end) 
   page_next = 1;
  else 
   page_next = page_num + 1;
  d.write("<A HREF='javascript:parent.go_next()'>" + spre + page_next + "</A>");
 }
 d.write("</FONT>");
 // d.write(sp);
 d.write("</TD>");

 if (thumb_pos == "left" || thumb_pos == "right")
  d.write("</TR>");

 for (var i = l_img_start ; i <= l_img_max ; i++) { 
  var img_n = name_thumb(i);

  if (thumb_pos == "left" || thumb_pos == "right")
   d.write("<TR ALIGN=CENTER>");
  d.write("<TD COLSPAN=3>"); 

  d.write("<A HREF='javascript:parent.go_image(" + i + ")' ");
  d.write(" onMouseOver='javascript:parent.over_image(" + i + ")' onMouseOut='javascript:parent.out_image(" + i + ")' ");
  d.write(" >"); 

  d.write("<IMG NAME='img" + i + "' SRC='" + img_n + "' "); 

  if (thumb_res) {

   if (img_flip.indexOf("-" + i + "-") == -1) 
    d.write(" HEIGHT=" + thumb_h + " WIDTH=" + thumb_w + " >"); 
   else
    d.write(" HEIGHT=" + thumb_w + " WIDTH=" + thumb_h + " >"); 

  }
  else
   d.write(" >");

  d.write("</A></TD>");
  if (thumb_pos == "left" || thumb_pos == "right")
   d.write("</TR>");

 }

 d.write("</TR></TABLE></CENTER>");

 doc_close(d);
 
 if (IS_MICROSOFT && IS_MAC)
  setTimeout("fix_small()", 100);
}

function fix_small() {
 for (var i = l_img_start ; i <= l_img_max ; i++)
  top.small.document["img" + i].src = name_thumb(i);
}

// generate frames
if (thumb_pos == "left") {
 w("<FRAMESET COLS='" + thumb_cols + ",*' FRAMEBORDER='no' BORDER=0 onLoad='load_all();' >"); 
 w("<FRAME NAME='small' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("<FRAME NAME='big' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("</FRAMESET>");
}
else if (thumb_pos == "right") {
 w("<FRAMESET COLS='*," + thumb_cols + "' FRAMEBORDER='no' BORDER=0 onLoad='load_all();' >"); 
 w("<FRAME NAME='big' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("<FRAME NAME='small' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("</FRAMESET>");
}
else if (thumb_pos == "top") {
 w("<FRAMESET ROWS='" + thumb_cols + ",*' FRAMEBORDER='no' BORDER=0 onLoad='load_all();' >"); 
 w("<FRAME NAME='small' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("<FRAME NAME='big' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("</FRAMESET>");
}
else if (thumb_pos == "bottom") {
 w("<FRAMESET ROWS='*," + thumb_cols + "' FRAMEBORDER='no' BORDER=0 onLoad='load_all();' >"); 
 w("<FRAME NAME='big' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("<FRAME NAME='small' SRC='javascript:parent.nothing' NORESIZE>"); 
 w("</FRAMESET>");
}

/////////////////////////////// END ///////////////////////////////////////////

