// Copyright 2010 - Mark Rasmussen - Rare Collections - 612-961-4747 - mark@rare-collections.com - www.rare-collections.com

var FontMin  = 12;  var FontMax  = 22;
var ThumbMin = 54;  var ThumbMax = 1920;
var ZoomMin  = 200; var ZoomMax  = 1920;
var SlideMin = 200; var SlideMax = 1920;

var SiteTitle; var Here; var Menu; var Link; var MaxThumbs; var MaxWidth; var Force; var Columns; var AlignTop; var AlignBottom; var Quality; var ItemTitle; var ItemNumber; var ItemStatus; var InquirePrefix; var Inquire; var InquireTip; var SlideShow; var Printer;

var IE = 0; var Initialized = false;
var PageDIV; var PageHTML = "";
var HideDIV; var TopHTML = ""; var BottomHTML = "";
var TipDIV; var TipOn=false; var TitleDIV; var TitleOn=false;
var ZoomDIV; var ZoomIMG_Obj; var Zoom1_Obj; var Zoom2_Obj; var ZoomOpen = 0; var ZoomTop  = 0; var ZoomLeft = 0; var ZoomOf = 0; var ZoomWidth; var ZoomHeight; var ZoomQuality;
var InqDIV; var InqOpen = 0;
var DetailDIV; var SlideDIV; var AdminDIV; var AdminOpen = 0; var AdminMode = 0; var Save_Func = ""; var Save_Gallery = "";
var MouseX = 0; var MouseY = 0;
var FakeCookie = "";
var AutoTimer = 0; var PollTimer = 0;
var Resizing = 0; var CurrentX = 0; var CurrentViewPortWidth = 0; var CurrentViewPortHeight = 0;
var SaveViewPortWidth = -1;
var Slides_Obj; var SlideShowControls_Obj; var SlideShowStatus_Obj;
var BarAdjust = 42; var WidthAdjust = 0; var HalfX = 0; var HalfY = 0;  // Was 22
var FontSize = "12px"; var ContentWidth = 1024; var ContentHeight = 768; var ViewPortWidth = 1024; var ViewPortHeight = 768;
var NoMouse = 0; var BigButtons = 0; var Printer_FontFamily = "arial"; var Printer_FontSize = "12px";
var Suffix = new Array('','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
var SlideList = new Array(); var SlideList_Item = new Array(); var SlideShowOpen = false; var PauseSlideShow = false;
var Slides = 0; var SlideWidth; var SlideHeight; var SlideTimer = 0; var LoadTimer = 0; var Slide = 0; var LoadSlide = 0;
var SlidesBuffer = new Array(); var SlideRequested = new Array(); var SaveBackground; var SaveOverFlow;
var Email_RE = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|tel|gov|arpa|biz|store|travel|web|aero|name|coop|nato|nom|pro|jobs|info|firm|pro|museum))$/;
var Phone_RE = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;

function Init() {
   if (typeof(Gallery) == 'undefined' || Gallery == '') {window.location = "./home.shtml"; return;}
   if (document.location.href.indexOf("&index=") > -1) {location.replace('gallery.shtml?' + Gallery + window.location.hash); return;}
   var i = 0; var i2 = 0; var args; var arg; var hashitem = -1; var tip = ""; var cookies; var cookie; var sold;
   args = document.location.href + "#?#"; args = args.substr(args.indexOf("?")); args = args.substr(1,args.indexOf("#"));
   if (args.indexOf("&admin") > 0) {
      if (User != '') {AdminMode=1; document.cookie="sold=";}
      else {window.location="./home.shtml"; return;}
   }
   cookies = document.cookie + "~sold=~"; cookie = cookies.substr(cookies.indexOf("sold=")+5); sold = cookie.substr(0, cookie.indexOf("~"));
   var hash = window.location.hash.substr(1) + ","; var word = hash.split(","); if (word[1] != "") {window.location.hash = "all";}
   if (sold != "") {for (i=0; i<I1.length; i++) {if (sold.indexOf(","+I4[i]+",") >= 0) {I5[i] = 23;}}}
   if (word[1] == "paypal") {
      for (i=0; i<I1.length; i++) {
          if (word[0] == I4[i]) {
             I5[i] = 24;
             if (sold.indexOf(","+I4[i]+",") == -1) {
                var date = new Date(); date.setTime(date.getTime()+8640000); var expires = "~; expires=" + date.toGMTString() + "; path=/"; sold = sold + "," + I4[i] + ",";
                document.cookie = "sold=" + sold + expires; alert("Thank you for your purchase!");
             }
             break;
          }
      }
   } else if (/#[0-9]+-[0-9]+/.test(window.location.hash)) {for (i=0; i<I1.length; i++) {if (word[0] == I4[i]) {hashitem = i; break;} if (hashitem == -1) {window.location.hash = "all";}}
   } else if (AdminMode || window.location.hash == "#slides") {
   } else window.location.hash = "all";
   Poll(1);
   PageDIV   = document.getElementById('PageDIV');   PageDIV.style.top='0px';   PageDIV.style.left='0px'; PageDIV.innerHTML="";
   TipDIV    = document.getElementById('TipDIV');    TipDIV.style.top='0px';    TipDIV.style.left='0px';
   TitleDIV  = document.getElementById('TitleDIV');  TitleDIV.style.top='0px';  TitleDIV.style.left='0px';
   ZoomDIV   = document.getElementById('ZoomDIV');   ZoomDIV.style.top='0px';   ZoomDIV.style.left='0px';
   SlideDIV  = document.getElementById('SlideDIV');  SlideDIV.style.top='0px';  SlideDIV.style.left='0px';
   DetailDIV = document.getElementById('DetailDIV'); DetailDIV.style.top='0px'; DetailDIV.style.left='0px';
   InqDIV    = document.getElementById('InqDIV');    InqDIV.style.top='0px';    InqDIV.style.left='0px';
   AdminDIV  = document.getElementById('AdminDIV');  AdminDIV.style.top='0px';  AdminDIV.style.left='0px';
   HideDIV   = document.getElementById('HideDIV');   HideDIV.style.top='0px';   HideDIV.style.left='0px';
   args = HideDIV.innerHTML.substr(0,HideDIV.innerHTML.indexOf("-->")) + ";sitetitle=;here=;menu=;link=;maxthumbs=;maxwidth=;thumbmin=;thumbmax=;force=;columns=;aligntop=;alignbottom=;quality=;itemtitle=;itemnumber=;itemstatus=;inquireprefix=;inquire=;inquiretip=;slideshow=;printer=;-->";
   arg=args.substr(args.indexOf("sitetitle=")+10);     SiteTitle     = arg.substr(0,arg.indexOf(";")); if (SiteTitle == '') SiteTitle=document.title; else document.title=SiteTitle;
   arg=args.substr(args.indexOf("here=")+5);           Here          = arg.substr(0,arg.indexOf(";")); if (Here != '') document.title=document.title + " - " + Here;
   arg=args.substr(args.indexOf("menu=")+5);           Menu          = arg.substr(0,arg.indexOf(";"));
   arg=args.substr(args.indexOf("link=")+5);           Link          = arg.substr(0,arg.indexOf(";"));
   arg=args.substr(args.indexOf("maxthumbs=")+10);     MaxThumbs     = parseInt("0"+arg.substr(0,arg.indexOf(";")),10); if (MaxThumbs == 0 || AdminMode) MaxThumbs=999999;
   arg=args.substr(args.indexOf("maxwidth=")+9);       MaxWidth      = parseInt("0"+arg.substr(0,arg.indexOf(";")),10); if (MaxWidth == 0) MaxWidth=screen.width;
   arg=args.substr(args.indexOf("thumbmin=")+9);       ThumbMin      = parseInt("0"+arg.substr(0,arg.indexOf(";")),10); if (ThumbMin == 0 || AdminMode) ThumbMin = 54;
   arg=args.substr(args.indexOf("thumbmax=")+9);       ThumbMax      = parseInt("0"+arg.substr(0,arg.indexOf(";")),10); if (ThumbMax == 0) ThumbMax = 1920;
   arg=args.substr(args.indexOf("force=")+6);          Force         = arg.substr(0,arg.indexOf(";"));
   arg=args.substr(args.indexOf("columns=")+8);        Columns       = parseInt("0"+arg.substr(0,arg.indexOf(";")),10); if (Columns == 0) Columns=5;
   arg=args.substr(args.indexOf("aligntop=")+9);       AlignTop      = arg.substr(0,arg.indexOf(";")); if (AlignTop == '') AlignTop='center';
   arg=args.substr(args.indexOf("alignbottom=")+12);   AlignBottom   = arg.substr(0,arg.indexOf(";")); if (AlignBottom == '') AlignBottom='center';
   arg=args.substr(args.indexOf("quality=")+8);        Quality       = parseInt("0"+arg.substr(0,arg.indexOf(";")),10); if (Quality == 0) Quality=75;
   arg=args.substr(args.indexOf("itemtitle=")+10);     ItemTitle     = parseInt("0"+arg.substr(0,arg.indexOf(";")),10);
   arg=args.substr(args.indexOf("itemnumber=")+11);    ItemNumber    = parseInt("0"+arg.substr(0,arg.indexOf(";")),10);
   arg=args.substr(args.indexOf("itemstatus=")+11);    ItemStatus    = parseInt("0"+arg.substr(0,arg.indexOf(";")),10);
   arg=args.substr(args.indexOf("inquireprefix=")+14); InquirePrefix = arg.substr(0,arg.indexOf(";"));
   arg=args.substr(args.indexOf("inquire=")+8);        Inquire       = arg.substr(0,arg.indexOf(";"));
   arg=args.substr(args.indexOf("inquiretip=")+11);    InquireTip    = arg.substr(0,arg.indexOf(";"));
   arg=args.substr(args.indexOf("slideshow=")+10);     SlideShow     = parseInt("0"+arg.substr(0,arg.indexOf(";")),10);
   arg=args.substr(args.indexOf("printer=")+8);        Printer       = parseInt("0"+arg.substr(0,arg.indexOf(";")),10);
   getStyles();
   if (navigator.platform == "iPhone" || navigator.platform == "iPad" || navigator.platform == "iPod") {NoMouse = 1;}  // Needed as iStuff can not deal with certain mouse events...
   if (navigator.appName == 'Microsoft Internet Explorer') {IE = 1; BarAdjust = BarAdjust - 19;}  // was 19
   var cookiename;
   if (AdminMode) {
      cookiename = "cols_admin" + Gallery + "=";
      cookies = document.cookie + "~" + cookiename + "~"; cookie = cookies.substr(cookies.indexOf(cookiename)+cookiename.length); cookie = cookie.substr(0, cookie.indexOf("~")); if (cookie && cookie != "~") Columns=cookie;
      for (i=0;i<I1.length;i++) {I10u[i]="<b>"+I4[i]+"</b>. "+unescape(I10[i]); if (I8[i] != '0' || I8s[i] != '0') I10u[i] += " <b>$"+I8[i]+", $"+I8s[i]+"</b>";}
   } else {
      cookiename = "cols_normal" + Gallery + "=";
      cookies = document.cookie + "~" + cookiename + "~"; cookie = cookies.substr(cookies.indexOf(cookiename)+cookiename.length); cookie = cookie.substr(0, cookie.indexOf("~")); if (cookie && cookie != "~") Columns=cookie;
      for (i=0;i<I1.length;i++) {
         if (ItemNumber) I10u[i]="<b>"+I4[i]+"</b>. "+unescape(I10[i]);
         else if (I10[i]) I10u[i]="<b>"+unescape(I10[i])+"</b>"; else I10u[i] = '';
      }
   }
   if (Force_MaxThumbs && !AdminMode) MaxThumbs = Force_MaxThumbs;
   if (HideDIV.innerHTML.indexOf("<top>") > -1 && HideDIV.innerHTML.indexOf("</top>") > -1) {
      TopHTML = HideDIV.innerHTML.substr(HideDIV.innerHTML.indexOf("<top>")+5); TopHTML = TopHTML.substr(0,TopHTML.indexOf("</top>"));
   }
   if (HideDIV.innerHTML.indexOf("<bottom>") > -1 && HideDIV.innerHTML.indexOf("</bottom>") > -1) {
      BottomHTML = HideDIV.innerHTML.substr(HideDIV.innerHTML.indexOf("<bottom>")+8); BottomHTML = BottomHTML.substr(0,BottomHTML.indexOf("</bottom>"));
   }
   TopHTML = TopHTML.replace(/ZZSITE/g, Site); TopHTML = TopHTML.replace(/ZZMENU/g, Here); TopHTML = TopHTML.replace(/ZZSUB/g, Sub);
   BottomHTML = BottomHTML.replace(/ZZSITE/g, Site); BottomHTML = BottomHTML.replace(/ZZMENU/g, Here); BottomHTML = BottomHTML.replace(/ZZSUB/g, Sub);
   if (typeof(window.innerWidth) != 'undefined') {
      ContentWidth  = "Math.min(window.innerWidth,document.documentElement.clientWidth,MaxWidth)"; ViewPortWidth = "Math.min(window.innerWidth,document.documentElement.clientWidth)";
      ContentHeight = "Math.min(window.innerHeight,document.documentElement.clientHeight)"; ViewPortHeight = "Math.min(window.innerHeight,document.documentElement.clientHeight)";
   } else if (typeof(document.documentElement.clientWidth) != 'undefined') {
      ContentWidth  = "Math.min(document.documentElement.clientWidth,MaxWidth)"; ViewPortWidth = "Math.min(document.documentElement.clientWidth)";
      ContentHeight = "document.documentElement.clientHeight"; ViewPortHeight = "document.documentElement.clientHeight";
   } else {
      ContentWidth  = "Math.min(document.getElementsByTagName('body')[0].clientWidth,MaxWidth)"; ViewPortWidth = "Math.min(document.getElementsByTagName('body')[0].clientWidth)";
      ContentHeight = "document.getElementsByTagName('body')[0].clientHeight"; ViewPortHeight = "document.getElementsByTagName('body')[0].clientHeight";
   }
   HalfX = Math.floor(eval(ViewPortWidth)/2); HalfY = Math.floor(eval(ViewPortHeight)/2);
   PageHTML = "<table border='0' cellpadding='1' cellspacing='0' class='menu' style='width:ZZRWpx;font-size:ZZFSpx'>";
   PageHTML += "<tr><td align='left'><a href='home.shtml'>Home</a></td><td align='right'>";
   if (AdminMode) {
      PageHTML += "<a href='help.shtml' target='_blank'>Help</a>&nbsp;&nbsp;";
      if (Admin && I1.length == 0) {PageHTML += "<a href='javascript:PostAdmin(\"&scope=load\",99" + ")'>Load</a>&nbsp;&nbsp;";}
   }
   else if (SlideShow) PageHTML += "<a href='javascript:OpenSlideShow()'>Slideshow</a>&nbsp;&nbsp;";
   if (Menu != '') {
      var work_menu = Menu.split(",");
      var work_link = Link.split(",");
      for (var m=0; m<work_menu.length&&work_link.length; m++) {
          PageHTML += "<a href='" + work_link[m] + "'>" + work_menu[m] + "</a>&nbsp;&nbsp;";
      }
   }
   PageHTML += "<a href='news.shtml'>News</a>&nbsp;&nbsp;<a href='about.shtml'>About</a>&nbsp;&nbsp;<a href='contact.shtml'>Contact</a></td></tr></table>";
   if (AdminMode) {
      TopHTML = TopHTML.replace(/ZZADMIN/g, "&admin");
      BottomHTML = BottomHTML.replace(/ZZADMIN/g, "&admin");
      PageHTML = PageHTML.replace(/ZZADMIN/g, "&admin");
   } else {
      TopHTML = TopHTML.replace(/ZZADMIN/g, "");
      BottomHTML = BottomHTML.replace(/ZZADMIN/g, "");
      PageHTML = PageHTML.replace(/ZZADMIN/g, "");
   }
   if (TopHTML != '') {
      PageHTML += "<div style='width:100%'><div align='center'>";
      PageHTML += "<div align='" + AlignTop + "' class='top' style='width:ZZRWpx'>" + TopHTML + "</div></div></div>";
   }
   i = 0; i2 = 1;
   var stats = "background-repeat:no-repeat;background-image:url(\"/utils/zzhit01.cgi?&site=" + Site + "&sub=" + Sub + "&stats=g&key=" + Gallery + "&image=hit.gif\")";
   var ieadjust = 0; if (IE && MaxWidth >= screen.width) ieadjust = 21;  // was 21
   var thumbwidth = Math.floor((Math.min(screen.width,MaxWidth)-(Columns*WidthAdjust)-BarAdjust-ieadjust)/Columns);
   if (thumbwidth < ThumbMin) thumbwidth = ThumbMin;
   if (thumbwidth > ThumbMax) thumbwidth = ThumbMax;
   var force = ""; if (Force) {force = "_" + Force; thumbheight = thumbwidth;} else thumbheight = 0;
   PageHTML += "<div class='thumbs' style='width:ZZRWpx;font-size:ZZFSpx'>";
   for (i=0; i<I1.length; i++) {
       if (I5[i] < HideBegin || AdminMode) {
          PageHTML += "<div style='position:relative;float:left;" + stats + "' ";
          if (ItemTitle && I10u[i]) {
             if (!NoMouse) {PageHTML += " onmousemove='ShowTitle(" + i + ")' onmouseout='HideTitle()'";}
             else {PageHTML += " title='" + unescape(I10[i]) + "'";}
          }
          var cache = "./cache/" + I2[i] + "_" + I3[i] + "a_" + thumbwidth + "_" + thumbheight + "_" + Quality + force + ".jpg";
          if (I17[i].substr(0,1) == '!' && !AdminMode) {
             PageHTML += "><a href='" + I17[i].substr(1) + "'><img src='" + cache + "?" + MTime + "&w=" + thumbwidth + "&h=" + thumbheight + "&q=" + Quality + "&f=" + Force + "&c=" + I2[i] + "_" + I3[i] + "a&s=" + I1[i] + "a.jpg' width='ZZTW' class='thumb'>";
             PageHTML += "<div class='thumblnk' style='width:ZZTWpx;font-size:ZZTTpx'>" + unescape(I11[i]) + "</div></a>";
          } else {
             PageHTML += "><img src='" + cache + "?" + MTime + "&w=" + thumbwidth + "&h=" + thumbheight + "&q=" + Quality + "&f=" + Force + "&c=" + I2[i] + "_" + I3[i] + "a&s=" + I1[i] + "a.jpg' width='ZZTW' class='thumb' onclick='OpenZoom(" + i + ")'>";
             if ((S1[I5[i]] && ItemStatus) || AdminMode) {
                if (AdminMode) tip = S6[I5[i]]; else tip = S4[I5[i]];
                PageHTML += "<div class='thumbtxt' onclick='OpenZoom(" + i + ")' ";
                PageHTML += " title='" + tip + "'>" + S3[I5[i]] + "</div>";
             }
          }
          PageHTML += "</div>";
          SlideList[i2] = "./cache/" + I2[i] + "_" + I3[i] + "a_ZZSW_ZZSH_" + Quality + ".jpg" + "?" + MTime + "&w=ZZSW&h=ZZSH&q=" + Quality + "&c=" + I2[i] + "_" + I3[i] + "a&s=" + I1[i] + "a.jpg";
          SlideList_Item[i2] = i;
          if (i2 >= MaxThumbs) break;
          i2++; stats = '';
       }
   }
   PageHTML += "</div>";
   if (BottomHTML != '') {
      PageHTML += "<div style='width:100%;float:right'><div align='center'>";
      PageHTML += "<div align='" + AlignBottom + "' class='bottom' style='width:ZZRWpx'>" + BottomHTML + "</div></div></div>";
   }
   if (!NoMouse) {AutoHide();if (window.addEventListener) {document.addEventListener("mousemove",GetMouseXY,false);} else if (window.attachEvent) {document.attachEvent("onmousemove",GetMouseXY);}}
   ResizePage(); window.onresize = function(){ResizePage();}
   SaveBackground = document.getElementsByTagName('body')[0].style.backgroundColor; SaveOverFlow = document.getElementsByTagName('html')[0].style.overflow;
   if (Polling && Polling < 30000) {Polling = 30000;} if (Polling && !AdminMode) {PollTimer = setTimeout("Poll()",Polling);}
   Initialized = true;
   if (window.location.hash == "#slides") OpenSlideShow(); else if (hashitem >= 0) OpenZoom(hashitem);
}

function getStyles() { 
    var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
    for (var x=0;x<classes.length;x++) {
        var selector = classes[x].selectorText;
        if (selector.toLowerCase().indexOf("body") > -1) {
           var work = classes[x].cssText || classes[x].style.cssText;
           var temp = classes[x].style.fontFamily + ",";
           temp = temp.substr(0,temp.indexOf(","));
           if (temp != '') Printer_FontFamily = temp;
           var temp = classes[x].style.fontSize;
           if (temp != '') Printer_FontSize = temp;
        }
        if (selector.toLowerCase() == ".thumb") {
           var work = classes[x].cssText || classes[x].style.cssText;
           WidthAdjust = (parseInt("0"+classes[x].style.borderWidth,10) * 2) + (parseInt("0"+classes[x].style.margin,10) * 2);
        } 
    } 
}

function GetMouseXY(e) {
   if (IE) {
      MouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; MouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
   } else {
      MouseX = e.pageX; MouseY = e.pageY;
   }
}

function AutoHide() {
   if (TipOn){TipOn=false;TipDIV.style.visibility='hidden';TipDIV.style.top='0px';TipDIV.style.left='0px';}
   if (TitleOn){TitleOn=false;TitleDIV.style.visibility='hidden';TitleDIV.style.top='0px';TitleDIV.style.left='0px';}
   AutoTimer=setTimeout('AutoHide()',2000);
}

function ResizePage() {
   CurrentViewPortWidth = eval(ViewPortWidth);
   CurrentViewPortHeight = eval(ViewPortHeight);
   if (Resizing) return;
   Resizing=1;
   document.body.style.overflow = "hidden";
   if (SaveViewPortWidth == eval(ViewPortWidth)) {
      document.body.style.overflow = "visible";
      Resizing=0;
      return;
   }
   cols = Columns;
   CurrentX=eval(ContentWidth);
   var thumbwidth=Math.floor((CurrentX-(Columns*WidthAdjust)-BarAdjust)/Columns);
   if (thumbwidth < ThumbMin) {thumbwidth=ThumbMin;cols=Math.floor((CurrentX-BarAdjust)/(thumbwidth+WidthAdjust));
   if (cols < 1) cols=1;}
   thumbwidth=Math.floor((CurrentX-(cols*WidthAdjust)-BarAdjust)/cols);
   if (thumbwidth < ThumbMin) thumbwidth=ThumbMin;
   if (thumbwidth > ThumbMax) thumbwidth=ThumbMax;
   FontSize=Math.floor(CurrentX*.0275);
   if (FontSize < FontMin) {FontSize=FontMin;} else if (FontSize > FontMax) {FontSize=FontMax;}
   var html=PageHTML.replace(/ZZFS/g,FontSize);
   FontSize=Math.floor(thumbwidth*.22);if (FontSize < 12) {FontSize=12;} else if (FontSize > 16) {FontSize=16;}
   html=html.replace(/ZZTT/g,FontSize);
   var resizewidth = (thumbwidth*cols)+(WidthAdjust*cols);
   var resizehalf = Math.floor(resizewidth/2);
   html=html.replace(/ZZRW/g,resizewidth);
   html=html.replace(/ZZ50RW/g,resizehalf);
   PageDIV.style.width=(thumbwidth*cols)+(WidthAdjust*cols)+'px';
   PageDIV.innerHTML=html.replace(/ZZTW/g,thumbwidth);
   HalfX=Math.floor(eval(ViewPortWidth)/2);
   HalfY=Math.floor(eval(ViewPortHeight)/2);
   SaveViewPortWidth = eval(ViewPortWidth);
   document.body.style.overflow = "visible";   
   Resizing=0;
}

function getViewportWidth() {
   if (window.innerWidth) {
      return window.innerWidth;
    } else if (document.body && document.body.offsetWidth) {
      return document.body.offsetWidth;
    } else {
      return 0;
    }
}

function ShowTip(text) {
   TipDIV.innerHTML=text;
   if (MouseX > HalfX){TipDIV.style.left=MouseX-TipDIV.clientWidth-5+'px';} else TipDIV.style.left=MouseX+'px';
   if (MouseY > HalfY){TipDIV.style.top=MouseY-40+'px';} else TipDIV.style.top=MouseY+24+'px';
   TipDIV.style.visibility='visible';
   TipOn=true;
}

function HideTip() {
   TipDIV.style.visibility='hidden';
   TipOn=false;
   TipDIV.style.top='0px';
   TipDIV.style.left='0px';
}

function ShowTitle(i) {
   if (MouseX > HalfX){TitleDIV.style.left=MouseX-TitleDIV.clientWidth-5+'px';} else TitleDIV.style.left=MouseX+'px';
   if (MouseY > HalfY){TitleDIV.style.top=MouseY-40+'px';} else TitleDIV.style.top=MouseY+24+'px';
   TitleDIV.innerHTML=I10u[i];
   TitleDIV.style.visibility='visible';
   TitleOn=true;
}

function HideTitle() {
   TitleDIV.style.visibility='hidden';
   TitleOn=false;
   TitleDIV.style.top='0px';
   TitleDIV.style.left='0px';
}

function OpenPref() {
   AdminOpen = 1;
   var html = "<div align='center' style='width:307px;border:2px solid red'>";
   html = html + "<div align='left' class='admintxt' style='padding:4px'>";
   html = html + "<b>Display Preferences for Gallery " + parseInt(Gallery,10) + "</b>";
   html = html + "<br><br><b>Columns (4-30):</b>";
   html = html + "<br><input type='text' id='cols_normal' class='input' style='width:61px;'>";
   if (AdminMode) {
      html = html + "<br><br><b>Administrative Columns (4-30):</b>";
      html = html + "<br><input type='text' id='cols_admin' class='input' style='width:61px;'>";
   }
   html += "<br><br><div align='center' style='padding:4px;'>";
   html += "<span class='inqbtn' onclick='PostPref(0)' title='Click to Update'>Update</span>&nbsp;&nbsp;&nbsp;&nbsp;";
   html += "<span class='inqbtn' onclick='PostPref(1)' title='Click to Default'>Default</span>&nbsp;&nbsp;&nbsp;&nbsp;";
   html += "<span class='inqbtn' style='color:red' onclick='ClosePref()' title='Click to Cancel'>Cancel</span></div>";
   html = html + "</div><div style='position:absolute;width:100%;top:6px;left:0px'>";
   html = html + "<div align='center' style='width:307px'>";
   html = html + "<div style='float:right;padding:4px;'><span class='closebtn' onclick='ClosePref()'>&nbsp;X&nbsp;</span></div></div></div>";
   AdminDIV.innerHTML = html + "</div>";
   var cookies; var cookie;
   var obj = document.getElementById("cols_normal");
   var cookiename = "cols_normal" + Gallery + "=";
   if (obj) {
      cookies = document.cookie + "~" + cookiename + "~"; cookie = cookies.substr(cookies.indexOf(cookiename)+cookiename.length); cookie = cookie.substr(0, cookie.indexOf("~")); if (!cookie) cookie=Columns;
      obj.value = cookie;
   }
   var obj = document.getElementById("cols_admin");
   cookiename = "cols_admin" + Gallery + "=";
   if (obj) {
      cookies = document.cookie + "~" + cookiename + "~"; cookie = cookies.substr(cookies.indexOf(cookiename)+cookiename.length); cookie = cookie.substr(0, cookie.indexOf("~")); if (!cookie) cookie=Columns;
      obj.value = cookie;
   }
   var divtop = document.body.scrollTop + document.documentElement.scrollTop;
   if (divtop < 0) {divtop = 0;}
   AdminDIV.style.top  = divtop  + 'px';
   AdminDIV.style.visibility = 'visible';
   var obj = document.getElementById("cols_normal");
   setTimeout(function(){obj.focus();obj.select();},1);
   obj.focus();
}

function PostPref(opt) {
   if (opt) {document.cookie = "cols_normal" + Gallery + "=~"; document.cookie = "cols_admin" + Gallery + "=~"; ClosePref(); window.location.reload();}
   var date = new Date();
   date.setTime(date.getTime()+31622400000);
   var expires = "~; expires=" + date.toGMTString() + "; path=/";
   var obj = document.getElementById("cols_normal");
   if (!/[0-9]+/.test(obj.value) || obj.value == "" || obj.value == null || obj.value < 4 || obj.value > 30) {
      setTimeout(function(){obj.focus();obj.select();},1);
      obj.focus();
      obj.select();
      alert("Please provide a valid number (4-30).");
      return;
   }
   document.cookie = "cols_normal" + Gallery + "=" + obj.value + expires;
   if (document.getElementById("cols_admin")) {
      var obj = document.getElementById("cols_admin");
      if (!/[0-9]+/.test(obj.value) || obj.value == "" || obj.value == null || obj.value < 4 || obj.value > 30) {
         setTimeout(function(){obj.focus();obj.select();},1);
         obj.focus();
         obj.select();
         alert("Please provide a valid number (4-30).");
         return;
      }
      document.cookie = "cols_admin" + Gallery + "=" + obj.value + expires;
   }
   ClosePref();
   window.location.reload();
}

function ClosePref() {
   AdminDIV.style.visibility = 'hidden';
   AdminDIV.innerHTML = "";
   AdminDIV.style.top  = "0px";
   AdminDIV.style.left = "0px";
   AdminOpen = 0;
}

function OpenZoom(i) {
   if (AdminMode) {OpenAdmin(i); return;}
   if (ZoomOpen || I5[i] >= HideBegin || I12[i] == ";" || I12[i] == "") {return;}
   ZoomOpen = 1; ZoomOf = 1; window.location.hash = I4[i];
   HideTitle(); HideTip();
   CurrentViewPortWidth = eval(ViewPortWidth);
   CurrentViewPortHeight = eval(ViewPortHeight);
   ZoomWidth = CurrentViewPortWidth - 4;
   if (ZoomWidth < ZoomMin) {ZoomWidth = ZoomMin;} else if (ZoomWidth > ZoomMax) {ZoomWidth = ZoomMax;}
   ZoomHeight = CurrentViewPortHeight - 4;
   var firstwidth = ZoomWidth;
   var firstheight = ZoomHeight;
   var size = I12[i].split(";");
   var imgwidth  = parseInt(size[0],10);
   var imgheight = parseInt(size[1],10);
   var aspect = imgwidth / imgheight;
   var w1 = Math.min(ZoomWidth, imgwidth);   var h1 = w1 / aspect;
   var h2 = Math.min(ZoomHeight, imgheight); var w2 = h2 * aspect;
   if (w1 > firstwidth || h1 > firstheight) {firstwidth = Math.floor(w2); firstheight = Math.floor(h2);} else {firstwidth = Math.floor(w1); firstheight = Math.floor(h1);}
   ZoomQuality = Quality;
   var stats = "background-repeat:no-repeat;background-image:url(\"/utils/zzhit01.cgi?&site=" + Site + "&sub=" + Sub + "&stats=z&key=" + Gallery + "~" + I2[i] + "~" + I3[i] + "~" + I7[i] + "~&image=hit.gif\")";
   var inqbtn = '';
   if (I10u[i] || InquirePrefix) {
      if (Inquire != '' && I17[i] != '') {
         inqbtn = "<div class='zoombtn'><a href='" + Inquire + "' title='" + InquireTip + "' target='_blank'>" + InquirePrefix + I10u[i] + "</a></div>";
         inqbtn = inqbtn.replace(/ZZKEY/g,I17[i]); inqbtn = inqbtn.replace(/ZZHOST/g,Host); inqbtn = inqbtn.replace(/ZZSUB/g,Sub); inqbtn = inqbtn.replace(/ZZITEM/g,I4[i]);
      } else {
         var inqtip = S5[I5[i]]; if (I9[i] && S2[I5[i]] && I8[i] != '0') {inqtip = inqtip + " or BuyNow";}
         inqbtn = "<div class='zoombtn'><a href='javascript:OpenInquire(" + i + ")' title='" + inqtip + "'>" + InquirePrefix + I10u[i] + "</a></div>";
      }
   }
   var inqdtl = '';
   if (I11[i] != '' || I14[i] != '') {
      inqdtl = "<span class='zoombtn'><a href='javascript:OpenDetail(" + i + ")' title='Show Details'>Details</a></span>";
   }
   var inqof = '';
   if (I6[i] > 1) {
      inqof = "<span class='zoombtn'><a href='javascript:ZoomNext(" + i + ")' title='Next Photo'><span id='of'>1 of " + I6[i] + "</span></a></span>&nbsp;&nbsp;&nbsp;&nbsp;";
   }
   var html = "<div style='overflow:hidden'>";
   html += "<img id='zoomimg' src='./cache/"+I2[i]+"_"+I3[i]+Suffix[ZoomOf]+"_ZZZW_ZZZH_"+Quality+".jpg?"+MTime+"&w=ZZZW&h=ZZZH&q="+Quality+"&c="+I2[i]+"_"+I3[i]+Suffix[ZoomOf]+"&s="+I1[i]+Suffix[ZoomOf]+".jpg' class='zoomimg' style='" + stats + "'>";
   html += "<div style='position:absolute;width:100%;top:2px;left:0px'>";
   html += "<div id='zoom1' align='center' style='width:" + firstwidth + "px'>";
   html += "<div style='float:left;padding:4px;'>" + inqbtn + "</div><div style='float:right;padding:4px;'><div class='closebtn' onclick='CloseZoom()'>&nbsp;X&nbsp;</div></div></div></div>";
   html += "<div style='position:absolute;width:100%;top:41px;left:0px'>";
   html += "<div id='zoom2' align='center' style='width:" + firstwidth + "px'>";
   html += "<div style='float:left;padding:4px;'>" + inqof + inqdtl + "</div></div></div></div>";
   html = html.replace(/ZZZW/g, ZoomWidth); html = html.replace(/ZZZH/g, ZoomHeight); html = html.replace(/ZZQUALITY/g, ZoomQuality);
   ZoomDIV.innerHTML = html;
   ZoomIMG_Obj = document.getElementById('zoomimg');
   Zoom1_Obj   = document.getElementById('zoom1');
   Zoom2_Obj   = document.getElementById('zoom2');
   var divtop = document.body.scrollTop + document.documentElement.scrollTop;
   if (divtop < 0) {divtop = 0;}
   ZoomDIV.style.top = divtop  + 'px';
   ZoomTop = divtop;
   ZoomDIV.style.visibility = 'visible';
}

function ZoomNext(i) {
   ZoomOf++; if (ZoomOf > I6[i]) {ZoomOf = 1;}
   document.getElementById('of').innerHTML = ZoomOf + " of " + I6[i];
   var source = "./cache/"+I2[i]+"_"+I3[i]+Suffix[ZoomOf]+"_ZZZW_ZZZH_"+Quality+".jpg?"+MTime+"&w=ZZZW&h=ZZZH&q="+Quality+"&c="+I2[i]+"_"+I3[i]+Suffix[ZoomOf]+"&s="+I1[i]+Suffix[ZoomOf]+".jpg";
   source = source.replace(/ZZZW/g, ZoomWidth); source = source.replace(/ZZZH/g, ZoomHeight); source = source.replace(/ZZQUALITY/g, ZoomQuality);
   ZoomIMG_Obj.onload = function(){Zoom1_Obj.style.width = ZoomIMG_Obj.width + 'px';Zoom2_Obj.style.width = ZoomIMG_Obj.width + 'px';};
   ZoomIMG_Obj.src = source;
}

function CloseZoom() {
   CloseInquire(); CloseDetail(); window.location.hash = "all";
   ZoomDIV.style.visibility = 'hidden';
   ZoomDIV.innerHTML = "";
   ZoomDIV.style.top  = "0px";
   ZoomDIV.style.left = "0px";
   ZoomOpen = 0;
}

function OpenDetail(i) {
   HideTip();
   var ref = "";
   var keys = I14[i].split(",");
   if (keys[0] != "") {
      for (var i2=0; i2<keys.length; i2++) {
          if (i2 > 0) {ref = ref + ", ";} else {ref = "Reference: ";}
          ref = ref + "<a href='ref.shtml?" + keys[i2].replace(/ /g, "_") + "' target='_blank'>" + keys[i2] + "</a>";
      }
   }
   var printerfriendly = '';
   if (Printer) {
      printerfriendly = "<a href='javascript:PrintItem(" + i + ")' title='Click for Printer Friendly Popup'>Printer Friendly</a>";
   }
   var mydesc = unescape(I11[i]);
   mydesc = mydesc.replace(/\r\n|\n/g,"<br>");
   var html = "<div style='position:absolute;width:100%;top:0px;left:0px;'>";
   html += "<div align='center' class='detailtxt' style='width:" + ZoomIMG_Obj.width + "px'>";
   html += "<div align='left' style='padding:4px'>" + I10u[i] + "<p>" + mydesc + "</p><p>" + ref + "</p><p>" + printerfriendly + "</p></div></div></div>";
   html += "<div style='position:absolute;width:100%;top:6px;left:0px'>";
   html += "<div align='center' style='width:" +  ZoomIMG_Obj.width + "px'>";
   html += "<div style='float:right;padding:4px;'><span class='closebtn' onclick='CloseDetail()'>&nbsp;X&nbsp;</span></div></div></div>";
   DetailDIV.innerHTML = html;
   DetailDIV.style.top  = ZoomTop + 'px';
   DetailDIV.style.visibility = 'visible';
}

function CloseDetail() {
   HideTip();
   DetailDIV.style.visibility = 'hidden';
   DetailDIV.innerHTML = "";
   DetailDIV.style.top  = "0px";
   DetailDIV.style.left = "0px";
}

function PrintItem(i) {
   var mydesc = unescape(I11[i]);
   mydesc = mydesc.replace(/\r\n|\n/g,"<br>");
   var html = "<div style='font-family:" + Printer_FontFamily + "; font-size:" + Printer_FontSize + ";'>" + document.getElementById('Company').innerHTML;
   html += "<div align='left'><div align='left' style='width:600px'><p>" + I10u[i] + "</p><p>" + mydesc + "</p></div>";
   for (i2=1; i2<=I6[i]; i2++) {
       html += "<p><img src='./cache/"+I2[i]+"_"+I3[i]+Suffix[i2]+"_600_600_100.jpg?"+MTime+"&w=600&h=600&q=100&c="+I2[i]+"_"+I3[i]+Suffix[i2]+"&s="+I1[i]+Suffix[i2]+".jpg'></p>";
   }
   html += "</div></div>";
   popup=window.open("","Print",'toolbar=1,location=0,menuBar=0,status=0,width=637,left=0,top=0,scrollbars=1,resizable=1');
   popup.document.open();
   popup.document.write(html);
   popup.document.close();
}

function OpenInquire(i) {
   if (InqOpen) {return;}
   HideTip();
   if (!S2[I5[i]]) {alert("Unavailable - Sorry"); return;}
   InqOpen = 1;
   var html = "<div style='position:absolute;width:100%;top:0px;left:0px'>";
   html += "<div align='center' class='inqtxt' style='width:307px'>";
   html += "<div align='left' style='padding:4px'>";
   html += "<div style='width:274px'>" + I10u[i] + "</div>";
   var buyused = "";
   var price = 0;
   var shipping = 0;
   if (/^[0-9]+(\.[0-9]{1,2})?$/.test("0" + I8[i])) {price = new Number(I8[i]); price = price.toFixed(2);}
   if (/^[0-9]+(\.[0-9]{1,2})?$/.test("0" + I8s[i])) {shipping = new Number(I8s[i]); shipping = shipping.toFixed(2);}
   var vars = I7[i] + "_vars";
   var buydata = unescape(eval(vars)) + ";;;;"; var buyword = buydata.split(";");
   if ((price > 0 && ShowPrice) || (price > 0 && buyword[0] != "" && buyword[1] != "")) {
      html += "<br><b>$" + price + "</b>&nbsp;&nbsp;<i>" + buyword[2] + "</i><br>";
   }
   if ((shipping > 0 && ShowShipping) || (price > 0 && shipping > 0 && buyword[0] != "" && buyword[1] != "")) {
      html += "<br><b>$" + shipping + "</b>&nbsp;&nbsp;<i>" + buyword[3] + "</i><br>";
   }
   if ((Force_BuyNow || I9[i]) && price > 0 && buyword[0] != "" && buyword[1] != "") {
      if (buyword[0] == "paypal") {
         buyused = "paypal";
         html += "<br><div align='center'><form action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post' class='buynowbtn'>";
         html += "<input type='hidden' name='cmd' value='_xclick'>";
         html += "<input type='hidden' name='business' value='" + buyword[1] + "'>";
         html += "<input type='hidden' name='lc' value='US'>";
         html += "<input type='hidden' id='paypal_item_name' name='item_name' value=''>";
         html += "<input type='hidden' name='item_number' value='" + I4[i] + "'>";
         html += "<input type='hidden' name='amount' value='" + price + "'>";
         if (shipping > 0) {html += "<input type='hidden' name='shipping' value='" + shipping + "'>";}
         html += "<input type='hidden' name='currency_code' value='USD'>";
         html += "<input type='hidden' name='button_subtype' value='products'>";
         html += "<input type='hidden' name='return' value='http://" + Host + "/gallery.shtml?" + Gallery + "#" + I4[i] + ",paypal'>";
         html += "<input type='hidden' name='cancel_return' value='http://" + Host + "/gallery.shtml?" + Gallery + "#all'>";
         html += "<input type='hidden' name='notify_url' value='http://" + Host + "/utils/zzipn01.cgi'>";
         html += "<input type='hidden' name='custom' value='&gallery=" + Gallery + "&menu=" + Here + "&sourcegallery=" + I2[i] + "&sourceitem=" + I3[i] + "&contact=" + I7[i] + "&status=" + S3[I5[i]] + "'>";
         html += "<input type='hidden' name='bn' value='PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest'>";
         html += "<input type='image' src='https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif' name='submit'>";
         html += "</form><br>";
         html += "<b>You may <i>Buy Now</i> or send us your inquiry:</b></div>";
      }
   }
   html += "<br><b>Email Address <span style='color:green'>*</span></b>";
   html += "<br><input type='text' id='i_email' title='Email Address - Required' style='width:293px'>";
   html += "<br><b>Phone Number <span style='color:green'>*</span></b>";
   html += "<br><input type='text' id='i_phone' title='Phone Number - Required' style='width:293px'>";
   html += "<br><b><div style='width:108px; float:left'>First Name <span style='color:green'>*</span></div><div style='width:168px; float:left'>Last Name <span style='color:green'>*</span></div>&nbsp;Mi</b>";
   html += "<br><input type='text' id='i_first' title='First Name - Required' style='width:100px'>";
   html += "&nbsp;<input type='text' id='i_last' title='Last Name - Required' style='width:160px'>";
   html += "&nbsp;<input type='text' id='i_middle' title='Middle Initial' style='width:15px'>";
   html += "<br><b>Note <span style='color:green'>*</span></b>";
   if (ItemNumber) {
      html += "<br><textarea id='i_note' title='Note - Required' class='input' style='width:293px; height:35px;'>Please contact me about item: " + I4[i] + ".</textarea>";
   } else {
      html += "<br><textarea id='i_note' title='Note - Required' class='input' style='width:293px; height:35px;'>Please contact me about item: " + unescape(I10[i]) + ".</textarea>";
   }
   html += "<br><br><div align='center' style='width:300px;'><b>If you want to be added to our mailing list or will need a shipping quote, please enter the following:</b></div>";
   html += "<br><b>Company Name</b>";
   html += "<br><input type='text' title='Company Name' id='i_company' style='width:293px'>";
   html += "<br><b>Address Line 1</b>";
   html += "<br><input type='text' title='Address Line 1' id='i_addr1' style='width:293px'>";
   html += "<br><b>Address Line 2</b>";
   html += "<br><input type='text' title='Address Line 2' id='i_addr2' style='width:293px'>";
   html += "<br><b><div style='width:148px; float:left'>City</div>&nbsp;State / Province</b>";
   html += "<br><input type='text' id='i_city' title='City' style='width:142px'>";
   html += "&nbsp;<input type='text' id='i_state' title='State / Province' style='width:142px'>";
   html += "<br><b><div style='width:148px; float:left'>Zip / Postal Code</div>&nbsp;Country</b>";
   html += "<br><input type='text' id='i_zip' title='Zip / Postal Code' style='width:142px'>";
   html += "&nbsp;<input type='text' id='i_country' title='Country' style='width:142px'>";
   html += "<br><input type='checkbox' id='i_cookie' title='Uncheck if on public computer' class='adminchk'> Remember me after closing the browser";
   html += "<br><br><div align='center' style='width:292px; padding:4px; height:20px;'><span class='inqbtn' onclick='PostInquire(" + i + ")'>Send Inquiry</span>&nbsp;&nbsp;&nbsp;&nbsp;<span class='inqbtn' style='color:red' onclick='CloseInquire()'>Cancel</span></div></div>";
   html += "<div style='position:absolute;width:100%;top:6px;left:0px'>";
   html += "<div align='center' style='width:307px'>";
   html += "<div style='float:right;padding:4px;'><span class='closebtn' onclick='CloseInquire()'>&nbsp;X&nbsp;</span></div></div></div></div></div></div></div>";
   InqDIV.innerHTML = html;
   if (buyused == "paypal") {document.getElementById("paypal_item_name").value = unescape(I10[i]);}
   document.getElementById('i_cookie').checked = true;
   GetInquireCookies();
   var divtop = document.body.scrollTop + document.documentElement.scrollTop;
   if (divtop < 0) {divtop = 0;}
   InqDIV.style.top = divtop + 'px';
   InqDIV.style.visibility = 'visible';
   var obj = document.getElementById("i_email");
   setTimeout(function(){obj.focus();},1); obj.focus();
}

function SetInquireCookies(i) {
   var date = new Date();
   date.setTime(date.getTime()+31622400000);
   var expires = "~; expires=" + date.toGMTString() + "; path=/";
   var savecookie = false; if (document.getElementById('i_cookie').checked) {savecookie = true;}
   FakeCookie =  "i_host="          + Host             + "~"; if (savecookie) {document.cookie = "i_host="          + Host            + expires;}
   FakeCookie += "i_site="          + Site             + "~"; if (savecookie) {document.cookie = "i_site="          + Site            + expires;}
   FakeCookie += "i_sub="           + Sub              + "~"; if (savecookie) {document.cookie = "i_sub="           + Sub             + expires;}
   FakeCookie += "i_sitetitle="     + SiteTitle        + "~"; if (savecookie) {document.cookie = "i_sitetitle="     + SiteTitle       + expires;}
   FakeCookie += "i_gallery="       + Gallery          + "~"; if (savecookie) {document.cookie = "i_gallery="       + Gallery         + expires;}
   FakeCookie += "i_menu="          + Here             + "~"; if (savecookie) {document.cookie = "i_menu="          + Here            + expires;}
   FakeCookie += "i_image="         + I1[i] + "a.jpg"  + "~"; if (savecookie) {document.cookie = "i_image="         + I1[i] + "a.jpg" + expires;}
   FakeCookie += "i_sourcegallery=" + I2[i]            + "~"; if (savecookie) {document.cookie = "i_sourcegallery=" + I2[i]           + expires;}
   FakeCookie += "i_sourceitem="    + I3[i]            + "~"; if (savecookie) {document.cookie = "i_sourceitem="    + I3[i]           + expires;}
   FakeCookie += "i_item="          + I4[i]            + "~"; if (savecookie) {document.cookie = "i_item="          + I4[i]           + expires;}
   FakeCookie += "i_status="        + S3[I5[i]]        + "~"; if (savecookie) {document.cookie = "i_status="        + S3[I5[i]]       + expires;}
   FakeCookie += "i_count="         + I6[i]            + "~"; if (savecookie) {document.cookie = "i_count="         + I6[i]           + expires;}
   FakeCookie += "i_contact="       + I7[i]            + "~"; if (savecookie) {document.cookie = "i_contact="       + I7[i]           + expires;}
   FakeCookie += "i_price="         + I8[i]            + "~"; if (savecookie) {document.cookie = "i_price="         + I8[i]           + expires;}
   FakeCookie += "i_sh="            + I8s[i]           + "~"; if (savecookie) {document.cookie = "i_sh="            + I8s[i]          + expires;}
   FakeCookie += "i_buynow="        + I9[i]            + "~"; if (savecookie) {document.cookie = "i_buynow="        + I9[i]           + expires;}
   FakeCookie += "i_key="           + I17[i]           + "~"; if (savecookie) {document.cookie = "i_key="           + I17[i]          + expires;}
   FakeCookie += "i_title="         + unescape(I10[i]) + "~"; if (savecookie) {document.cookie = "i_title="         + I10[i]          + expires;}
   FakeCookie += "i_desc="          + unescape(I11[i]) + "~"; if (savecookie) {document.cookie = "i_desc="          + I11[i]          + expires;}
   FakeCookie += "i_email="   + document.getElementById("i_email").value   + "~"; if (savecookie) {document.cookie = "i_email="   + escape(document.getElementById("i_email").value)   + expires;}
   FakeCookie += "i_phone="   + document.getElementById("i_phone").value   + "~"; if (savecookie) {document.cookie = "i_phone="   + escape(document.getElementById("i_phone").value)   + expires;}
   FakeCookie += "i_last="    + document.getElementById("i_last").value    + "~"; if (savecookie) {document.cookie = "i_last="    + escape(document.getElementById("i_last").value)    + expires;}
   FakeCookie += "i_first="   + document.getElementById("i_first").value   + "~"; if (savecookie) {document.cookie = "i_first="   + escape(document.getElementById("i_first").value)   + expires;}
   FakeCookie += "i_middle="  + document.getElementById("i_middle").value  + "~"; if (savecookie) {document.cookie = "i_middle="  + escape(document.getElementById("i_middle").value)  + expires;}
   FakeCookie += "i_note="    + document.getElementById("i_note").value    + "~"; if (savecookie) {document.cookie = "i_note="    + escape(document.getElementById("i_note").value)    + expires;}
   FakeCookie += "i_company=" + document.getElementById("i_company").value + "~"; if (savecookie) {document.cookie = "i_company=" + escape(document.getElementById("i_company").value) + expires;}
   FakeCookie += "i_addr1="   + document.getElementById("i_addr1").value   + "~"; if (savecookie) {document.cookie = "i_addr1="   + escape(document.getElementById("i_addr1").value)   + expires;}
   FakeCookie += "i_addr2="   + document.getElementById("i_addr2").value   + "~"; if (savecookie) {document.cookie = "i_addr2="   + escape(document.getElementById("i_addr2").value)   + expires;}
   FakeCookie += "i_city="    + document.getElementById("i_city").value    + "~"; if (savecookie) {document.cookie = "i_city="    + escape(document.getElementById("i_city").value)    + expires;}
   FakeCookie += "i_state="   + document.getElementById("i_state").value   + "~"; if (savecookie) {document.cookie = "i_state="   + escape(document.getElementById("i_state").value)   + expires;}
   FakeCookie += "i_zip="     + document.getElementById("i_zip").value     + "~"; if (savecookie) {document.cookie = "i_zip="     + escape(document.getElementById("i_zip").value)     + expires;}
   FakeCookie += "i_country=" + document.getElementById("i_country").value + "~"; if (savecookie) {document.cookie = "i_country=" + escape(document.getElementById("i_country").value) + expires;}
}

function GetInquireCookies() {
   var cookie; var cookies = unescape(document.cookie) + FakeCookie + "~i_email=~i_phone=~i_last=~i_first=~i_middle=~i_company=~i_addr1=~i_addr2=~i_city=~i_state=~i_zip=~i_country=~";
   cookie = cookies.substr(cookies.indexOf("i_email=")+8);    document.getElementById("i_email").value   = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_phone=")+8);    document.getElementById("i_phone").value   = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_last=")+7);     document.getElementById("i_last").value    = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_first=")+8);    document.getElementById("i_first").value   = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_middle=")+9);   document.getElementById("i_middle").value  = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_company=")+10); document.getElementById("i_company").value = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_addr1=")+8);    document.getElementById("i_addr1").value   = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_addr2=")+8);    document.getElementById("i_addr2").value   = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_city=")+7);     document.getElementById("i_city").value    = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_state=")+8);    document.getElementById("i_state").value   = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_zip=")+6);      document.getElementById("i_zip").value     = cookie.substr(0, cookie.indexOf("~"));
   cookie = cookies.substr(cookies.indexOf("i_country=")+10); document.getElementById("i_country").value = cookie.substr(0, cookie.indexOf("~"));
}

function PostInquire(i) {
   var phoneobj = document.getElementById("i_phone");
   phoneobj.value = phoneobj.value.replace(/\s/g,"");
   if (!Phone_RE.test(phoneobj.value) || phoneobj.value == "" || phoneobj.value == null) {
      setTimeout(function(){phoneobj.focus();phoneobj.select();},1);
      phoneobj.focus();
      phoneobj.select();
      alert("Please provide a valid Phone Number");
      return;
   }
   var emailobj = document.getElementById("i_email");
   emailobj.value = emailobj.value.replace(/\s/g,"");
   if (!Email_RE.test(emailobj.value) || emailobj.value == "" || emailobj.value == null) {
      setTimeout(function(){emailobj.focus();emailobj.select();},1);
      emailobj.focus();
      emailobj.select();
      alert("Please provide a valid Email Address");
      return;
   }
   var firstobj = document.getElementById("i_first");
   if (firstobj.value == "" || firstobj.value == null) {
      setTimeout(function(){firstobj.focus();firstobj.select();},1);
      firstobj.focus();
      firstobj.select();
      alert("Please provide your First and Last Name");
      return;
   }
   var lastobj = document.getElementById("i_last");
   if (lastobj.value == "" || lastobj.value == null) {
      setTimeout(function(){lastobj.focus();lastobj.select();},1);
      lastobj.focus();
      lastobj.select();
      alert("Please provide your First and Last Name");
      return;
   }
   var noteobj = document.getElementById("i_note");
   if (noteobj.value == "" || noteobj.value == null) {
      setTimeout(function(){noteobj.focus();noteobj.select();},1);
      noteobj.focus();
      noteobj.select();
      alert("Please provide a Note");
      return;
   }
   document.getElementById("i_email").value   = document.getElementById("i_email").value.replace(/~/g,"");
   document.getElementById("i_phone").value   = document.getElementById("i_phone").value.replace(/~/g,"");
   document.getElementById("i_last").value    = document.getElementById("i_last").value.replace(/~/g,"");
   document.getElementById("i_first").value   = document.getElementById("i_first").value.replace(/~/g,"");
   document.getElementById("i_middle").value  = document.getElementById("i_middle").value.replace(/~/g,"");
   document.getElementById("i_note").value    = document.getElementById("i_note").value.replace(/~/g,"");
   document.getElementById("i_company").value = document.getElementById("i_company").value.replace(/~/g,"");
   document.getElementById("i_addr1").value   = document.getElementById("i_addr1").value.replace(/~/g,"");
   document.getElementById("i_addr2").value   = document.getElementById("i_addr2").value.replace(/~/g,"");
   document.getElementById("i_city").value    = document.getElementById("i_city").value.replace(/~/g,"");
   document.getElementById("i_state").value   = document.getElementById("i_state").value.replace(/~/g,"");
   document.getElementById("i_zip").value     = document.getElementById("i_zip").value.replace(/~/g,"");
   document.getElementById("i_country").value = document.getElementById("i_country").value.replace(/~/g,"");
   SetInquireCookies(i);
   CloseInquire();
   alert("Thank you! Your inquiry is being sent.");
   var obj_xml = false; if (window.ActiveXObject) {try {obj_xml = new ActiveXObject("Msxml2.XMLHTTP");} catch(err) {obj_xml = false;}}
   if (!obj_xml && window.ActiveXObject) {try {obj_xml = new ActiveXObject("Microsoft.XMLHTTP");} catch(err) {obj_xml = false;}}
   if (!obj_xml) {try {obj_xml = new XMLHttpRequest();} catch(err) {obj_xml = false;}}
   if (obj_xml) {
      try {
         var args = encodeURIComponent(FakeCookie);
         obj_xml.open("POST", "/utils/zzinq01.cgi", true);
         obj_xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         obj_xml.send("PostData=" + args);
         obj_xml.onreadystatechange=function()
         {
            if (obj_xml.readyState==4) {
               if (obj_xml.responseText != 0 || obj_xml.status != 200) {
                  alert("We are sorry, your inquiry did not go thru.\r\nThere may a connection issue or we may be performing maintenance.\r\nPlease try again later." + "\r\n\r\nResponseText='" + obj_xml.responseText + "'");
               }
            }
         }
      } catch(err){};
   }
}

function CloseInquire() {
   HideTip();
   InqDIV.style.visibility = 'hidden';
   InqDIV.innerHTML = "";
   InqDIV.style.top  = "0px";
   InqDIV.style.left = "0px";
   InqOpen = 0;
}

function WatchForBookMark() {
   if (!Initialized || AdminMode) {return;}
   if (window.location.hash == "#slides" && !SlideShowOpen) {
      if (ZoomOpen) {CloseZoom();}
      OpenSlideShow();
   } else {
      if (!ZoomOpen && /#[0-9]+-[0-9]+/.test(window.location.hash)) {
         var hash = window.location.hash.substr(1) + ","; var word = hash.split(",");
         var hashitem = -1; for (var i=0; i<I1.length; i++) {if (I4[i] == word[0]) {if (I5[i] < HideBegin) {hashitem = i;} break;}}
         if (hashitem >= 0) {document.title = SiteTitle + " - " + Here; OpenZoom(hashitem);} else {window.location.hash = "all";}
      }
   }
}

function Poll(silent) {
   var obj_xml = false; if (window.ActiveXObject) {try {obj_xml = new ActiveXObject("Msxml2.XMLHTTP");} catch(err) {obj_xml = false;}}
   if (!obj_xml && window.ActiveXObject) {try {obj_xml = new ActiveXObject("Microsoft.XMLHTTP");} catch(err) {obj_xml = false;}}
   if (!obj_xml) {try {obj_xml = new XMLHttpRequest();} catch(err) {obj_xml = false;}}
   if (obj_xml) {
      try {
         var args = "&gallery=" + Gallery + "&mtime=" + MTime;
         obj_xml.open("POST", "/utils/zzpoll01.cgi", true);
         obj_xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         obj_xml.send(args);
         obj_xml.onreadystatechange=function()
         {
            if (obj_xml.readyState==4) {
               if (obj_xml.responseText == 0 && JS_MTime == MTime) {
                  if (!silent) {
                     PollTimer = setTimeout("Poll()",Polling);
                  }
               } else {
                  if (silent) {
                     clearTimeout(PollTimer);
                     document.location.reload(true);
                  } else {
                     clearTimeout(PollTimer);
                     if (SlideShowOpen) {SlideShowOpen = false; clearTimeout(SlideTimer); clearTimeout(LoadTimer);}
                     alert("Automated message from " + SiteTitle + ":\r\n\r\nOur content has changed - we will reload/refresh your page.");
                     document.location.reload(true);
                  }
               }
            }
         }
      } catch(err){};
   }
}

function OpenSlideShow() {
   if (SlideShowOpen) {return;}
   if (SlideList.length < 2) {return;}
   Slides = SlideList.length - 1;
   clearTimeout(SlideTimer); clearTimeout(LoadTimer);
   CurrentViewPortWidth = eval(ViewPortWidth);
   CurrentViewPortHeight = eval(ViewPortHeight);
   SlideWidth = CurrentViewPortWidth - 4;
   if (SlideWidth < SlideMin) {SlideWidth = SlideMin;} else if (SlideWidth > SlideMax) {SlideWidth = SlideMax;}
   SlideHeight = CurrentViewPortHeight - 4;
   document.getElementsByTagName('html')[0].style.overflow = 'hidden';
   document.getElementsByTagName('body')[0].style.backgroundColor = 'black';
   PageDIV.style.visibility = 'hidden';
   var firstwidth = SlideWidth;
   var firstheight = SlideHeight;
   var size = I12[SlideList_Item[1]].split(";");
   var imgwidth  = parseInt(size[0],10);
   var imgheight = parseInt(size[1],10);
   var aspect = imgwidth / imgheight;
   var w1 = Math.min(firstwidth, imgwidth);   var h1 = w1 / aspect;
   var h2 = Math.min(firstheight, imgheight); var w2 = h2 * aspect;
   if (w1 > firstwidth || h1 > firstheight) {firstwidth = Math.floor(w2); firstheight = Math.floor(h2);} else {firstwidth = Math.floor(w1); firstheight = Math.floor(h1);}
   var divtop = document.body.scrollTop + document.documentElement.scrollTop;
   if (divtop < 0) {divtop = 0;}
   SlideDIV.style.top  = divtop  + 'px';
   SlideDIV.style.left = '0px';
   var stats = "background-repeat:no-repeat;background-image:url(\"/utils/zzhit01.cgi?&site=" + Site + "&sub=" + Sub + "&stats=s&key=" + Gallery + "&image=hit.gif\")";
   var html = "<div style='overflow:hidden;" + stats + "'>";
   html += "<img id='slides' style='cursor:pointer' src='" + SlideList[1] + "' class='slideimg' onclick='ClickSlide()'";
   html += " title='Click to Pause or Continue'>";
   html = html.replace(/ZZSW/g, SlideWidth); html = html.replace(/ZZSH/g, SlideHeight); html = html.replace(/ZZQUALITY/g, Quality);
   html += "<div style='position:absolute;width:100%;top:6px;left:0px'>";
   html += "<div id='slideshowcontrols' align='center' style='width:" + firstwidth + "px'>";
   html += "<div style='float:left;padding:4px;'><div class='slidetxt' id='slideshowstatus'></div></div><div style='float:right;padding:4px;'><span class='closebtn' title='Close' onclick='CloseSlideShow()'>&nbsp;X&nbsp;</span></div></div></div></div>";
   for (var i=1; i<=Slides; i++) {SlidesBuffer[i] = new Image(); SlideRequested[i] = false;}
   SlideDIV.innerHTML = html;
   SlideDIV.style.visibility = 'visible';
   SlideShowControls_Obj = document.getElementById('slideshowcontrols');
   SlideShowStatus_Obj = document.getElementById('slideshowstatus');
   Slides_Obj = document.getElementById('slides');
   Slide = 1; LoadSlide = 1;
   if (SlidesDelay < 4000) {SlidesDelay = 4000;}
   SlideShowOpen = true; PauseSlideShow = false; window.location.hash = "slides";
   SlideTimer = setTimeout("SwitchSlide()",SlidesDelay); LoadTimer = setTimeout("LoadSlides()",2000);
}

function LoadSlides() {
   if (!SlideShowOpen) {return;}
   if (SlideRequested[LoadSlide] && !SlidesBuffer[LoadSlide].complete) {LoadTimer = setTimeout("LoadSlides()",1000); return;}
   LoadSlide++; if (LoadSlide > Slides) {LoadSlide = 1;}
   var source = SlideList[LoadSlide].replace(/ZZSW/g, SlideWidth); source = source.replace(/ZZSH/g, SlideHeight); source = source.replace(/ZZQUALITY/g, Quality);
   SlidesBuffer[LoadSlide].src = source;
   SlideRequested[LoadSlide] = true;
   if (LoadSlide != 1) {LoadTimer = setTimeout("LoadSlides()",1000);}
}

function SwitchSlide() {
   if (!SlideShowOpen) {return;} if (PauseSlideShow) {return;}
   if (!Slides_Obj.complete) {SlideTimer = setTimeout("SwitchSlide()",1000); return;}
   if (Slide < Slides && !SlidesBuffer[Slide + 1].complete) {SlideTimer = setTimeout("SwitchSlide()",1000); return;}
   Slide++; if (Slide > Slides) {Slide = 1;}
   Slides_Obj.onload = function(){SlideShowControls_Obj.style.width = SlidesBuffer[Slide].width + 'px';};
   Slides_Obj.src = SlidesBuffer[Slide].src;
   SlideTimer = setTimeout("SwitchSlide()",SlidesDelay);
}

function ClickSlide() {
   try {
      if (PauseSlideShow) {
         PauseSlideShow = false; SlideShowStatus_Obj.style.visibility = 'hidden'; SwitchSlide();
      } else {
         clearTimeout(SlideTimer); PauseSlideShow = true;
         if (I17[SlideList_Item[Slide]].substr(0,1) == '!') {
            SlideShowStatus_Obj.innerHTML = "Pause: <a href='" + I17[SlideList_Item[Slide]].substr(1) + "'>" + I10u[SlideList_Item[Slide]] + "</a>";
         } else {
            SlideShowStatus_Obj.innerHTML = "Pause: <a href='javascript:CloseSlideShow();OpenZoom(" + SlideList_Item[Slide] + ")' title='Click for Zoom View'>" + I10u[SlideList_Item[Slide]] + "</a>";
         }
         SlideShowStatus_Obj.style.visibility = 'visible';
      }
   } catch(err){};
}

function CloseSlideShow() {
   SlideShowOpen = false; window.location.hash = "all";
   clearTimeout(SlideTimer); clearTimeout(LoadTimer);
   HideTip();
   SlideDIV.style.visibility = 'hidden'; SlideDIV.innerHTML = ""; SlideDIV.style.top  = "0px"; SlideDIV.style.left = "0px";
   document.getElementsByTagName('html')[0].style.overflow = SaveOverFlow;
   document.getElementsByTagName('body')[0].style.backgroundColor = SaveBackground;
   PageDIV.style.visibility = 'visible';
}
