// Title: xs_image_a
// modification - pass direct imageilst (not xml list)
// Description: See the demo at url
// URL: www.elogic.ru/ekwatt/js/xs_image/
// Version: 0.5
// Date: 14-05-2006 (dd-mm-yyyy)
// Notes: This script is free. Visit official site for further details.
// (C) Evgeny Kolevatov aka Ekwatt 2006
var Id=[];
function html_xs_image(xs_name,template)
{
var html_code = template.html_template;
html_code = html_code.replace(/#progressholder#/gm,xs_name+'progressholder');
html_code = html_code.replace(/#dst_image#/gm,xs_name+'dst_image');
html_code = html_code.replace(/#prev#/gm,xs_name+'prev');
html_code = html_code.replace(/#next#/gm,xs_name+'next');
return html_code;
}

function Init_xsa_image (xs_name, xs_list, xs_template )
{
  document.write(html_xs_image(xs_name,xs_template));
  preview_holder  = document.images[xs_name+'dst_image'];
  progress_holder = document.images[xs_name+'progressholder'];

  Id[xs_name] = new xsa_image(xs_name, xs_list, xs_template, xs_name+'dst_image', xs_name+'progressholder')
  document.getElementById(xs_name+'next').onclick = function(){Id[xs_name].SetNext();};
  document.getElementById(xs_name+'prev').onclick = function(){Id[xs_name].SetPrev();};
}

//
function xsa_image(xs_name, xs_list, xs_template, preview_holder_name, progress_holder_name){

         this.DstImage_name = preview_holder_name;//
         this.ProgressHolder_name = progress_holder_name;
         this.template = xs_template;
         this.xs_name = xs_name;
        // var request;
       //  try {
       //       request = new XMLHttpRequest();
       //       } catch (e) {  request = new ActiveXObject("Msxml2.XMLHTTP"); }
      //        try {
      //             netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
      //             } catch (e) {  /* ignore */ }
      //             request.open("GET", xs_album, false);
      //             request.send(null);
      //             this.XmlDoc = request.responseXML;
      //             this.Pic_List = this.XmlDoc.getElementsByTagName('pics');
      //             this.Pic_Count = this.Pic_List.length;

         this.Pic_List =  xs_list;
         this.Pic_Count = xs_list.length;

         this.SetNext = function(){
              this.Pic_Current = this.Pic_Current + 1;
              if (this.Pic_Current > (this.Pic_Count-1)) this.Pic_Current = 0;
              this.SetPicture();
              }

         this.SetPrev = function(){
              this.Pic_Current= this.Pic_Current-1;
              if (this.Pic_Current < 0) this.Pic_Current = this.Pic_Count - 1;
              this.SetPicture();
              }


             this.ProgressImageOn = new Image();
               this.ProgressImageOn.src = this.template.LoadOn_src;
             this.ProgressImageOff = new Image();
               this.ProgressImageOff.src = this.template.LoadOff_src;

            // this.Pic_Current = 0;
             this.SetPicture();
}
xsa_image.prototype.CurrentLoadImg={}
xsa_image.prototype.ProgressImageOff={}
xsa_image.prototype.ProgressImageOn={}
xsa_image.prototype.Pic_Current=0;
xsa_image.prototype.xs_name='';

function arf(sxN)
{
 Id[sxN].WhiteWhileImgLoad();
}

xsa_image.prototype.WhiteWhileImgLoad = function A()
{
 var nn= this.xs_name
 //alert (nn);

 if (!this.CurrentLoadImg.complete || (typeof(this.CurrentLoadImg.naturalWidth) != 'undefined' &&
              this.CurrentLoadImg.naturalWidth == 0))
              {

                     setTimeout(function() {arf(nn); }, 200);
              }
              else
              {
                       document.images[this.ProgressHolder_name].src = this.ProgressImageOff.src;
                       document.images[this.DstImage_name].src = this.CurrentLoadImg.src;
                       delete this.CurrentLoadImg;
              }
}
xsa_image.prototype.SetPicture = function ()
{
 // alert (this.Pic_Current);
  document.images[this.ProgressHolder_name].src = this.ProgressImageOn.src;
  this.CurrentLoadImg = new Image();
  this.CurrentLoadImg.src = this.Pic_List[this.Pic_Current];
  this.WhiteWhileImgLoad();
}
