/*
	$Id: script.js,v 1.2 2005/07/16 18:54:16 morgan_ross Exp $
*/

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


// IMAGE GALLERY

function showPic (whichpic, placeholder) {
 if (document.getElementById) {
  document.getElementById(placeholder).src = whichpic.href;
  return false;
 } else {
  return true;
 }
}

// POP-UP LINK

var defaultOptions = 'location=0,statusbar=0,menubar=0,width=400,height=300';

function raw_popup(url, target, features) {
  if (isUndefined(features)) { features = defaultOptions; }
  if (isUndefined(target)) { target = '_blank'; }
  var theWindow = window.open(url, target, features);
  theWindow.focus();
  return theWindow;
}

function link_popup(src, features) {
  return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}


// SLIDESHOW

function slide(src) {
  this.src = src;
  // this.timeout = 3000

  if (document.images) {
    this.image = new Image();
  }

  this.loaded = false;
  this.load = function() {
    if (!document.images) { return; }
    if (!this.loaded) {
      this.image.src = this.src;
      this.loaded = true;
    }
  }
  
  this.load = function() {
    if (!document.images) { return; }

    if (!this.loaded) {
      this.image.src = this.src;
      this.loaded = true;
    }
  }
}

function outOf(c){
	document.ss_form.counter.value = (c + 1) + " of " + i;
}

function slideshow(slideshowname) {
  this.name = slideshowname;
  this.repeat = true;
  // -1 = preload all images
  //  0 = load each image is it is used
  //  n = pre-fetch n images ahead of the current image
  this.prefetch = -1;
  this.image;
  this.timeout = 3000;
  this.slides = new Array();
  this.current = 0;
  this.timeoutid = 0;

  this.add_slide = function(slide) {
    var i = this.slides.length;
    if (this.prefetch == -1) {
      slide.load();
    }

    this.slides[i] = slide;
  }

  this.play = function(timeout) {
    this.pause();
    if (timeout) {
      this.timeout = timeout;
    }
    if (typeof this.slides[ this.current ].timeout != 'undefined') {
      timeout = this.slides[ this.current ].timeout;
    } else {
      timeout = this.timeout;
    }
	outOf(this.current);
    this.timeoutid = setTimeout( this.name + ".loop()", timeout);
  }


  this.pause = function() {
    if (this.timeoutid != 0) {
      clearTimeout(this.timeoutid);
      this.timeoutid = 0;
    }
  }


  this.update = function() {
   
    if (! this.valid_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();
    }

    if (this.prefetch > 0) {
      var next, prev, count;
      next = this.current;
      prev = this.current;
      count = 0;
	  
      do {
        if (++next >= this.slides.length) next = 0;
        if (--prev < 0) prev = this.slides.length - 1;
        this.slides[next].load();
        this.slides[prev].load();


      } while (++count < this.prefetch);
    }
  }


  this.next = function() {
    if (this.current < this.slides.length - 1) {
      this.current++;
    } else if (this.repeat) {
      this.current = 0;
    }

    this.update();
	outOf(this.current);
  }


  this.previous = function() {
    if (this.current > 0) {
      this.current--;
    } else if (this.repeat) {
      this.current = this.slides.length - 1;
    }
  
    this.update();
	outOf(this.current);
	
  }


  this.loop = function() {
    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 { // last slide
      this.next();
    }

    this.play( );
  }



  this.valid_image = function() {
    // Returns 1 if a valid image has been set for the slideshow
  
    if (!this.image)
    {
      return false;
    }
    else {
      return true;
    }
  }


  this.getElementById = function(element_id) {
    // This method returns the element corresponding to the id

    if (document.getElementById) {
      return document.getElementById(element_id);
    }
    else if (document.all) {
      return document.all[element_id];
    }
    else if (document.layers) {
      return document.layers[element_id];
    } else {
      return undefined;
    }
  }
}


// MISC
function isUndefined(a) { return typeof a == 'undefined' }

 function change(id, newClass) {
	 if (document.getElementById) {
 var identity=document.getElementById(id);
	identity.className=newClass;
 	} 
	}