function Slideshow (_bi) {
	var ref = this;
	//this.ti = SJEL.$(_ti); SJEL.SStyle(this.ti, {overflow: "hidden"});
	this.bi = SJEL.$(_bi);
	this.loading = SJEL.CE("img");
	this.loading.src = "/publisher/js/Fxs/Gallery2/imgs/loader.gif";
	this.loading.className = "loading";
	this.slsOn = true;  // slideshow on
	this.slSpeed = 9600;  // slideshow speed
	this.fadeSpeed = 460;
	this.slId = 0;
	this.thmbs = new Array();
	this.mo = new SJEL.Morph();

	this.OnSlTimer = function () {
		ref.ShowBigImage(++ref.slId);
	};

	this.tsl = new SJEL.Timer(this.OnSlTimer);
	this.tsl.SetSpeed(this.slSpeed);

	this.ShowBigImage = function (_id) {
		var id = _id;
		if (id == this.thmbs.length)
			id = 0;
		this.slId = id;

		var thmb = this.thmbs[id];
//	alert('ddd');
//		alert(thmb);
		if (thmb.bimg.src != "")
			this.FadeBigImage(thmb);
		else
			thmb.LoadBigImage();
	};
	
	this.FadeBigImage = function (_thmb) {
		this.bi.innerHTML = "";
		if (_thmb.tl)
			this.bi.href = _thmb.tl;
		SJEL.SStyle(_thmb.bimg, {opacity: 0.0});
		this.bi.appendChild(_thmb.bimg);
		this.mo.Init(_thmb.bimg, {opacity: 1.0}, this.fadeSpeed);
		this.mo.Morph();
	};

	/**
	 * _th - thumb element
	 * _l - link (on big image)
	 * _id - id in this.thmbs array 
	 */ 
	this.Thumb = function (_l, _s, _i) {
		this.tl = _l;  // link
		this.bis = _s;  // big image src
		this.id = _i;
		this.bimg = SJEL.CE("img");// SJEL.SStyle(this.bimg, {opacity: 1.0});
		this.bimg.r = this;

		this.bimg.onload = function() {
			ref.ShowBigImage(this.r.id);
		};
			
		this.LoadBigImage = function () {
			ref.bi.innerHTML = "";
			ref.bi.appendChild(ref.loading);
			this.bimg.src = this.bis;
		};
	};

	this.OnSlTimer = function () {
		ref.ShowBigImage(++ref.slId);
	};
	
	this.AddImage = function (_l, _s) {
		this.thmbs.push(new this.Thumb(_l, _s, this.thmbs.length));
	};
	
	this.Start = function () {
		if (this.thmbs.length > 1)
			this.tsl.Start(true);
	};
};
