// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully


function insertAfter(newElement,targetElement) {
	var parent = targetElement.parentNode;
	if ( parent.lastChild == targetElement ) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}
function SlideShow(imagelist,id) {
	this.imagelist = imagelist;
	this.id = id;
	this.crossFadeDuration = 2;
	this.slideShowSpeed = 2700;
	this.slidePlaying = true;
	this.imagenum = 0;
	if ( document.getElementById(this.id) ) {
		this.addPausePlayControl(this.playPause);
		//addEventToId(this.id,'click',playpause);
		this.loadImages();
		this.run();
	/*
	*/
	}
}
SSP = SlideShow.prototype;
SSP.loadImages = function() {
	var Pics = this.imagelist.split(",");
	var i = 0;
	var preLoad = new Array()

	for (i = 0; i < Pics.length; i++){
		preLoad[i] = new Image()
		preLoad[i].src = Pics[i]
	}
	
	this.images = preLoad;
	
}
SSP.addPausePlayControl = function(ppfunc) {
	var para = document.createElement("p");
	var lnk = document.createElement("a");
	var txt = document.createTextNode("pause");
	var myself = this;
	
	lnk.appendChild(txt);
	lnk.setAttribute("href","#");
	para.appendChild(lnk);
	para.setAttribute("id",this.id + 'PlayPause');
	
	//addEvent(para,"click",this.playPause);
	para.style.marginTop = 0;
	insertAfter(para,document.getElementById(this.id));
	
	document.getElementById(this.id).onclick = function() {
		ppfunc(myself);
	}
	document.getElementById(this.id + 'PlayPause').onclick = function() {
		ppfunc(myself);
	}
	
}
SSP.playPause = function(obj) {
	var controltext = "";
	
	if ( obj.slidePlaying ) {
		obj.slidePlaying = false;
		controltext = "play";
	} else {
		obj.slidePlaying = true;
		controltext = "pause";
		obj.run();
	}
	if ( document.getElementById(obj.id + 'PlayPause') ) {
		document.getElementById(obj.id + 'PlayPause').getElementsByTagName("a")[0].innerHTML = controltext;
	}
}
SSP.run = function() {
	var myself = this;
	if ( this.slidePlaying ) {
		
		if (document.all){
			document.images[this.id].style.filter="blendTrans(duration=crossFadeDuration)"
			document.images[this.id].filters.blendTrans.Apply();
		}
		document.images[this.id].src = this.images[this.imagenum].src
		if (document.all){
			document.images[this.id].filters.blendTrans.Play();
		}
		
		this.imagenum = this.imagenum + 1;
		if (this.imagenum >= this.images.length) {
			this.imagenum = 0;
		}
		SlideShowRun = function() {
			myself.run();
		}
		
		t = setTimeout(SlideShowRun, this.slideShowSpeed);
	}
}



if (typeof images != 'undefined' && images != '' ) {
	function slider(){
		ss = new SlideShow(images,'SlideShow')
	}
	addEvent(window,'load',slider);
}