//###########################################################################
//## ALBUM.JS -- WebPhotoAlbum resource file
//###########################################################################

var scriptVersion = "4.01";

// Album object's names and IDs.
var slide_name="slide";
var frame_name="frame";
var text_name="text";

var zoom_id="zoom";
var nzoom_id="nzoom";
var nzoom_image_id="nzoomimage";
var album_title_id="album-title";
var album_title_shadow_id="album-title-shadow";
var blank_htm="blank.htm";
var photo_album_id="photo-album";
var frames_id="frames";

// Album Layout variables.
var total_slides = thumbnail_files.length - 1; //Total number of slides in album calculated from thumbnail files array.
var slide_columns;               //Number of slide columns in album for auto layout.
var slide_rows;                  //Number of slide rows in album for auto layout.
var current_page = -1;           //Current page number.
var client_width, client_height; //Dimensions of  the client area.
var zoom_mode=-1;                // -1 Album view mode, 0 - SlideShow mode, 1 - Zoom mode.
var actual_image_area_width=0;   //Actual image area width. Used when album_type=0.
var actual_image_area_height=0;  //Actual image area height. Used when album_type=0.

var app = navigator.appName;
var ver = parseInt(navigator.appVersion.substring(0,1));
var browser_check = ((app == "Netscape") && (ver >= 3)) || ((app == "Microsoft Internet Explorer") && (ver >= 4));
var is_ie4 = ((app == "Microsoft Internet Explorer") && (ver >= 4)); //browser_check && ((document.all)    ? true : false);
var is_ns  = ((app == "Netscape") && (ver >= 3)); //browser_check && ((document.layers) ? true : false);

//alert("ScriptVer="+scriptVersion+"\napp="+app+"\nver="+ver+"\nbrowser_check="+browser_check+"\nNS="+is_ns+"\nIE="+is_ie4);

if (is_ie4) {
FRAME      = new Image (slide_width, slide_height);
FRAME.src  = frame_image;
IMAGES     = new Array ();
THUMBNAILS = new Array ();
};

function PrefetchNextImage(index)
{
	var doNext = (index < total_slides);
	window.status = "Loading Image "+index;
	IMAGES[index] = new Image(image_dimensions[index*2], image_dimensions[index*2+1]);
	if (doNext) {
		IMAGES[index].onload = new Function('setTimeout("PrefetchNextImage('+(index+1)+')",10)');
	};
	IMAGES[index].src = image_files[index];
};
function PrefetchNextThumb(index)
{
	var doNext = (index < total_slides);
	window.status = "Loading Thumbnail "+index;
	THUMBNAILS[index] = new Image(thumbnail_dimensions[index*2], thumbnail_dimensions[index*2+1]);
	if (doNext) {
		THUMBNAILS[index].onload = new Function('setTimeout("PrefetchNextThumb('+(index+1)+')",10)');
	};
	THUMBNAILS[index].src = thumbnail_files[index];
};

//###########################################################################
//###########################################################################
//## stub functions
//###########################################################################
//###########################################################################
function SetupLayout ()
{
  CalculateLayout ();
	if (is_ie4) {
		//setTimeout('PrefetchNextImage(1)',10);
		setTimeout('PrefetchNextThumb(1)',10);
	};

  //** do not print layout in FullTemplate mode
  if (generation_mode == 3) return;

  if (is_ie4)      PrintLayoutIE4 ();
  else if (is_ns)  PrintLayoutNS ();
  else             ReportError ();
};
function Display ()
{
  if (is_ie4)      DisplayIE4 ();
  else if (is_ns)  DisplayNS ();
  else             ReportError ();
};
function DisplayActualImage(actual_image_index)
{
  if (is_ie4)      DisplayActualImageIE4(actual_image_index);
  else if (is_ns)  DisplayActualImageNS(actual_image_index);
  else             ReportError ();
};
function DisplayZoomInWindow (slide_show_mode, actual_image_index)
{
  if (is_ie4)      DisplayZoomInWindowIE4 (slide_show_mode, actual_image_index);
  else if (is_ns)  DisplayZoomInWindowNS (slide_show_mode, actual_image_index);
  else             ReportError ();
};

//###########################################################################
//###########################################################################
//## Common functions
//###########################################################################
//###########################################################################

/////////////////////////////////////////////////////////////////////////////
// function Next()
function Next()
{
  if(current_page < number_of_pages-1) {
    current_page++;
    Display();
  };
};
/////////////////////////////////////////////////////////////////////////////
// function Previous()
function Previous()
{
  if (current_page > 0) {
    current_page--;
    Display();
  };
};
/////////////////////////////////////////////////////////////////////////////
// function First()
function First()
{
  current_page=0;
  Display();
};
/////////////////////////////////////////////////////////////////////////////
// function Last()
function Last()
{
  current_page=number_of_pages-1;
  Display();
};
/////////////////////////////////////////////////////////////////////////////
// function ZoomLink(i)
function ZoomLink(i)
{
  if(!album_type)
    DisplayZoomInWindow(0,i);
};
/////////////////////////////////////////////////////////////////////////////
// function Link(i)
function Link(i)
{
  var zoom_num=current_page*slides_per_page+i;;
  if(zoom_image) {
    if(album_type)
      DisplayZoomInWindow(0,zoom_num);
    else
      DisplayActualImage(zoom_num);
  } else if(slide_link) {
    if (open_link_in_new_window) {
      window.open(slide_links[zoom_num],null);
    } else {
      window.navigate (slide_links[zoom_num]);
    };
  };
};
/////////////////////////////////////////////////////////////////////////////
// function SlideShow()
function SlideShow()
{
  if(zoom_image)
    DisplayZoomInWindow(1,1);
};
/////////////////////////////////////////////////////////////////////////////
// utility
function ReportError ()
{
  alert ("Your version of Web Browser is completely obsolete !!!\nTry something more recent");
};
function BOUND (x, min, max)
{
  return (x < min) ? min : (x > max) ? max : x;
};
function MAX (a, b)
{
  return (a > b) ? a : b;
};


/////////////////////////////////////////////////////////////////////////////
// function CalculateLayout()
function CalculateLayout ()
{
  if (generation_mode == 3) {
    var LAYER = (is_ie4) ? document.all[nzoom_id] : NULL;

    actual_image_area_width  = LAYER.style.pixelWidth; //client_width-actual_image_area_left-album_right_margin-actual_image_right_margin;
    actual_image_area_height = LAYER.style.pixelHeight; //client_height-album_bottom_margin-actual_image_bottom_margin-actual_image_area_top;
  };

  number_of_pages = Math.ceil (total_slides/slides_per_page);

  //** Set album title.
  t='<font color="'+album_name_color+'" face="'+album_name_font+'" size='+album_name_size+'>'+album_name_type+album_name+album_name_type_end+'</font>';
  if(album_name_shadow)
    ts='<font color="'+album_name_shadow_color+'" face="'+album_name_font+'" size='+album_name_size+'>'+album_name_type+album_name+album_name_type_end+'</font>';

  if (is_ie4) {
  	document.all[album_title_id].innerHTML = t;
		if(album_name_shadow)
			document.all[album_title_shadow_id].innerHTML = ts;
	};
};


//###########################################################################
//###########################################################################
//## MS Internet Explorer-specific functions
//###########################################################################
//###########################################################################


/////////////////////////////////////////////////////////////////////////////
// function SetupLayout() //setup the layout of the album.
function PrintLayoutIE4 ()
{
  var nslide_id, slide_id, text_id, row_ver_pos, text_ver_pos, slide_left, actual_image_area_left, actual_image_area_top;
  var frames_text = "", nzoom_text = "", t = "", ts = ""; //** HTML source

  if(auto_layout) {
    client_width  = (margins_mode) ? (document.body.clientWidth-4) : set_client_width;
    client_height = (margins_mode) ? (document.body.clientHeight-27) : set_client_height;

    //** Calculate number of rows and columns in album.
    slide_columns = Math.floor( (client_width-album_right_margin-album_left_margin+hor_space)/(slide_width+hor_space));
    if(auto_layout != 1) {
      if(slide_columns>max_columns || auto_layout==2)
        slide_columns=max_columns;
    };

    slide_rows = Math.floor((client_height-album_top_margin-album_bottom_margin+ver_space)/(slide_height+ver_space));

    if(auto_layout != 1) {
      if(slide_rows>max_rows || auto_layout==2)
        slide_rows=max_rows;
    };

    if(!album_type) { //** auto_layout_type= 0, thumbnails+Actual image
      if(slides_orientation) {
        //** horizontal
        slide_rows=1;
        actual_image_area_left=album_left_margin+actual_image_left_margin;
        actual_image_area_top=album_top_margin+actual_image_top_margin+slide_height+ver_space;
      } else {
        //** vertical
        slide_columns=1;
        actual_image_area_left=album_left_margin+actual_image_left_margin+slide_width+hor_space;
        actual_image_area_top=album_top_margin+actual_image_top_margin;
      };
      actual_image_area_width=client_width-actual_image_area_left-album_right_margin-actual_image_right_margin;
      actual_image_area_height=client_height-album_bottom_margin-actual_image_bottom_margin-actual_image_area_top;
    };

    slides_per_page = slide_columns*slide_rows;

    var i = 1;
    for(row = 0; row < slide_rows; row++) {
      row_ver_pos = album_top_margin+row*(slide_height+ver_space);
      text_ver_pos = row_ver_pos+slide_height+ver_text_space;
      for(col = 0; col < slide_columns; col++) {
        //** Positioning of the slides and texts on the screen.
        slide_id=slide_name+i.toString();
        text_id=text_name+i.toString();
        frame_id=frame_name+i.toString();

        slide_left=album_left_margin+col*(slide_width+hor_space);

        var img_text = ' border=0 width='+slide_width+' height='+slide_height;

        t += '<div id="'+slide_id+'" style="position:absolute;width:'+slide_width+'px;height:'+slide_height+'px;left:'+slide_left+'px;top:'+row_ver_pos+'px;"><img id="img'+slide_id+'"'+img_text+'></div>\n';
        if (frame_image!="")
          t += '<div id="'+frame_id+'" style="position:absolute;width:'+slide_width+'px;height:'+slide_height+'px;left:'+slide_left+'px;top:'+row_ver_pos+'px;"><img id="img'+frame_id+'"'+img_text+'></div>\n';
        t += '<div id="'+text_id+'" style="position:absolute;width:'+slide_width+'px;left:'+slide_left+'px;top:'+text_ver_pos+'px;"></div>\n';

        i++;
      }; //** columns
    }; //** rows

    if(!album_type) { //** auto_layout_type= 0, thumbnails+Actual image
      var img_txt = ' border=0 width='+actual_image_area_width+' height='+actual_image_area_height;

      t += '<div id="'+nzoom_id+'" style="position:absolute;width:'+actual_image_area_width+'px;height:'+actual_image_area_height+'px;left:'+actual_image_area_left+'px;top:'+actual_image_area_top+'px;';
      if (zoom_background_color) t += 'background-color:'+zoom_background_color+';';
      if (zoom_background_image) t += 'background-image:url('+zoom_background_image+');';
      t += '"><img id="img'+nzoom_id+'"'+img_text+'></div> \n';
    };

    eval ('document.all[photo_album_id].innerHTML = t;');
  }; //** AutoLayout

  number_of_pages = Math.ceil (total_slides/slides_per_page);
}; //** SetupLayout

/////////////////////////////////////////////////////////////////////////////
// function Display()
function DisplayIE4 ()
{
  var item_name, text_item_name;
  var temp_string,title_text,description_text, temp_border_string="";
  var slide_index, s_left, s_top;
  var cur_frame_image;

  for(i = 1; i <= slides_per_page; i++) {
    if(current_page*slides_per_page+i <= total_slides) {
      slide_index=current_page*slides_per_page+i;
      cur_frame_image=frame_image;
    } else {
      slide_index=0;
      cur_frame_image=thumbnail_files[slide_index];
    };

    th_width  = thumbnail_dimensions[slide_index*2];
    th_height = thumbnail_dimensions[slide_index*2+1];
    if (slide_index != 0) {
      temp_border_string  = 'position:absolute;width:'+th_width+'px;height:'+th_height+'px;';
      if (slide_border_width>0)
        temp_border_string += 'border-width:'+slide_border_width+'px;border-style:'+slide_border_style+';border-color:'+slide_border_color+';';
    } else {
      temp_border_string=' border-width:0px;';
    };

    title_text='<p><font color="'+slide_title_color+'" face="'+slide_title_font+'" size='+slide_title_size+'>'+slide_title_type+text[slide_index]+slide_title_type_end+'</font></p>';
    s_left=Math.ceil((slide_width-th_width)/2);
    s_top=Math.ceil((slide_height-th_height)/2);

    item_name=slide_name+i.toString();
    frame_item_name=frame_name+i.toString();
    if(slide_description)
      description_text=alternate_text[slide_index];
    else
      description_text="";

    temp_string  = "";
    if (slide_index > 0) {
      temp_string += '<a href="javascript:Link('+i+');">\n';
      temp_string += '<img src="'+thumbnail_files[slide_index]+'" hspace='+s_left+' vspace='+s_top;
      temp_string += ' width='+th_width+' height='+th_height+' alt="'+description_text+'"';
      if (slide_border_width>0)
        temp_string += ' style="'+temp_border_string+'"';
      else
        temp_string += ' border=0';
      temp_string += '>\n';
      temp_string += '</a>\n';
    };
    frames_temp_string = "";
    if(frame_image!="" && auto_layout && slide_index>0)
      frames_temp_string='<a href="javascript:Link('+i+');"><img src="'+cur_frame_image+'" alt="'+description_text+'" border=0></a>';

    text_item_name=text_name+i.toString();

    if(slide_title)
      document.all[text_item_name].innerHTML=title_text;
    document.all[item_name].innerHTML=temp_string;
    if(frame_image!="" && auto_layout)
      document.all[frame_item_name].innerHTML= frames_temp_string;
  };  //** end thumbnails loop

  if(!album_type) //** auto_layout_type= 0, thumbnails+Actual image
    DisplayActualImage(current_page*slides_per_page+1);
};

/////////////////////////////////////////////////////////////////////////////
// function DisplayActualImage(actual_image_index)
function DisplayActualImageIE4(actual_image_index)
{
  var t, s_left, s_top;
  var imageAR,imageWidth,imageHeight,areaAR;

  imageWidth=image_dimensions[actual_image_index*2];
  imageHeight=image_dimensions[actual_image_index*2+1];

  //** Actual image aspect ratio.
  imageAR=imageWidth/imageHeight;
  //** Actual image area aspect ratio.
  areaAR=actual_image_area_width/actual_image_area_height;

  if(imageWidth >actual_image_area_width || imageHeight >actual_image_area_height) {
    if(imageAR > areaAR) {
      imageWidth=actual_image_area_width;
      imageHeight=Math.ceil(imageWidth/imageAR);
    } else {
      imageHeight=actual_image_area_height;
      imageWidth=Math.ceil(imageHeight*imageAR);
    };
  };

  s_left = Math.ceil((actual_image_area_width-imageWidth)/2);
  s_top  = Math.ceil((actual_image_area_height-imageHeight)/2);

  t = "";
  t += '<a href="javascript:ZoomLink('+actual_image_index+');">\n';
  t += '<img src="'+image_files[actual_image_index]+'"';
  t += ' hspace='+s_left+' vspace='+s_top;
  t += ' width='+imageWidth+' height='+imageHeight;
  t += ' style="border-width:'+actual_border_width+'px;border-style:'+actual_border_style+';border-color:'+actual_border_color+';"';
  t += '></a>';

  document.all[nzoom_id].innerHTML= t;
};

/////////////////////////////////////////////////////////////////////////////
// function DisplayZoomInWindow(slide_show_mode, actual_image_index)
function DisplayZoomInWindowIE4(slide_show_mode, actual_image_index)
{
  if (!use_advanced_features) {
    DisplayZoomInWindowNS (slide_show_mode, actual_image_index);
    return;
  };

  var t; //** HTML source of the Zoom Window.
  var temp="";
  var navigator_image_file;
  var windowWidth, windowHeight;

  if (window.screen) {
    windowWidth = screen.availWidth-8;
    windowHeight =  screen.availHeight-27;
  } else {
    windowWidth = 800;
    windowHeight = 600;
  };

  t = '<html>\n<head>\n';
  t += '<title>' + text[actual_image_index] + '</title>\n';
  t += '<style>\n';
  t += '.nav_ctrl_wnd { color:blue;font-size:12px;font-weight:bold;font-family:Arial;position:absolute;height:18px; }\n';
  t += '</style>\n';
  t += '<script  language="JavaScript1.2">\n';
  t += 'var slide_show_mode='+slide_show_mode+', zoom_num='+actual_image_index+', slide_show_delay='+slide_show_delay+', album_type='+ album_type+', m_flag=0;\n';
  t += '</script>\n';
  t += '<script  language="JavaScript1.2" src="'+album_data_file+'"></script>\n';
  t += '<script  language="JavaScript1.2" src="zoom.js"></script>\n';

  t += '<script language="JavaScript1.2">\n';
  t += 'function SetNavigatorImageStub() { if(m_flag) SetNavigatorImage(); else  setTimeout("SetNavigatorImageStub()",1000);}\n';

  if(!slide_show_mode) {
    t += 'function MoveNavigatorStub() { if(m_flag) MoveNavigator();}\n';
    t += 'function MoveNavigatorFrameStub() { if(m_flag) StartMoveNavigatorFrame();}\n';
  };
  t += '</script>\n';

  t += '</head>\n\n';
  t += '<body bgcolor="'+zoom_background_color+'" background="'+zoom_background_image+'"';
  t += ' onLoad="SetupZoomWindow();DisplayZoom();m_flag=1;"';
  t += '>\n';

  img_width  = BOUND (image_dimensions[actual_image_index*2], 0, windowWidth);
  img_height = BOUND (image_dimensions[actual_image_index*2+1], 0, windowHeight);
  left_pos = Math.floor(windowWidth/2 - img_width/2);
  if (left_pos < 0) left_pos = 0;
  top_pos  = Math.floor(windowHeight/2 - img_height/2);
  if (top_pos < 0) top_pos = 0;

  t += '  <div id=zoom_window style="position:absolute;left:0px;top:0px;width:0px;height:0px;"';
  if (!slide_show_mode) t += ' onMouseMove="MoveNavigatorStub();" onMouseUp="StopMoveNavigator();"';
  t += '>\n    <a href="javascript:self.close();">\n';
  t += '    <img border=0 id=actual_image src="'+ image_files[actual_image_index] +'" alt="' +alternate_text[actual_image_index]+'"';
  t += ' style="position:absolute;left:0px;top:0px;width:0px;height:0px;"'
  t += ' onError="ZoomImageError();" onLoad="SetNavigatorImageStub();"';
  t += '></a>\n';

  if(!slide_show_mode) {
    t += GenerateNavigatorTextIE4 ();
  };
  t += '</div>\n';
  t += '</body>\n</html>\n';

  var settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=0,top=0,width='+windowWidth.toString()+',height='+windowHeight.toString();
  ZoomWindow=window.open("",null,settings);
  ZoomWindow.document.write(t);
  ZoomWindow.document.close();
};


function GenerateNavigatorTextIE4 ()
{
  var text = "";

  text+='<div id=navigator_window style="background-color:silver; border-bottom:silver 2px outset; border-left:silver 2px outset; border-right:silver 2px outset; border-top:silver 2px outset; height:140px; left:9px; position:absolute; top:13px; width:135px;">\n';
  text+='<SELECT ID=zoom_value_list onchange="ZoomValueChanged();" style="font-size:10px; height:19px; left:1px; position:absolute; top:95px; width:86px;">\n';
  text+=' <OPTION value=-4 >25%</OPTION>  \n';
  text+=' <OPTION value=-3 >33%</OPTION>  \n';
  text+=' <OPTION value=-2 >50%</OPTION>  \n';
  text+=' <OPTION value=1>100%</OPTION> \n';
  text+=' <OPTION value=2>200%</OPTION> \n';
  text+=' <OPTION value=3>300%</OPTION> \n';
  text+=' <OPTION value=4>400%</OPTION> \n';
  text+=' <OPTION selected value=0 >Fit to screen</OPTION>  \n';
  text+='</SELECT> \n';

  text+='  <INPUT id="ZoomIn"   type=button value="+"  class=nav_ctrl_wnd style="left:88px;  top:95px;  width:19px;" onClick="ZoomIn();">\n';
  text+='  <INPUT id="ZoomOut"  type=button value="-"  class=nav_ctrl_wnd style="left:108px; top:95px;  width:19px;" onClick="ZoomOut();">\n';
  text+='  <INPUT id="First"    type=button value="<<" class=nav_ctrl_wnd style="left:0px;   top:116px; width:21px;" onClick="FirstZoom();">\n';
  text+='  <INPUT id="Previous" type=button value="<"  class=nav_ctrl_wnd style="left:21px;  top:116px; width:21px;" onClick="PreviousZoom();">\n';
  text+='  <INPUT id="Next"     type=button value=">"  class=nav_ctrl_wnd style="left:42px;  top:116px; width:21px;" onClick="NextZoom();">\n';
  text+='  <INPUT id="Last"     type=button value=">>" class=nav_ctrl_wnd style="left:63px;  top:116px; width:21px;" onClick="LastZoom();">\n';
  text+='  <INPUT id="ZoomNumber"           value=""   style="background:silver; color:black; font-size:10px; height:18px; left:84px; position:absolute; top:116px; width:45px">\n';

  text+='<div id=navigator_caption_window style="background-color:blue; color:white; font-family:MS Sans Serif; font-size:12px; font-weight:bold; height:16px; left:2px; position:absolute; top:0px; width:127px; cursor:move;" onMouseMove="StartMoveNavigator();"><p style="left:3px; top:1px; position:absolute;";>Navigator</p></div>\n';
  text+='<div id=navigator_image_window style="border-bottom:silver 2px inset; border-left:silver 2px inset; border-right:silver 2px inset; border-top:silver 2px inset; height:73; left:2; position:absolute; top:19; width:127;">\n';
  text+='<img border=0 id=navigator_image src="'+image_files[0]+'" style="height:0px; left:0px; position:absolute; top:0px; width:0px;"> \n';
  text+='<div id=navigator_frame style="height:0; left:0; position:absolute; top:0; width:0; border:1px red; border-style:solid; cursor:move;" onMouseMove="MoveNavigatorFrameStub();" onMouseUp="StopMoveNavigatorFrame();"><table width=100% height=100%><tr><td>&nbsp;</td></tr></table>\n';

  text+='   </div>\n  </div>\n </div>\n';
  text+=' <div id=navigator_window_frame style="height:142px; left:9px; position:absolute; top:13px; width:135px; border:solid white; border-style:solid; visibility:hidden;"></div>\n';
  text+='</div> \n';

  return text;
};

//###########################################################################
//###########################################################################
//## Netscape Communicator-specific functions
//###########################################################################
//###########################################################################


function GenerateGlobal (i)
{
  var str = "";

  var slide_id=slide_name+i.toString();
  var text_id=text_name+i.toString();
  var frame_id=frame_name+i.toString();

  var position = 'position:absolute;left:0px;width:'+(slide_width+hor_space).toString()+'px;height:'+(slide_height+ver_space).toString()+'px;';

  str += '<div id='+slide_id+' style="'+position+'top:0px;">&nbsp</div>\n';
  //if ((frame_image != "") || (slide_border_width > 0))
  str += '<div id='+frame_id+' style="'+position+'top:0px;">&nbsp</div>\n';
  str += '<div id='+text_id+' style="'+position+';top:'+(slide_height+ver_text_space).toString()+'px;">&nbsp</div>\n';

  return str;
};


/////////////////////////////////////////////////////////////////////////////
// function SetupLayout() //setup the layout of the album.
function PrintLayoutNS ()
{
  var nslide_id, slide_id, text_id, row_ver_pos, text_ver_pos, slide_left, actual_image_area_left, actual_image_area_top;
  var frames_text = "", nzoom_text = "", t = "", ts = ""; //** HTML source

  if(auto_layout) {
    client_width=(margins_mode) ? window.innerWidth : set_client_width;
    client_height=(margins_mode) ? window.innerHeight : set_client_height;

    //** Calculate number of rows and columns in album.
    slide_columns = Math.floor ((client_width-album_right_margin-album_left_margin+hor_space)/(slide_width+hor_space));
    if(auto_layout != 1) {
      if(slide_columns>max_columns || auto_layout==2)
        slide_columns=max_columns;
    };

    slide_rows= Math.floor((client_height-album_top_margin-album_bottom_margin+ver_space)/(slide_height+ver_space));

    if(auto_layout != 1) {
      if(slide_rows>max_rows || auto_layout==2)
        slide_rows=max_rows;
    };

    if(!album_type) { //** auto_layout_type= 0, thumbnails+Actual image
      if(slides_orientation) {
        //** horizontal
        slide_rows=1;
        actual_image_area_left=album_left_margin+actual_image_left_margin;
        actual_image_area_top=album_top_margin+actual_image_top_margin+slide_height+ver_space;
      } else {
        //** vertical
        slide_columns=1;
        actual_image_area_left=album_left_margin+actual_image_left_margin+slide_width+hor_space;
        actual_image_area_top=album_top_margin+actual_image_top_margin;
      };
      actual_image_area_width=client_width-actual_image_area_left-album_right_margin-actual_image_right_margin;
      actual_image_area_height=client_height-album_bottom_margin-actual_image_bottom_margin-actual_image_area_top;
    };

    slides_per_page = slide_columns*slide_rows;

    //** create HTML text of thumbnails layer
    var i = 1;
    for(row = 0; row < slide_rows; row++) {
      for(col = 0; col < slide_columns; col++) {
        //** Positioning of the slides and texts on the screen.
        slide_id=slide_name+i.toString();
        text_id=text_name+i.toString();
        frame_id=frame_name+i.toString();

        position  = 'position:absolute;';
        position += 'left:'+(col*(slide_width+hor_space)).toString()+'px;top:'+(row*(slide_height+ver_space)).toString()+'px;';
        position += 'width:'+(slide_width+hor_space).toString()+'px;height:'+(slide_height+ver_space).toString()+'px;';

        frames_text += '<div id=global'+i.toString()+' style="'+position+'">\n';
        //frames_text += '<table width=100% height=100% border=0><tr><td width=100% height=100% border=0>\n';
        //frames_text += '<div id=aassa'+i.toString()+' style="position:absolute;">\n';
        frames_text += GenerateGlobal (i);
        //frames_text += '</div>\n&nbsp</td></tr></table>\n';
        frames_text += '</div>\n';

        i++;
      }; //** columns
    }; //** rows

    //** now setup layer
    document.layers[frames_id].x = album_left_margin+4;
    document.layers[frames_id].y = album_top_margin+20;
    document.layers[frames_id].width = slide_columns*(slide_width+hor_space);
    document.layers[frames_id].height = slide_rows*(slide_height+ver_space);
    //document.layers[frames_id].bgColor = "yellow";

    document.layers[frames_id].zIndex = 1;
    document.layers[frames_id].document.write (frames_text);
    document.layers[frames_id].document.close();


    if(!album_type) { //** auto_layout_type= 0, thumbnails+Actual image
      nzoom_text += '<div id='+nzoom_id+' style="position:absolute;width:'+(actual_image_area_width-5).toString()+'px;height:'+(actual_image_area_height-5).toString()+'px;">\n'; //left:'+(actual_image_area_left).toString()+'px;top:'+(actual_image_area_top).toString()+'px;">\n';
      nzoom_text += '<table width='+(actual_image_area_width-5).toString()+' height='+(actual_image_area_height-5).toString()+'>\n';
      nzoom_text += '<tr><td width='+(actual_image_area_width-5).toString()+' height='+(actual_image_area_height-5).toString()+'';
      if (zoom_background_color) nzoom_text += ' bgcolor="'+zoom_background_color+'"';
      if (zoom_background_image) nzoom_text += ' background="'+zoom_background_image+'"';
      nzoom_text += '><div id='+nzoom_image_id+' style="position:absolute;"></div>\n&nbsp</td></tr>\n</table>\n';
      nzoom_text += '</div>\n';
    };

    document.layers["main-menu"].zIndex = 2000;

    if (nzoom_text) {
      document.layers[photo_album_id].zIndex = 2;
      document.layers[photo_album_id].x = actual_image_area_left;
      document.layers[photo_album_id].y = actual_image_area_top+16;
      document.layers[photo_album_id].width  = actual_image_area_width;
      document.layers[photo_album_id].height = actual_image_area_height;
      document.layers[photo_album_id].document.write(nzoom_text);
      document.layers[photo_album_id].document.close();
    };
  }; //** AutoLayout

  //** Set album title.
  t='<font color="'+album_name_color+'" face="'+album_name_font+'" size='+album_name_size+'>'+album_name_type+album_name+album_name_type_end+'</font>';
  if(album_name_shadow)
    ts='<font color="'+album_name_shadow_color+'" face="'+album_name_font+'" size='+album_name_size+'>'+album_name_type+album_name+album_name_type_end+'</font>';

  //document.layers[album_title_id].bgColor = "red";
  document.layers[album_title_id].document.write(t);
  document.layers[album_title_id].document.close();
  if (album_name_shadow) {
    document.layers[album_title_shadow_id].document.write(ts);
    document.layers[album_title_shadow_id].document.close();
  };

  number_of_pages = Math.ceil (total_slides/slides_per_page);
}; //** SetupLayout


/////////////////////////////////////////////////////////////////////////////
// function Display() -- Netscape
function DisplayNS ()
{
  var item_name, text_item_name;
  var temp_string,title_text,description_text, temp_border_string="";
  var slide_index, s_left, s_top;
  var cur_frame_image;

  for(i = 1; i <= slides_per_page; i++) {
    if(current_page*slides_per_page+i <= total_slides) {
      slide_index=current_page*slides_per_page+i;
      cur_frame_image=frame_image;
    } else {
      slide_index=0;
      cur_frame_image=thumbnail_files[slide_index];
    };

    th_width  = thumbnail_dimensions[slide_index*2];
    th_height = thumbnail_dimensions[slide_index*2+1];
    if (slide_index != 0) {
      temp_border_string  = 'position:absolute;';
      temp_border_string += 'width:'+MAX(th_width,slide_width).toString()+'px;height:'+MAX(th_height,slide_height).toString()+'px;';
      if (slide_border_width>0) {
        temp_border_string += 'border-width:'+slide_border_width+'px;border-style:'+slide_border_style+';border-color:'+slide_border_color+';';
      };
    } else {
      temp_border_string=' border-width:0px;';
    };

    title_text='<p><font color="'+slide_title_color+'" face="'+slide_title_font+'" size='+slide_title_size+'>'+slide_title_type+text[slide_index]+slide_title_type_end+'</font></p>';
    s_left=Math.ceil((slide_width-th_width)/2);
    s_top=Math.ceil((slide_height-th_height)/2);

    item_name=slide_name+i.toString();
    frame_item_name=frame_name+i.toString();
    if(slide_description)
      description_text=alternate_text[slide_index];
    else
      description_text="";

    global_id = 'global'+i.toString();
    //aassa_id  = 'aassa'+i.toString();
    LAYER = document.layers[frames_id].layers[global_id];//.layers[aassa_id];
    //LAYER.bgColor = "Green";
    LAYER.zIndex = 1000;
    LAYER.width = slide_width+hor_space;
    LAYER.height = slide_height+ver_space;

    ttt = '';
    if (slide_index > 0) {
      ttt += '<div id=border'+i.toString()+' style="'+temp_border_string+'">\n';
      ttt += '<a href="javascript:Link('+i+');">\n';
      ttt += '<img src="blank.gif" alt="'+description_text+'" border=0 width='+(MAX(th_width,slide_width)-slide_border_width*2-4).toString()+' height='+(MAX(th_height,slide_height)-slide_border_width-10).toString()+'>\n';
      ttt += '</a>\n';
      ttt += '</div>\n';
    };
    LAYER.layers[frame_item_name].document.open();
    LAYER.layers[frame_item_name].document.write(ttt);
    LAYER.layers[frame_item_name].document.close();

    temp_string  = "";
    if (slide_index > 0) {
      temp_string += '<a href="javascript:Link('+i+');">\n';
      temp_string += '<img src="'+thumbnail_files[slide_index]+'" hspace='+s_left+' vspace='+s_top;
      temp_string += ' width='+th_width+' height='+th_height+' alt="'+description_text+'"';
      temp_string += ' border=0';
      temp_string += '>\n';
      temp_string += '</a>\n';
    };

    frames_temp_string = "";
    if (frame_image!="" && auto_layout && slide_index>0) {
      frames_temp_string='<a href="javascript:Link('+i+');"><img src="'+cur_frame_image+'" alt="'+description_text+'" border=0></a>';
    } else if (slide_border_width>0 && slide_index>0) {
      frames_temp_string
    };

    text_item_name=text_name+i.toString();

    LAYER.layers[item_name].document.open();
    LAYER.layers[item_name].document.write(temp_string);
    LAYER.layers[item_name].document.close();
    if(slide_title) {
      LAYER.layers[text_item_name].document.open();
      LAYER.layers[text_item_name].document.write(title_text);
      LAYER.layers[text_item_name].document.close();
    };
    if(frame_image!="" && auto_layout) {
      LAYER.layers[frame_item_name].document.open();
      LAYER.layers[frame_item_name].document.write(frames_temp_string);
      LAYER.layers[frame_item_name].document.close();
    };

    if (LAYER.layers[item_name])
      LAYER.layers[item_name].zIndex = 6;

    if (LAYER.layers[text_item_name])
      LAYER.layers[text_item_name].zIndex = 7;

    if (LAYER.layers[frame_item_name]) {
      LAYER.layers[frame_item_name].zIndex = 8;
      border_name = 'border'+i.toString();
      if (LAYER.layers[frame_item_name].layers[border_name])
        LAYER.layers[frame_item_name].layers[border_name].zIndex = 10;
    };
  };  //** end thumbnails loop

  if(!album_type) //** auto_layout_type= 0, thumbnails+Actual image
    DisplayActualImage(current_page*slides_per_page+1);
};

/////////////////////////////////////////////////////////////////////////////
// function DisplayActualImage(actual_image_index)
function DisplayActualImageNS (actual_image_index)
{
  var t, s_left, s_top;
  var imageAR,imageWidth,imageHeight,areaAR;

  imageWidth=image_dimensions[actual_image_index*2];
  imageHeight=image_dimensions[actual_image_index*2+1];

  //** Actual image aspect ratio.
  imageAR=imageWidth/imageHeight;
  //** Actual image area aspect ratio.
  areaAR=actual_image_area_width/actual_image_area_height;

  if(imageWidth >actual_image_area_width || imageHeight >actual_image_area_height) {
    if(imageAR > areaAR) {
      imageWidth=actual_image_area_width;
      imageHeight=Math.ceil(imageWidth/imageAR);
    } else {
      imageHeight=actual_image_area_height;
      imageWidth=Math.ceil(imageHeight*imageAR);
    };
  };

  s_left=Math.ceil((actual_image_area_width-imageWidth)/2);
  s_top=Math.ceil((actual_image_area_height-imageHeight)/2);

  var temp_border_style = '';
  if (actual_border_width > 0) {
    imageWidth -= actual_border_width*2;
    imageHeight -= actual_border_width*2;
  };
  t  = '<div id=nzoomitself style="position:absolute;left:'+(s_left+4).toString()+'px;top:'+(s_top+4).toString()+'px;width:'+(imageWidth-12).toString()+'px;height:'+(imageHeight-5).toString()+'px;zIndex:8000;';
  if (actual_border_width) t += 'border-width:'+actual_border_width+'px;border-style:'+actual_border_style+';border-color:'+actual_border_color+';';
  t += '">\n';
  t += '<a href="javascript:ZoomLink('+actual_image_index+');">\n';
  t += '<img src="'+image_files[actual_image_index]+'" border=0 width='+(imageWidth-13).toString()+' height='+(imageHeight-7).toString()+'>\n</a>\n';
  t += '</div>\n';

  LAYER = document.layers[photo_album_id].layers[nzoom_id].layers[nzoom_image_id];
  LAYER.document.open();
  LAYER.document.write(t);
  LAYER.document.close();
};

/////////////////////////////////////////////////////////////////////////////
// function DisplayZoomInWindow(slide_show_mode, actual_image_index)
function DisplayZoomInWindowNS (slide_show_mode, actual_image_index)
{
  var t; //** HTML source of the Zoom Window.
  var temp="";
  var navigator_image_file;
  var windowWidth, windowHeight;

  if (window.screen) {
    windowWidth = screen.availWidth-8;
    windowHeight =  screen.availHeight-27;
  } else {
    windowWidth = 800;
    windowHeight = 600;
  };

  t = '<html>\n<head>\n';
  t += '<title>' + text[actual_image_index] + '</title>\n';
  t += '</head>\n\n';
  t += '<body bgcolor="'+zoom_background_color+'" background="'+zoom_background_image+'"';
  t += '>\n';

  img_width  = BOUND (image_dimensions[actual_image_index*2], 0, windowWidth);
  img_height = BOUND (image_dimensions[actual_image_index*2+1], 0, windowHeight);
  left_pos = Math.floor(windowWidth/2 - img_width/2);
  if (left_pos < 0) left_pos = 0;
  top_pos  = Math.floor(windowHeight/2 - img_height/2);
  if (top_pos < 0) top_pos = 0;

  t += '  <div id=zoom-window style="position:absolute;left:'+left_pos.toString()+'px;top:'+top_pos.toString()+'px;width:'+img_width.toString()+'px;height:'+img_height.toString()+'px;">\n'
  t += '    <a href="javascript:self.close();">\n';
  t += '      <img id=actual-image border=0 src="'+image_files[actual_image_index]+'" alt="'+alternate_text[actual_image_index]+'" width='+img_width.toString()+' height='+img_height.toString()+'>\n';
  t += '    </a>\n';
  t += '  </div>\n';
  t += '</body>\n</html>\n';

  var settings = 'resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,left=0,top=0,width='+windowWidth.toString()+',height='+windowHeight.toString();
  ZoomWindow=window.open("",null,settings);
  ZoomWindow.document.write(t);
  ZoomWindow.document.close();
};
