/**
 *  author:		Timothy Groves - http://www.brandspankingnew.net
 */

	var useBSNns;
	
	if (useBSNns){
	
		if (typeof(bsn) == "undefined"){
		
			bsn = {}
			var _bsn = bsn;
		
		}
	
	} else {
	
		var _bsn = this;
	
	}
	
	// init slideshow
	
	_bsn.Crossfader = function (divs,thumbs){

		this.nAct		= -1;
		this.aDivs		= divs;
		this.aThumbs	= thumbs;

		for (i=0;i<divs.length;i++){

			document.getElementById(divs[i]).style.opacity		= 0;
			document.getElementById(divs[i]).style.position		= "absolute";
			document.getElementById(divs[i]).style.filter		= "alpha(opacity=0)";
			document.getElementById(divs[i]).style.visibility	= "hidden";

		}
		
		this.nDur		= 600; // transition duration
		this.nDelay		= slideshowdelay; // slide duration
		
		this._newfade();
	
	}
	
	// run slideshow
	
	_bsn.Crossfader.prototype._newfade = function(){
		
		if (this.nID1){ clearInterval(this.nID1); }
		
		this.nOldAct = this.nAct;
		this.nAct++;
		
		if (!this.aDivs[this.nAct]){ this.nAct = 0; }
		
		if (this.nAct == this.nOldAct){ return false; }
		
		document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible";
		
		this.nInt = 50;
		this.nTime = 0;
		
		var p=this;
		
		this.nID2 = setInterval(function() { p._fade() }, this.nInt);

	}
	
	// do a fade from one slide to an other
	
	_bsn.Crossfader.prototype._fade = function(){

		this.nTime += this.nInt;
	
		var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
		var op = ieop / 100;

		document.getElementById( this.aDivs[this.nAct] ).style.opacity	= op;
		document.getElementById( this.aDivs[this.nAct] ).style.filter		= "alpha(opacity="+ieop+")";
		document.getElementById( this.aThumbs[this.nAct] ).src 			= "/images/thumb_s.gif";
		
		if (this.nOldAct > -1){
			
			document.getElementById( this.aDivs[this.nOldAct] ).style.opacity		= 1 - op;
			document.getElementById( this.aDivs[this.nOldAct] ).style.filter		= "alpha(opacity="+(100 - ieop)+")";
			document.getElementById( this.aThumbs[this.nOldAct] ).src 			= "/images/thumb.gif";
		
		}
		
		if (this.nTime == this.nDur){
		
			clearInterval( this.nID2 );
			
			if (this.nOldAct > -1){
				
				document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";	
				
			}
			
			var p=this;
			this.nID1 = setInterval(function() { p._newfade() }, this.nDelay);
	
		}
	
	}
	
	// easing in and out
	
	_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d){
	
		return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
	
	}
	
	// select a thumbnail to show big image (stops the slideshow)
	
	function openThumbnail(thisslide){
		
		stopSlideShow();
	
		for (i=0;i<slides.length;i++){
			
			if (i == thisslide){
				
				document.getElementById(slides[i]).style.opacity		= 1;
				document.getElementById(slides[i]).style.visibility 	= "visible";				
				document.getElementById(slides[i]).style.filter			= "alpha(opacity=100)";
				document.getElementById(thumbs[i]).src		 			= "/images/thumb_s.gif";
				
			} else {
	
				document.getElementById(slides[i]).style.opacity 		= 0;
				document.getElementById(slides[i]).style.visibility 	= "hidden";
				document.getElementById(slides[i]).style.filter 		= "alpha(opacity=0)";
				document.getElementById(thumbs[i]).src		 			= "/images/thumb.gif"
				
			}
		}
	}
	
	// stop the slideshow
	
	function stopSlideShow(){
		
		if (cf){
		
			clearInterval(cf.nID1);
			clearInterval(cf.nID2);
		
		}
	
	}