Slideshow = function (param) {
	this.settings = param;
	this.elementId = this.settings.elementId || "";
	this.width = this.settings.width;
	this.height = this.settings.height;
	this.backgroundColor = this.settings.backgroundColor || "";
	this.textBackgroundColor = this.settings.textBackgroundColor || "#111111";
	this.textColor = this.settings.textColor || "#FFFFFF";
	this.textSize = (this.settings.textSize || "13")+"px";
	this.border = this.settings.border || "0px solid black";
	this.slides = this.settings.slides;
	this.loading = this.settings.loading || "loading.gif";
	this.link = "";
	this.linkLocation = "_self";
	this.interval = this.settings.interval?this.settings.interval*1000:2500;
	this.currentSlide = this.settings.currentSlide?this.settings.currentSlide-1:0;
	this.pausable = this.settings.pausable || false;
	this.cycles = this.settings.cycles || Infinity;
	this.textType = this.settings.textType || "none";
	this.textHeight = this.settings.textHeight || 20;
	this.delayStart = this.settings.delayStart?this.settings.delayStart*1000:10;
	this.paused = this.settings.paused || false;
	this.animControler = 0;
	this.animCoef = 1;
	this.autoplay = true;
	delete this.settings;
	this.loadedPics = 0;
	this.pics = [];
	this.pendingSlide = "";
}
Slideshow.prototype = {
	init : function () {var this_ref = this;
		if (window.addEventListener) window.addEventListener('load',function() {this_ref.createTags();},false);
		else if (document.addEventListener) document.addEventListener('load',function() {this_ref.createTags();},false);
		else if (window.attachEvent) window.attachEvent('onload',function() {this_ref.createTags();});
		else if (typeof window.onload=='function') {
				var oldload = window.onload;
				window.onload = function() {
					oldload();
					this_ref.createTags();
				}
			}
			else window.onload = function() {this_ref.createTags();};
	},
	createTags : function () {var this_ref=this;
		this.container = document.getElementById(this.elementId);
		this.container.style.width = this.width+"px";
		this.container.style.height = this.height+"px";
		this.container.style.color = this.textColor;
		this.container.style.margin = "auto auto "+(this.textType == "none"?"auto":this.textHeight+"px");
		this.container.style.fontSize = this.textSize;
		this.container.style.fontFamily = '"Trebuchet MS", "Lucida Grande", Arial, Helvetica, sans-serif';
		this.container.style.textAlign = "center";
		this.container.style.border = this.border;
		if (this.backgroundColor) this.container.style.background = this.backgroundColor;
		this.back = document.createElement('div');
		this.back.style.width = this.width+"px";
		this.back.style.height = this.height+"px";
		this.back.style.zIndex = "-1";
		this.container.appendChild(this.back);
		this.front = document.createElement('img');
		this.front.src = this.loading;
		this.front.style.zIndex = "0";
		this.back.appendChild(this.front);
		this.text = document.createElement('div');
		this.text.style.overflow = "hidden";
		this.text.style.background = this.textBackgroundColor;
		this.text.innerHTML = "0 %";
		this.container.appendChild(this.text);
		this.cachePics();
	},
	cachePics : function () {var this_ref = this;
		for (var i=0;i<this.slides.length;i++) {
			this.pics[i] = new Image();
			this.pics[i].onload = function () {
				this_ref.loadedPics++;
				this_ref.text.innerHTML = parseInt((this_ref.loadedPics/this_ref.slides.length)*100,10)+" %";
				if (this_ref.loadedPics == this_ref.slides.length) this_ref.start();
			}
			this.pics[i].src = this.slides[i][0];
		}
	},
	start : function() {var this_ref = this;
		if (this.pausable) {
			this.container.onmouseover = function () {
				this_ref.paused = true;
				clearTimeout(this_ref.pendingSlide);
			};
			this.container.onmouseout = function () {
				this_ref.paused = false;
				clearTimeout(this_ref.pendingSlide);
				this_ref.pendingSlide = setTimeout(function() {
					if (this_ref.textType == "pop") {
						this_ref.text.style.height = this_ref.textHeight+"px";
						this_ref.animateText(-0.2*this_ref.textHeight);
					}
					this_ref.setLink();
					this_ref.animateSlide();
				},this_ref.interval*0.5);
			};
		}
		this.container.onclick = function () {
			if (this_ref.link) {
				window.open(this_ref.link,this_ref.linkLocation);
				if (this_ref.pausable) this_ref.container.onmouseout();
			}
		};
		if (this.textType == "none") {
			this.text.parentNode.removeChild(this.text);
		}
		else {
			this.text.style.height = (this.textType == "pop"?0:this.textHeight)+"px";
			this.text.innerHTML = "";
		}
		setTimeout(function() {
			this_ref.front.style.width = this_ref.width+"px";
			this_ref.front.style.height = this_ref.height+"px";
			this_ref.front.src = this_ref.pics[this_ref.currentSlide].src;
			this_ref.setLink();
			this_ref.animateSlide();
		},this.delayStart);
	},
	animateText : function (modifier) {
		var this_ref = this;
		var currentHeight = this.text.offsetHeight;
		if (modifier>0 && currentHeight<this.textHeight) {
			this.text.style.height = ((currentHeight+modifier)<this.textHeight?(currentHeight+modifier):this.textHeight)+"px";
			setTimeout(function() {this_ref.animateText(modifier);},45);
		}
		else if (modifier<0 && currentHeight>0) {
			this.text.style.height = ((currentHeight+modifier)>0?(currentHeight+modifier):0)+"px";
			setTimeout(function() {this_ref.animateText(modifier);},45);
		}
	},
	animateSlide : function () {
		var this_ref = this;
		if (this.animControler<10) {
			this.animControler+=this.animCoef;
			this.setOpacity(this.front,this.animControler);
			setTimeout(function() {this_ref.animateSlide();},45);
		}
		else if (this.autoplay) {
			if (this.textType != "none" && this.slides[this.currentSlide][2]) this.text.innerHTML = this.slides[this.currentSlide][2];
			if (this.textType == "pop") {
				this.text.style.height = 0;
				this.animateText(0.2*this_ref.textHeight);
			}
			this.setNextSlide();
		}
	},
	setNextSlide : function () {
		var this_ref = this;
		this.back.style.backgroundImage="url("+this.pics[this.currentSlide].src+")";
		this.setOpacity(this.front,0);
		this.animControler = 0;
		this.changeCurrentSlide();
		this.front.src = this.pics[this.currentSlide].src;
		if (this.paused === false) {
			clearTimeout(this_ref.pendingSlide);
			this.pendingSlide = setTimeout(function() {
				if (this_ref.textType == "pop") {
					this_ref.text.style.height = this_ref.textHeight;
					this_ref.animateText(-0.2*this_ref.textHeight);
				}
				this_ref.setLink();
				this_ref.animateSlide();
			},this.interval);
		}
	},
	changeCurrentSlide : function () {
		this.currentSlide+=1;
		if (this.currentSlide == this.slides.length-1) this.cycles>1?this.cycles--:this.autoplay=false;
		if (this.currentSlide > this.slides.length-1) this.currentSlide = 0;
	},
	setLink : function () {
		if (this.slides[this.currentSlide][1]) {
			this.link = this.slides[this.currentSlide][1];
			this.linkLocation = this.slides[this.currentSlide][3] || "_self";
			this.container.style.cursor = "pointer";
		} else {
			this.link = "";
			this.container.style.cursor = "auto";
		}
	},
	setOpacity : function (object,value) {
		if (value <= 0) value = 0.1;
		if (value >=10) value = 9.9;
		object.style.opacity = value/10;// Safari 1.2, newer Firefox and Mozilla, CSS3
		object.style.filter = 'alpha(opacity=' + (value*10) + ')';// IE/Win
	}
}
