function RollingImageAdvertisement(timeOutSecond) {
	this.timeOut = timeOutSecond * 1000;
	this.timeOutId = null;
	this.box = new Array();
	this.banners = new Array();
	this.navigObjs = new Array();
	this.displayed = 0;
	this.hidden = 1;

	this.destNext = null;
	this.destCurrent = null;
	
	this.currIdx = 0;
	
	this.init = function(box1Id, box2Id) {
		this.box[0] = document.getElementById(box1Id);
		this.box[1] = document.getElementById(box2Id);
	};
	
	this.addBanner = function(imgObj, navId) {
		var img = new Image(imgObj.w, imgObj.h);
		img.src = imgObj.src;
		this.banners[this.banners.length] = img;
		this.navigObjs[this.navigObjs.length] = document.getElementById(navId);
	};
	
	
	this.switchBanner = function(idx) {
		if (idx != this.currIdx) {
			clearTimeout(this.timeOutId);
			this.unmarkNavig(this.currIdx);
			this.currIdx = idx;
			this.markNavig(this.currIdx);
			this.box[this.hidden].src = this.banners[idx].src;
			this.switchContext();
			this.hideCurrentBanner();
			this.showNextBanner();
			var self = this;
			this.timeOutId = setTimeout(function(){self.switchNextBanner()}, this.timeOut);
		}
	};
	
	this.switchNextBanner = function() {
		this.unmarkNavig(this.currIdx);
		this.currIdx = (this.currIdx + 1) %  this.banners.length;
		this.markNavig(this.currIdx);
		this.box[this.hidden].src = this.banners[this.currIdx].src;
		this.switchContext();
		this.hideCurrentBanner();
		this.showNextBanner();
		var self = this;
		this.timeOutId = setTimeout(function(){self.switchNextBanner()}, this.timeOut);
	};
	
	this.markNavig = function(id) {
		this.navigObjs[id].style.fontWeight = 'bold';
	}
	
	this.unmarkNavig = function(id) {
		this.navigObjs[id].style.fontWeight = 'normal';
	}
	
	this.roll = function() {
		var self = this;
		this.timeOutId = setTimeout(function(){self.switchNextBanner()}, this.timeOut);
	};
	
	this.switchContext = function () {
		this.destNext = this.box[this.hidden];
		this.destCurrent = this.box[this.displayed];
		if (typeof(this.destNext.filters) == "object") {
			this.destNext.filters.item(0).opacity = 10;
			this.destCurrent.filters.item(0).opacity = 90;
		}
		
		if (typeof(this.destNext.style.MozOpacity) != "undefined") {
			this.destNext.style.MozOpacity = 0.1;
			this.destCurrent.style.MozOpacity = 0.9;
		}
		if (typeof(this.destNext.style.opacity) != "undefined") {
			this.destNext.style.opacity = 0.1;
			this.destCurrent.style.opacity = 0.9;
		}
		this.destNext.style.display = 'inline';
		this.displayed = (this.displayed + 1) % 2;
		this.hidden = (this.hidden + 1) % 2;
	}
	
	this.showNextBanner = function() {
		var dest = this.destNext;
		var self = this;
		if (typeof(dest.filters) == "object" && dest.filters.length > 0) {
			var op = dest.filters.item(0).opacity;
			if (op + 10 < 100) {
				dest.filters.item(0).opacity = op + 10;
				setTimeout(function(){self.showNextBanner()}, 30);
			} else {
				if (op < 100) {
					dest.filters.item(0).opacity = 100;
				}
			}
		}
		if (typeof(dest.style.MozOpacity) != "undefined") {
			var op = parseFloat(dest.style.MozOpacity);
			if (op + 0.1 < 1) {
				dest.style.MozOpacity = op + 0.1;
				setTimeout(function(){self.showNextBanner()}, 30);
			} else {
				if (op < 1) {
					dest.style.MozOpacity = 1;
				}
			}
		} else if (typeof(dest.style.opacity) != "undefined") {
			var op = parseFloat(dest.style.opacity);
			if (op + 0.1 < 1) {
				dest.style.opacity = op + 0.1;
				setTimeout(function(){self.showNextBanner()}, 30);
			} else {
				if (op < 1) {
					dest.style.opacity = 1;
				}
			}
		}	
	};
	
	this.hideCurrentBanner = function() {
		var dest = this.destCurrent;
		var self = this;
		if (typeof(dest.filters) == "object" && dest.filters.length > 0) {
			var op = dest.filters.item(0).opacity;
			if (op - 10 > 0) {
				dest.filters.item(0).opacity = op - 10;
				setTimeout(function(){self.hideCurrentBanner()}, 30);
			} else {
				if (op >= 0) {
					dest.filters.item(0).opacity = 0;
					dest.style.display = 'none';
				}
			}
		}
		if (typeof(dest.style.MozOpacity) != "undefined") {
			var op = parseFloat(dest.style.MozOpacity);
			if (op - 0.1 >= 0.1) {
				dest.style.MozOpacity = op - 0.1;
				setTimeout(function(){self.hideCurrentBanner()}, 30);
			} else {
				if (op >= 0) {
					dest.style.MozOpacity = 0;
					dest.style.display = 'none';
				}
			}
		} else if (typeof(dest.style.opacity) != "undefined") {
			var op = parseFloat(dest.style.opacity);
			if (op - 0.1 >= 0.1) {
				dest.style.opacity = op - 0.1;
				setTimeout(function(){self.hideCurrentBanner()}, 30);
			} else {
				if (op >= 0) {
					dest.style.opacity = 0;
					dest.style.display = 'none';
				}
			}
		}	
	};
}
var ra = new RollingImageAdvertisement(10);

function initReklama() {
	ra.init('reklama1','reklama2');
	ra.addBanner({src: "/_img/web/reklama.jpg", w: 564, h: 162}, "ranav1");
	ra.addBanner({src: "/_img/web/reklama5.jpg", w: 564, h: 162}, "ranav2");
	ra.addBanner({src: "/_img/web/reklama4.jpg", w: 564, h: 162}, "ranav3");
	ra.roll();
	
}

