/**
 * 
 */
myBanner = function(){
	this.bannerCnt = null;
	this.controlls = null;
	this.items = null;
	this.actualItem = 0;
	this.player = null;
	
	this.waitLong = 10000;//ms (30s)
	this.waitNormal = 10000;//ms (10s)
	
	this.initBanner = function() {
		this.bannerCnt = $j("#slider");
		if(this.bannerCnt == null) return;

		this.items = $j(this.bannerCnt).find(".slide");
		if(this.items.length == 0) return;
		$j(this.items).each(function(){
			$j(this).find("img").first().before("<div class=\"over\">&nbsp;</div>");
			$j(this).hide();
		});
		//this.createControlls();
		this.update(this.actualItem);
		this.player = setInterval('ban.ctrl("next")', this.waitNormal);
	};
	
	this.createControlls = function(){
		var dots = "<div id=\"controlls\"><div class=\"arrows\" id=\"prev\">&nbsp;</div><div class=\"slides\">";
		for(var i=0; i < this.items.length; i++) dots += "<span>&nbsp;</span>";
		dots += "</div><div class=\"arrows\" id=\"next\">&nbsp;</div></div>";
		$j(".slides").before(dots);
		
		this.controlls = $j("#controlls");
		if(this.controlls == null) return;
		$j(this.controlls).find(".arrows").each(function(index){
			$j(this).bind("click", function(){
				ban.ctrl(this, true);
			});
		});
	};
	
	this.next = function(){
		this.actualItem++;
		if(this.actualItem >= this.items.length) this.actualItem = 0;
		return this;
	};
	this.previous = function(){
		this.actualItem--;
		if(this.actualItem < 0) this.actualItem = this.items.length-1;
		return this;
	};
	this.ctrl = function(item, posponePlayer){
		var act = "";
		if(item == "next" || item == "prev"){
			act = item;
		}else if(item.id == "next" || item.id == "prev"){
			act = item.id;
		}
		if(act != ""){
			var oldItem = this.actualItem;
			if(act == "next"){
				this.next();
			}else{
				this.previous();
			}
			this.update(oldItem);
			//if(this.player != null) clearTimeout(this.player);
			if(posponePlayer === true){
				//clearInterval(this.player);
				//this.player = setTimeout('ban.ctrl("next")', this.waitLong);
			}else{
				//this.player = setTimeout('ban.ctrl("next")', this.waitNormal);
			}
		}
		return this;
	};
	
	this.update = function(oldId) {
		$j(this.controlls).find("span").each(function(index){
			if(index == ban.actualItem){
				$j(this).addClass("active");
			}else{
				$j(this).removeClass("active");
			}
		});
		this.transpose(oldId);
		return this;
	};
	
	this.transpose = function(oldId){
		if(oldId == this.actualItem){
			$j(this.items[oldId]).fadeIn(500);
		}else{
			$j(this.items[oldId]).fadeOut(500, function(){
				$j(ban.items[ban.actualItem]).fadeIn(500); 
			});
		}
		return this;
	};
};

