/***********************************************
* TapsWeb slideshow script
* Copyright 2007-2008 All Rights Reserved TapsWeb, Media, PA at www.tapsweb.com
* Please email us at info@tapsweb.com if you are interested in using this.
***********************************************/
function FP_preloadImgs() {
 var d=document,a=arguments; 
 if(!d.FP_imgs) {
 	d.FP_imgs=new Array();
 }
 for(var i=0; i<a.length; i++) {
 	d.FP_imgs[i]=new Image; 
 	d.FP_imgs[i].src=a[i]; 
 }
}

function FP_swapImg() {
 var doc=document,args=arguments,elm,n; 
 doc.$imgSwaps=new Array(); 
 for(n=2; n<args.length; n+=2) { 
 	elm=FP_getObjectByID(args[n]); 
 	if(elm) { 
 		doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 		elm.$src=elm.src; 
 		elm.src=args[n+1]; 
 	}
 }
}

function FP_getObjectByID(id,o) {
 var c,el,els,f,m,n; 
 if(!o){
 	o=document;
 }
 if(o.getElementById){
 	el=o.getElementById(id);
 }
 else {
 	if(o.layers) {
 		c=o.layers; 
 	}
 	else {
 		if(o.all) {
 			el=o.all[id]; 
 		}
 	}
 }
 if(el) {
 	return el;
 }
 if(o.id==id || o.name==id){
	return o;
 }
 if(o.childNodes){
 	 c=o.childNodes;
 }
 if(c){
 	for(n=0; n<c.length; n++) { 
 		el=FP_getObjectByID(id,c[n]);
 		if(el){
 			return el;
 		}
 	}
 }
 f=o.forms; 
 if(f){
 	for(n=0; n<f.length; n++) { 
 		els=f[n].elements;
 		for(m=0; m<els.length; m++){ 
 			el=FP_getObjectByID(id,els[n]); 
 			if(el){
 			 	return el; 
 			}
 		} 
 	}
 }
 return null;
}



var $flashTimer; 
var $id = 0; 
var $count = 0; 
var $lastColor = "magenta"; 
var globalObject; 
function clearBorders( thisNumber) {
   $name = ""; 
   for (i = 1; i <= thisNumber; i++) {
      $name = 'pic' + i; 
      if ( document.getElementById($name) ) {
         $el = document.getElementById($name); 
         $el.style.border = '0px'; 
         $el.style.padding = '4px'; 
         }
      }
   }
function addBorder( id, thisNumber ) {
   clearBorders( thisNumber ); 
   $name = 'pic' + id; 
   if ( document.getElementById($name) ) {
      $el = document.getElementById($name); 
      if ( $lastColor == "yellow" ) {
         $el.style.border = '4px solid magenta'; 
         $lastColor = "magenta"; 
         }
      else {
         $el.style.border = '4px solid yellow'; 
         $lastColor = "yellow"; 
         }
      $el.style.padding = '0px'; 
      }
   }
function flashBorder() {
   if ( $count > 0 ) {
      $count = 1; 
      $name = 'pic' + $id; 
      if ( document.getElementById($name) ) {
         $el = document.getElementById($name); 
         if ($lastColor == "yellow") {
            $el.style.borderColor = "magenta"; 
            $lastColor = "magenta"; 
            }
         else {
            $el.style.borderColor = "yellow"; 
            $lastColor = "yellow"; 
            }
         }
      }
   else {
      $count = 1; 
      return; 
      }
   }
function slide(src, text, attr) {
   this.src = src; 
   this.attr = attr; 
   if (document.images) {
      this.image = new Image(); 
      }
   this.loaded = false; 
   this.text = text; 
   //--------------------------------------------------
   this.load = function() {
      if (!document.images) {
         return; 
         }
      if (!this.loaded) {
         this.image.src = this.src; 
         this.loaded = true; 
         }
      };
   }
//==================================================
// slideshow object
//==================================================
function slideshow( slideshowname ) {
   this.name = slideshowname; 
   this.repeat = true; 
   this.image; 
   this.timeout = 4000; 
   this.slides = new Array(); 
   this.current = 0; 
   this.timeoutid = 0; 
   $flashTimer = setInterval("flashBorder()", 1500); 
   this.add_slide = function(slide) {
      var i = this.slides.length; 
      slide.load(); 
      this.slides[i] = slide; 
      };
   //--------------------------------------------------
   this.play = function() {
      this.pause(); 
      globalObject = this; 
      this.timeoutid = setTimeout( 'globalObject.loop()', this.timeout); 
      };
   //--------------------------------------------------
   this.pause = function() {
      if (this.timeoutid != 0) {
         clearTimeout(this.timeoutid); 
         this.timeoutid = 0; 
         }
      };
   //--------------------------------------------------
   this.update = function() {
      if (!this.image) {
         return; 
         }
      var slide = this.slides[ this.current ]; 
      var dofilter = false; 
      if (this.image && typeof this.image.filters != 'undefined' && typeof this.image.filters[0] != 'undefined') {
         dofilter = true; 
         }
      slide.load(); 
      if (dofilter) {
         if (slide.filter && this.image.style && this.image.style.filter) {
            this.image.style.filter = slide.filter; 
            }
         this.image.filters[0].Apply(); 
         }
      this.image.src = slide.image.src; 
      if (dofilter) {
         this.image.filters[0].Play(); 
         }
      addBorder( this.current + 1, this.slides.length); 
      $id = this.current + 1; 
      $count = 0; 
      flashBorder(); 
      if ( document.getElementById("slide_text") ) {
         $el = document.getElementById("slide_text"); 
         $el.innerHTML = slide.text; 
         }
      };
   //--------------------------------------------------
   this.goto_slide = function(n) {
      this.pause(); 
      if (n == - 1) {
         n = this.slides.length - 1; 
         }
      if (n < this.slides.length && n >= 0) {
         this.current = n; 
         }
      this.update(); 
      };
   //--------------------------------------------------
   this.next = function() {
      if (this.current < this.slides.length - 1) {
         this.current++; 
         }
      else if (this.repeat) {
         this.current = 0; 
         }
      this.update(); 
      };
   //--------------------------------------------------
   this.save_position = function(cookiename) {
      if (!cookiename) {
         cookiename = this.name + '_slideshow'; 
         }
      document.cookie = cookiename + '=' + this.current; 
      };
   //--------------------------------------------------
   this.restore_position = function(cookiename) {
      //Get cookie code by Shelley Powers
      if (!cookiename) {
         cookiename = this.name + '_slideshow'; 
         }
      var search = cookiename + "="; 
      if (document.cookie.length > 0) {
         offset = document.cookie.indexOf(search); 
         // if cookie exists
         if (offset != - 1) {
            offset += search.length; 
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset); 
            // set index of end of cookie value
            if (end == - 1) {
               end = document.cookie.length;
            } 
            this.current = parseInt(unescape(document.cookie.substring(offset, end)),10); 
            }
         }
      };
   //--------------------------------------------------
   this.loop = function() {
      // Make sure the next slide image has finished loading
      if (this.current < this.slides.length - 1) {
         next_slide = this.slides[this.current + 1]; 
         if (next_slide.image.complete == null || next_slide.image.complete) {
            this.next(); 
            }
         }
      else {
         // we're at the last slide
         this.next(); 
         }
      // Keep playing the slideshow
      this.play( ); 
      }
   };

