var animateBanner = function(obj, ctrl){
	this.timeInterval = 4000;
	this.obj = obj;
	this.ctrl = ctrl;
	this.objchilds = null;
	this.present = null;
	this.presentID = 0;
	this.animation = null;
	this.removeInvalidChilds = function(parent){
		var childs = parent.childNodes;
		for(var i=0;i<childs.length;i++){if(childs[i].nodeType == 3){parent.removeChild(childs[i]);}}
		return childs;
	}
	this.nextSlide = function(ns){
		this.present.fadeOut();
		jQuery("#"+this.present.attr("rel")).removeClass("active");
		if(ns){this.present = ns;}
		else{
			this.presentID++;
			if(this.presentID >= this.objchilds.length){this.presentID = 0;}
			this.present = jQuery(this.objchilds[this.presentID]);
			/*this.presentID++;
			if(!!this.objchilds[this.presentID]){this.present = jQuery(this.objchilds[this.presentID]);}
			else{this.present = jQuery(this.objchilds[0]);this.presentID = 0;}*/
		}
		jQuery("#"+this.present.attr("rel")).addClass("active");
		this.present.fadeIn();
	}
	this.play = function(){
		var _this = this;
		_this.stop();
		_this.animation = setInterval(function(){
			_this.nextSlide();
		},_this.timeInterval);
	}
	this.jump = function(np){
		if(np.attr("id") == this.present.attr("id")){return false;}
		this.stop();
		this.nextSlide(np);
	}
	this.stop = function(){
		if(this.animation){clearInterval(this.animation);}
	}
	this.start = function(){
		var childs = this.removeInvalidChilds(this.obj);
		this.objchilds = childs;
		//esconde lis, exceto a primeira
		for(var i=0;i<childs.length;i++){
			childs[i].setAttribute("id", "banner_"+i);
			childs[i].setAttribute('rel', 'controles_'+i);
			if(i>0){childs[i].style.display='none';}
		}
		this.present = jQuery(this.objchilds[0]);
		this.presentID = 0;
		this.observCtrl();
		this.play();
	}
	this.observCtrl = function(){
		var _this = this;
		var ctrls = this.removeInvalidChilds(this.ctrl);
		for(var i=0;i<ctrls.length;i++){
			ctrls[i].setAttribute('id', 'controles_'+i);
			ctrls[i].setAttribute('rel', 'banner_'+i);
			ctrls[i].onclick = function(){
				_this.jump(jQuery('#'+this.getAttribute("rel")));
				return false;
			}
		}
		jQuery(ctrls[0]).addClass("active");
	}
	this.start();
};
var animateBannerHome = true;
