//###########################################################################
//## ALBUM.JS -- WebPhotoAlbum resource file
//## Performs all action upon main page of album
//## 06.07.2000
//###########################################################################

// Names and IDs of Album's objects.
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 actual_image_id="actual-image"; // use "photo-album" for previous version
var photo_album_id="photo-album"; // use "frames" for previous version

// 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 = browser_check && ((document.all)    ? true : false);
var is_ns  = browser_check && ((document.layers) ? true : false);


//###########################################################################
//###########################################################################
//## stub functions
//###########################################################################
//###########################################################################
function SetupLayout ()
{
  (is_ie4)?CalculateLayoutIE4():(is_ns)?CalculateLayoutNS():ReportError();
  if (generation_mode == 3) return;
  //** do not print layout in FullTemplate mode
  (is_ie4)?PrintLayoutIE4():(is_ns)?PrintLayoutNS():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()
{
  if (current_page != 0) {
    current_page=0;
    Display();
  };
};
/////////////////////////////////////////////////////////////////////////////
// function Last()
function Last()
{
  if (current_page != number_of_pages-1) {
    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("You're using old version of Web Browser !!!\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 MIN(a,b){return(a<b)?a:b;};

//###########################################################################
//###########################################################################
//## MS Internet Explorer-specific functions
//###########################################################################
//###########################################################################

/////////////////////////////////////////////////////////////////////////////
// function CalculateLayout()
function CalculateLayoutIE4 ()
{
  var temp = "";
  if ((generation_mode == 3) && !album_type) {
    var LAYER = document.all[nzoom_id];
    actual_image_area_width  = LAYER.style.pixelWidth;
    actual_image_area_height = LAYER.style.pixelHeight;
  };
  number_of_pages = Math.ceil (total_slides/slides_per_page);

  //** Set album title.
  document.all[album_title_id].innerHTML = album_name;
  if(album_name_shadow)
    document.all[album_title_shadow_id].innerHTML = album_name;
};

/////////////////////////////////////////////////////////////////////////////
// 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 = ""; //** HTML source

  if(auto_layout) {
    client_width  = (margins_mode) ? (document.body.clientWidth-1) : set_client_width;
    client_height = (margins_mode) ? (document.body.clientHeight-1) : 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;
    };

    //** generate HTML for frames layer
    slides_per_page = slide_columns*slide_rows;
    t += CreateFramesText (album_left_margin, album_top_margin, slide_rows, slide_columns);

    //** generate HTML for nzoom layer (actual image layer)
    if(!album_type) { //** auto_layout_type= 0, thumbnails+Actual image
      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 += '"></div> \n';
    };

    document.all[actual_image_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,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;';
    };

    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();
    description_text=(slide_description)?alternate_text[slide_index]:"";

    temp_string  = "";
    if (slide_index > 0) {
      if (slide_link) 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';
      if (slide_link) temp_string += '</a>\n';
    };
    frames_temp_string = "";
    if(frame_image!="" && auto_layout && slide_index>0) {
      if (slide_link) frames_temp_string+='<a href="javascript:Link('+i+');">';
      frames_temp_string+='<img src="'+cur_frame_image+'" alt="'+description_text+'" border=0>';
      if (slide_link) frames_temp_string+='</a>';
    };

    if(slide_title) {
      var text_item_name=text_name+i.toString();
      document.all[text_item_name].innerHTML=text[slide_index];
    };
    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) //** thumbnails table=0, thumbnails+Actual image=1
    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 temp=""; //** HTML source of the Zoom Window.
  var navigator_image_file;
  var windowWidth, windowHeight;

  if (window.screen) {
    windowWidth = screen.availWidth-8;
    windowHeight =  screen.availHeight-27;
  } else {
    windowWidth = 800;
    windowHeight = 600;
  };

  temp += '<html>\n<head>\n';
  temp += '<title>' + text[actual_image_index] + '</title>\n';
  temp += '<script  language="JavaScript1.2">\n';
  temp += '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';
  temp += '</script>\n';
  temp += '<script  language="JavaScript1.2" src="'+album_data_file+'"></script>\n';
  temp += '<script  language="JavaScript1.2" src="zoom.js"></script>\n';

  temp += '<script language="JavaScript1.2">\n';
  temp += 'function SetNavigatorImageStub() { if(m_flag) SetNavigatorImage(); else  setTimeout("SetNavigatorImageStub()",1000);}\n';

  if(!slide_show_mode) {
    temp += 'function MoveNavigatorStub() { if(m_flag) MoveNavigator();}\n';
    temp += 'function MoveNavigatorFrameStub() { if(m_flag) StartMoveNavigatorFrame();}\n';
  };
  temp += '</script>\n';

  temp += '</head>\n\n';
  temp += '<body onLoad="SetupZoomWindow();DisplayZoom();m_flag=1;" bgcolor="'+zoom_background_color+'" background="'+zoom_background_image+'">\n';

  temp += '  <div id="zoom-window" style="position:absolute;left:0px;top:0px;width:0px;height:0px;"';
  if (!slide_show_mode) temp += ' onMouseMove="MoveNavigatorStub();" onMouseUp="StopMoveNavigator();"';
  temp += '>\n    <a href="javascript:self.close();">\n';
  temp += '    <img id="actual-image" border=0 src="'+ image_files[actual_image_index] +'" alt="' +alternate_text[actual_image_index]+'"';
  temp += ' style="position:absolute;left:0px;top:0px;width:0px;height:0px;"'
  temp += ' onError="ZoomImageError();" onLoad="SetNavigatorImageStub();"';
  temp += '></a>\n';

  if(!slide_show_mode) temp += GenerateNavigatorText();
  temp += '</div>\n';
  temp += '</body>\n</html>\n';

  var settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=0,top=0,width='+windowWidth+',height='+windowHeight;
  ZoomWindow=window.open("",null,settings);
  ZoomWindow.document.write(temp);
  ZoomWindow.document.close();
};


function GenerateNavigatorText()
{
  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+='<style>\n';
  text+='.navCtrlWnd { color:blue; font-size:12px; font-weight:bold; font-family:Arial; position:absolute; height:18px; }\n';
  text+='</style>\n';
  text+='<form name="form">\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+='</form>\n';

  text+='  <input id="ZoomIn"   type=button value="+"  class=navCtrlWnd style="left:88px; top:95px; width:19px;" onClick="ZoomIn();"       onDblClick="ZoomIn();">\n';
  text+='  <input id="ZoomOut"  type=button value="-"  class=navCtrlWnd style="left:108px;top:95px; width:19px;" onClick="ZoomOut();"      onDblClick="ZoomOut();">\n';
  text+='  <input id="First"    type=button value="<<" class=navCtrlWnd style="left:0px;  top:116px;width:21px;" onClick="FirstZoom();"    onDblClick="FirstZoom();">\n';
  text+='  <input id="Previous" type=button value="<"  class=navCtrlWnd style="left:21px; top:116px;width:21px;" onClick="PreviousZoom();" onDblClick="PreviousZoom();">\n';
  text+='  <input id="Next"     type=button value=">"  class=navCtrlWnd style="left:42px; top:116px;width:21px;" onClick="NextZoom();"     onDblClick="NextZoom();">\n';
  text+='  <input id="Last"     type=button value=">>" class=navCtrlWnd style="left:63px; top:116px;width:21px;" onClick="LastZoom();"     onDblClick="LastZoom();">\n';
  text+='  <input id="ZoomNumber" value="" style="position:absolute;top:116px;left:84px;width:45px;height:18px;background-color:silver;color:black;font-size:10px;">\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 id="navigator-image" border=0 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();">\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 CalculateLayout()
function CalculateLayoutNS ()
{
  if ((generation_mode == 3) && !album_type) {
    var LAYER = document.layers[actual_image_id];//.layers[nzoom_id];

    actual_image_area_width  = LAYER.clip.right;
    actual_image_area_height = LAYER.clip.height;
  };

  number_of_pages = Math.ceil (total_slides/slides_per_page);

  //** Set album title.
  var temp='<font color="'+album_name_color+'" face="'+album_name_font+'" size='+album_name_size+'>'+album_name_type+album_name+album_name_type_end+'</font>';
  document.layers[album_title_id].document.write(temp);
  document.layers[album_title_id].document.close();
  if (album_name_shadow) {
    var temp='<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_shadow_id].document.write(temp);
    document.layers[album_title_shadow_id].document.close();
  };
};

/////////////////////////////////////////////////////////////////////////////
// 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 = ""; //** 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;
    };

    //** generate HTML for frames layer
    slides_per_page = slide_columns*slide_rows;
    frames_text += CreateFramesText (0, 0, slide_rows, slide_columns);

    //** now setup layer
    document.layers[photo_album_id].x = album_left_margin+4;
    document.layers[photo_album_id].y = album_top_margin+20;
    document.layers[photo_album_id].width = slide_columns*(slide_width+hor_space);
    document.layers[photo_album_id].height = slide_rows*(slide_height+ver_space);
    //document.layers[photo_album_id].bgColor = "yellow";
    document.layers[photo_album_id].zIndex = 1;
    document.layers[photo_album_id].document.write (frames_text);
    document.layers[photo_album_id].document.close();

    //** generate HTML for nzoom layer (actual image layer)
    var w = actual_image_area_width+actual_border_width*2;
    var h = actual_image_area_height+actual_border_width*2;
    if(!album_type) { //** auto_layout_type= 0, thumbnails+Actual image
      nzoom_text += '<table width='+w+' height='+h+'><tr><td width='+w+' height='+h+'>\n';
      nzoom_text += '<div id='+nzoom_id+' style="position:absolute;width:'+w+'px;height:'+h+'px;">';
      nzoom_text += '</div>\n';
      nzoom_text += '</td></tr></table>\n';
    };

    document.layers["main-menu"].zIndex = 2000;

    if (nzoom_text) {
      document.layers[actual_image_id].zIndex = 2;
      document.layers[actual_image_id].x = actual_image_area_left;
      document.layers[actual_image_id].y = actual_image_area_top+16;
      document.layers[actual_image_id].width  = w;
      document.layers[actual_image_id].height = h;
      document.layers[actual_image_id].clip.right = w;
      document.layers[actual_image_id].clip.bottom = h;
      document.layers[actual_image_id].document.write(nzoom_text);
      document.layers[actual_image_id].document.close();
    };
  }; //** AutoLayout

  number_of_pages = Math.ceil (total_slides/slides_per_page);
}; //** SetupLayout

function CreateFramesText (offset_x, offset_y, slide_rows, slide_columns)
{
  //** create HTML text of thumbnails layer
  var res = "";
  var i = 1;
  var width = slide_width+hor_space;
  var height = slide_height+ver_space;
  for(var row = 0; row < slide_rows; row++) {
    for(var col = 0; col < slide_columns; col++) {
      //** Positioning of the slides and texts on the screen.
      var xpos = offset_x + col*width;
      var ypos = offset_y + row*height;
      var pos = 'position:absolute;left:'+xpos+'px;top:'+ypos+'px;width:'+width+'px;height:'+height+'px;font-size:0px;';
      res += '<div id="image'+i+'" style="'+pos+'">' + GenerateImageLayer(i,(frame_image!="" || is_ns)) + '</div>\n'
      i++;
    }; //** columns
  }; //** rows
  return res;
};

function GenerateImageLayer (i,is_frame)
{
  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+'px;height:'+slide_height+'px';
  str += '<div id="'+slide_id+'" style="'+position+';top:0px;">&nbsp</div>\n';
  if(is_frame) str += '<div id="'+frame_id+'" style="'+position+';top:0px;">&nbsp</div>\n';
  if(slide_title) {
    if (is_ie4) str += '<div id="'+text_id+'" class="SlideCaption">&nbsp</div>\n';
    else str += '<div id="'+text_id+'"  style="'+position+';top:'+(slide_height+ver_text_space).toString()+'px;align:left;text-align:'+slide_title_align+';">&nbsp</div>\n';
  };
  return str;
};

/////////////////////////////////////////////////////////////////////////////
// function Display() -- Netscape
function DisplayNS ()
{
  var item_name, text_item_name;
  var temp_string,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;';
    };

    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="";

    var image_id = 'image'+i.toString();
    LAYER = document.layers[photo_album_id].layers[image_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';
      if (slide_link) 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';
      if (slide_link) 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) {
      if (slide_link) 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';
      if (slide_link) temp_string += '</a>\n';
    };

    frames_temp_string = "";
    if (frame_image!="" && auto_layout && slide_index>0) {
      if (slide_link) frames_temp_string+='<a href="javascript:Link('+i+');">';
      frames_temp_string+='<img src="'+cur_frame_image+'" alt="'+description_text+'" border=0>'
      if (slide_link) frames_temp_string+='</a>';
    } else if (slide_border_width>0 && slide_index>0) {
      frames_temp_string
    };

    var 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) {
      var 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>';
      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;
  };

  var nzoom_text = "";
  nzoom_text += '<table width='+actual_image_area_width+' height='+actual_image_area_height+'>\n';
  nzoom_text += '<tr><td width='+actual_image_area_width+' height='+actual_image_area_height+'';
  if (zoom_background_color) nzoom_text += ' bgcolor="'+zoom_background_color+'"';
  if (zoom_background_image) nzoom_text += ' background="'+zoom_background_image+'"';
  nzoom_text += '>\n';
  //** !!!
  nzoom_text += '<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) nzoom_text += 'border:'+actual_border_width+'px '+actual_border_style+' '+actual_border_color+';';
  nzoom_text += '">\n';
  nzoom_text += '<a href="javascript:ZoomLink('+actual_image_index+');">\n';
  nzoom_text += '<img src="'+image_files[actual_image_index]+'" border=0 width='+(imageWidth-13).toString()+' height='+(imageHeight-7).toString()+'>\n</a>\n';
  //** !!!
  nzoom_text += '</div>\n&nbsp</td></tr></table>\n';

  LAYER = document.layers[actual_image_id].layers[nzoom_id];
  LAYER.document.open();
  LAYER.document.write(nzoom_text);
  LAYER.document.close();
};

/////////////////////////////////////////////////////////////////////////////
// function DisplayZoomInWindow(slide_show_mode, actual_image_index)
function DisplayZoomInWindowNS (slide_show_mode, actual_image_index)
{
  var temp = "";  //** HTML source of the Zoom Window.
  var navigator_image_file;
  var windowWidth, windowHeight;

  if (window.screen) {
    windowWidth = screen.availWidth-8;
    windowHeight =  screen.availHeight-27;
  } else {
    windowWidth = 800;
    windowHeight = 600;
  };

  temp += '<html>\n<head>\n';
  temp += '<title>' + text[actual_image_index] + '</title>\n';
  temp += '</head>\n\n';
  temp += '<body bgcolor="'+zoom_background_color+'" background="'+zoom_background_image+'"';
  temp += '>\n';

  var width  = BOUND (image_dimensions[actual_image_index*2], 0, windowWidth);
  var height = BOUND (image_dimensions[actual_image_index*2+1], 0, windowHeight);
  var left = Math.floor(windowWidth/2 - width/2);
  if (left < 0) left = 0;
  var top  = Math.floor(windowHeight/2 - height/2);
  if (top < 0) top = 0;

  //temp += GenerateNavigatorText();

  temp += '<table width='+windowWidth+' height='+windowHeight+' border=0><tr><td width='+windowWidth+' height='+windowHeight+' border=0>\n';
  temp += '  <div id="zoom-window" style="position:absolute;left:'+left+'px;top:'+top+'px;width:'+width+'px;height:'+height+'px;">\n'
  temp += '    <a href="javascript:self.close();">\n';
  temp += '      <img id="actual-image" border=0 src="'+image_files[actual_image_index]+'" alt="'+alternate_text[actual_image_index]+'" width='+width+' height='+height+'>\n';
  temp += '    </a>\n';
  temp += '  </div>\n';
  temp += '</td></tr></table>\n';
  temp += '</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+',height='+windowHeight;
  ZoomWindow=window.open("",null,settings);
  ZoomWindow.document.write(temp);
  ZoomWindow.document.close();
};

