/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 *	Copyright 2007 BOSS Logics, a division of Set Your Site, Inc.				*
 *												*
 *	USE OF THIS CODE IS PROHIBITED WITHOUT EXPRESS WRITTEN PERMISSION.			*
 *												*
 *												*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 

var curCanvas = false;
var widgetManagementURL = '/boss/widgets.php';


var slideshows = Array();
SlideShow.prototype.constructor = SlideShow;
function SlideShow(holder, delay) {
	this.holder = holder;					// div to hold slideshow
	this.delay = delay;					// time between slides, in seconds 

	this.pos = 0;						// cur position
	this.overrideStop = false;
	this.intvl = false;
	this.slides = new Array();				// initiate slide
	this.holder.obj = this;
	slideshows[this.holder.id] = this;
	this.loadDiv = document.createElement('div');
	this.loadDiv.style.display='none';

	// funcitons
	this.initSlides = function() {
		this.slides = new Array();		
	}
	this.addSlide  = function(src) {
		this.slides[this.slides.length] = src;	
	}
	this.nextSlide = function() {
		var src = this.slides[this.pos];
		var ext = src.substring(src.lastIndexOf('.')+1);
		var html = '';
		
		if(this.holder.firstChild && this.holder.firstChild.nodeName.toLowerCase()=='img') {	// set that background to the current image
			this.holder.style.backgroundImage = 'url('+this.holder.firstChild.src+')';
		}
		switch(ext.toLowerCase()) {	// setup holder new content
			case 'flv':
				html = generateEmbedCode('flv', this.slides[this.pos],
							 this.holder.offsetWidth,this.holder.offsetHeight, true, false, { onComplete:'$(\''+this.holder.id+'\').obj.start();' });
				setTimeout('$(\''+this.holder.id+'\').style.backgroundImage="";', 1000);
				this.stop();
				this.holder.innerHTML = html;
				fade_in(this.holder.firstChild, .15);
				break;
			default:
				var src = this.slides[this.pos].replace('.jpg', '.'+this.holder.offsetWidth+'.jpg');
				var img = document.createElement('img');
				html = '<img height="'+this.holder.offsetHeight+'" id="slideImage" src="'+src+'" onload="fade_in(this, .15);" class="transparent" />';
				this.holder.innerHTML = html;
		}
		this.lastType = ext.toLowerCase();
		
		this.pos++;
		if(this.pos >= this.slides.length)	this.pos = 0;

		// preload next
		if(this.slides[this.pos].substring(this.slides[this.pos].lastIndexOf('.')+1).toLowerCase()!='flv') {
			this.nextImg = new Image();
			this.nextImg = this.slides[this.pos].replace('.jpg', '.'+this.holder.offsetWidth+'.jpg');
		}
	}
	this.start = function() {	
		if(!this.slides.length)	return false;
		if(this.overrideStop) {
			this.stop();
		}
		if(this.intvl)	this.intvl.stop();
		this.intvl = window.setInterval('$(\''+this.holder.id+'\').obj.nextSlide();', this.delay*1000); 
		this.nextSlide();		
	}
	this.stop = function() { 	
		if(this.intvl)	clearInterval(this.intvl);					
		this.intvl = false;
	}
}
