// script (c) Roman Virdi

var imagepath = "pics/";

var fadeimages=new Array();

fadeimages[0]=["104pxza.jpg", "", ""]; 
fadeimages[1]=["01pxza.jpg", "", ""]; 
fadeimages[2]=["02pxza.jpg", "", ""]; 
fadeimages[3]=["09pxza.jpg", "", ""]; 
fadeimages[4]=["03pxza.jpg", "", ""]; 
fadeimages[5]=["05pxza.jpg", "", ""]; 
fadeimages[6]=["04pxza.jpg", "", ""]; 
fadeimages[7]=["7bpxza.jpg", "", ""]; 
fadeimages[8]=["08pxza.jpg", "", ""]; 
fadeimages[9]=["22pxza.jpg", "", ""]; 
fadeimages[10]=["105pxza.jpg", "", ""]; 
fadeimages[11]=["108pxza.jpg", "", ""]; 
fadeimages[12]=["109pxza.jpg", "", ""]; 
fadeimages[13]=["10pxza.jpg", "", ""]; 
fadeimages[14]=["12pxza.jpg", "", ""]; 
fadeimages[15]=["13pxza.jpg", "", ""]; 
fadeimages[16]=["14pxza.jpg", "", ""]; 
fadeimages[17]=["102pxza.jpg", "", ""]; 
fadeimages[18]=["15pxza.jpg", "", ""]; 
fadeimages[19]=["16pxza.jpg", "", ""]; 
fadeimages[20]=["17pxza.jpg", "", ""]; 
fadeimages[21]=["20pxza.jpg", "", ""]; 
fadeimages[22]=["21pxza.jpg", "", ""]; 
fadeimages[23]=["101pxza.jpg", "", ""]; 
fadeimages[24]=["103pxza.jpg", "", ""]; 
fadeimages[25]=["24pxza.jpg", "", ""]; 
fadeimages[26]=["25pxza.jpg", "", ""]; 
fadeimages[27]=["110pxza.jpg", "", ""]; 
var curDir="";  

var OPACITY_INITIAL=10;
var OPACITY_INCREMENT=15;

var BACKWARD=0; 
var FORWARD=1;
var RANDOM=2;
var NONE=3;   

var fadebgcolor="#ffffff";  // for black css this is #eeeeee
 
var instances=new Array(); //array to cache timeouts instances
var timeouts=new Array(); //array to cache corresponding clearinterval pointers
var viewtimeouts=new Array(); //array to cache view timeouts
 
var iebrowser=document.all;
var is_dom=document.getElementById;

var ACTION_NONE = 0;
var ACTION_CLICK = 1;
var ACTION_OVER = 2;
var actiontype = ACTION_NONE;
var actionimg = '';
var TIMESLICE = 50; /* milliseconds */

//--------------------------------------------------
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function thumbclicked (img)
{
   actiontype = ACTION_CLICK;
   actionimg = img;
}

function thumbover (img)
{
   actiontype = ACTION_OVER;
   actionimg = img;
}

function fadeshow(theimages, showthumbs, fadewidth, fadeheight, borderwidth, delay, pause, displayorder)
{
  var thumbshandle=iebrowser? iebrowser["thumbs"] : document.getElementById("thumbs");

  createCookie('tfalbumpage', location.href, 10);
  
  this.pausecheck=1; /* pause */
  this.paused=0;
  autorestart=1;
  this.delay=delay;
  this.delayRemaining = 0;
  this.degree=OPACITY_INITIAL;
  this.imageIsStable = 0;
  this.nrPrints = 0;
  
  instances[instances.length]=this;
  this.slideshowid=instances.length-1;
  this.canvasbase="canvas"+this.slideshowid;
  this.curcanvas=this.canvasbase+"_0";

  // initializing with any values. only used for IE fleck problem workaround
  this.othercanvas=this.canvasbase+"_1";
  this.otherobj=this;

  if (displayorder=="random")
    theimages.sort(function() {return 0.5 - Math.random();}) ;
  this.theimages=theimages;
  this.imageborder=parseInt(borderwidth);
  this.postimages=new Array(); //preload images
  thumbstring='';
 
  this.curimageindex=0;
   
  var fadewidth=fadewidth+this.imageborder*2;
  var fadeheight=fadeheight+this.imageborder*2;
   
  if (iebrowser&&is_dom||is_dom) //if IE5+ or modern browsers (ie: Firefox)
      document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+    'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;text-align:center;vertical-align:middle; width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=00);-moz-opacity:000;-khtml-opacity:000;background:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;text-align:center;vertical-align:middle; width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=100);-moz-opacity:100;background:'+fadebgcolor+'"></div></div>');
  else  // non fadeable browsers
	  document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>');

  var tempobj=iebrowser? iebrowser[this.canvasbase+"_1"] : document.getElementById(this.canvasbase+"_1");
  tempobj.innerHTML='<div style="margin-top: 160px"><img src="'+imagepath+'loading.gif"></div>'; 

  for (p=0;p<theimages.length;p++)
  {
    this.postimages[p]=new Image();
    this.postimages[p].src=imagepath+theimages[p][0];
  }

  if (iebrowser&&is_dom||is_dom) //if IE5+ or modern browsers such as Firefox
  {
	  this.startit(); 
  }
  else {
	// this.delayRemaining = this.delay;
	// SetInterval("instances["+this.slideshowid+"].rotateimage(NONE)", 4000);
  }
  setInterval("instances["+this.slideshowid+"].idletask()", TIMESLICE); // continual background process
}

//--------------------------------------------------
function fadepic(obj)
{
  if ((obj.degree<100) && (obj.curimageindex<obj.postimages.length))
  {
    // fade in picture. it fades over the previous pic
	
	obj.degree+=OPACITY_INCREMENT;  // edit this to get a slower/faster fade; was 10

	if (obj.tempobj.filters&&obj.tempobj.filters[0])
	{
      if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
        obj.tempobj.filters[0].opacity=obj.degree;
      else //else if IE5.5-
        obj.tempobj.style.filter="alpha(opacity="+obj.degree+")";
    }
    else if (obj.tempobj.style.MozOpacity)
		obj.tempobj.style.MozOpacity=(obj.degree-1)/100;
    else if (obj.tempobj.style)
		obj.tempobj.style.opacity=(obj.degree-1)/100;
	  
  } else {
    
	// workaround for IE flecks: display a black image in other canvas when image load complete
	
	obj.othercanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1";
	obj.otherobj=iebrowser? iebrowser[obj.othercanvas] : document.getElementById(obj.othercanvas);
    obj.otherobj.innerHTML='<img src="black.jpg" width="840" height="467" />';

	// pic is faded in, set timer till next is displayed 
	
	clearInterval(timeouts[obj.slideshowid]); // stop the fader timer

	if ((!obj.paused) && 
	    (autorestart || (obj.curimageindex<obj.postimages.length+1)))
	   // set view timer 
    { 
  	  obj.delayRemaining = obj.delay;
	  obj.imageIsStable = 1;
	  // viewtimeouts[obj.slideshowid] = 
	  //   setTimeout("instances["+obj.slideshowid+"].rotateimage(FORWARD)", TIMESLICE);
		 
	}
  }
}

//--------------------------------------------------
fadeshow.prototype.displayImage=function(picobj, picindex)
{
  var slideHTML="";

  if (this.theimages[picindex][1]!="") //if associated link exists for image
    slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">';

  slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">';

  if (this.theimages[picindex][1]!="") //if associated link exists for image
    slideHTML+='</a>';
  picobj.innerHTML=slideHTML;
};
 
//--------------------------------------------------

fadeshow.prototype.idletask=function()
{
  if (actiontype == ACTION_OVER)
  {
	   this.imageIsStable = 0;
	   actiontype = ACTION_NONE;
       clearInterval(timeouts[this.slideshowid]); // stop the fader timer

       var pausecontainer=iebrowser? iebrowser["pause"] : document.getElementById("pause");
       var fwdcontainer=iebrowser? iebrowser["fwd"] : document.getElementById("fwd");

       this.paused=1; 
       pausecontainer.innerHTML=PLAY_HTML;
    
       this.nextcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_0" : this.canvasbase+"_1";
       this.tempobj=iebrowser? iebrowser[this.nextcanvas] : document.getElementById(this.nextcanvas);
	 
       this.delayRemaining = 0;
	   this.curimageindex = parseInt(actionimg);
	   this.displayImage(this.tempobj, this.curimageindex);
       this.rotateimage(RANDOM, this.curimageindex);
	}
	
  if (this.paused == 1)
  {
	  this.delayRemaining = 0;  // be sure that the auto-mode delay is turned off
      this.imageIsStable = 0;
  }
  else 
  if (this.delayRemaining > 0)
  {
	 this.delayRemaining = this.delayRemaining-TIMESLICE; // wait some more
  }
  else 
  {
	  if (this.imageIsStable == 1)
	  {
		  this.imageIsStable = 0;
		  this.rotateimage(FORWARD); // ok, next image
	  }
  }
};

fadeshow.prototype.rotateimage=function(theAction, imageid) 
{
	this.nextcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_0" : this.canvasbase+"_1";
	this.tempobj=iebrowser? iebrowser[this.nextcanvas] : document.getElementById(this.nextcanvas);

    if (theAction==FORWARD)
      this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0;
    else if (theAction==BACKWARD)
      this.curimageindex=(this.curimageindex>0)? this.curimageindex-1 : this.postimages.length-1;
	else if (theAction==RANDOM)
	  this.curimageindex = imageid;

    this.displayImage(this.tempobj, this.curimageindex);

    if (iebrowser&&is_dom||is_dom)
    {
      this.resetit(); // reset opacity to initial value
      var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas);
      crossobj.style.zIndex++;
    
      // begin crossfading pics
  	  timeouts[this.slideshowid]=setInterval("fadepic(instances["+this.slideshowid+"])", TIMESLICE);
      this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0";
    } 
    else 
    {
	  // browser can't fade, just swap pics
      var ns4imgobj=document.images['defaultslide'+this.slideshowid];
      ns4imgobj.src=this.postimages[this.curimageindex].src;
    }
}
 
//--------------------------------------------------
//  reset opacity

fadeshow.prototype.resetit=function()
{
  this.degree=OPACITY_INITIAL;
  var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas);

//  if (crossobj.filters)
//      crossobj.filters.alpha.opacity=this.degree;
  if (crossobj.filters&&crossobj.filters[0])
  {
    if (typeof crossobj.filters[0].opacity=="number") //if IE6+
      crossobj.filters(0).opacity=this.degree;
    else //else if IE5.5-
      crossobj.style.filter="alpha(opacity="+this.degree+")";
  }
  else if (crossobj.style.MozOpacity)
    crossobj.style.MozOpacity=(this.degree-1)/100;
  else if (crossobj.style)
    crossobj.style.opacity=(this.degree-1)/100;
	
};
 
//--------------------------------------------------
fadeshow.prototype.startit=function()
{
  var pausecontainer=iebrowser? iebrowser["pause"] : document.getElementById("pause");
  var fwdcontainer=iebrowser? iebrowser["fwd"] : document.getElementById("fwd");
  var backcontainer=iebrowser? iebrowser["back"] : document.getElementById("back");
  var cacheobj = this;
  var thumbshandle=iebrowser? iebrowser["thumbs"] : document.getElementById("thumbs");

  var cartcontainer=iebrowser? iebrowser["cart"] : document.getElementById("cart");
  var checkoutcontainer=iebrowser? iebrowser["checkout"] : document.getElementById("checkout");
  
  var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas);
  this.displayImage(crossobj, this.curimageindex);
  
  this.rotateimage(NONE);
}