function ImgRot(_bi, _aw, _cl) {
	var ref = this;
	this.bi = SJEL.$(_bi);
	this.loader = SJEL.CE("img");
	this.loader.src = "/images/loading.gif";
	this.loader.className = "loading";
	this.slSpeed = 8000;  // slideshow speed
	this.fadeSpeed = 460;
	this.slId = 0;
	this.thmbs = new Array();
	this.mo = new SJEL.Morph();
	this.thOnClass = "thumb_on";
	this.as = SJEL.$A(_aw, "class", _cl);
	this.prev = -1;

	this.OnSlTimer = function () {
		ref.ShowBigImage(++ref.slId);
	}

	this.tsl = new SJEL.Timer(this.OnSlTimer);
	this.tsl.SetSpeed(this.slSpeed);

	for (var i = 0; i < this.as.length; i++) {
		this.as[i].i = i;
		this.as[i].onclick = function() {
			ref.ShowBigImage(this.i, this.i);
			ref.Stop();
		}
		this.as[i].onmouseover = function() {
			ref.ThumbOn(this.i);
		}
		this.as[i].onmouseout = function() {
			ref.ThumbOff(this.i);
		}
	}
	
	this.ThumbOn = function(_i) {
		//if (!SJEL.ClassExists(this.as[_i], this.thOnClass))
			SJEL.AddClass(this.as[_i], this.thOnClass);
	}

	this.ThumbOff = function(_i) {
		/*SJEL.SStyle(this.as[_i], {opacity: 1.0});*/
		SJEL.RemoveClass(this.as[_i], this.thOnClass);
	}
	
	//this.ThumbOn(this.slId);
	
	this.ShowBigImage = function (_id, _click) {
		var id = _id, prevId = 0, tLen = this.thmbs.length, click = (_click == undefined) ? -1 : _click;
		if (id == tLen)
			id = 0;
			
		this.slId = id;
		
		if (click == -1) {
			for (var i = 0; i < tLen; i++)
				this.ThumbOff(i);
		} else {
			//this.ThumbOn(click);
			for (var i = 0; i < tLen; i++)
				if (i != click)
					this.ThumbOff(i);
		}

		/*if (click == -1)
			this.ThumbOn(this.slId);*/
			
		var thmb = this.thmbs[id];
		//alert(thmb.bimg.src);
		if (thmb.bimg.src != "")
			this.FadeBigImage(thmb);
		else
			thmb.LoadBigImage();
	}
	
	this.FadeBigImage = function (_thmb) {
		this.bi.innerHTML = "";
		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();
	}

	this.Thumb = function (_l, _s, _i) {
		this.tl = _l;  // link
		this.bis = _s;  // big image src
		this.id = _i;
		this.bimg = SJEL.CE("img");
		this.bimg.r = this;

		this.bimg.onload = function() {
//			alert(this.r.id);
			ref.FadeBigImage(ref.thmbs[this.r.id]);
			/*if (ref.tsl.IsRunning())
				ref.ShowBigImage(this.r.id);*/
		}
			
		this.LoadBigImage = function () {
			ref.bi.innerHTML = "";
			ref.bi.appendChild(ref.loader);
			this.bimg.src = this.bis;
		}
	}

	this.AddImg = 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);
	}
	
	this.Stop = function() {
		this.tsl.Stop();
	}
}
