/*
--------------------------------------------------------------------
PUBLICIDADE
--------------------------------------------------------------------
*/
var FeaturedProducts = {
	total : Object,
	current : null,
	cont : null,
	timeout : 4000,
	timeOutBanner : null,

	init : function() {
		//VARIAVEIS	
		currentBanner = 0;
		totalBanner = $("ul.slide-goto li").length; //returns total amount li
		btnNext = $("li.btn-next"); //caminho do botão próximo
		btnPrev = $("li.btn-previous"); //caminho do botão anterior
		//MONTA NAVEGAÇÃO BULLETS
		$("ul.slide-goto").empty();
		for (cont=0; cont <= totalBanner-1; cont++) {
			$("ul.slide-goto").append('<li><a href="#" target="'+cont+'">'+(cont+1)+'</a></li>').find("a").click(this.bulletBanner);
		}
		//CONFIGURACAO INICIAL
		$("div#featured-products-content").children("div.featured-product:not(:first)").hide();
		$("div#featured-products-content").children("div.featured-product:first").show();
		$("div#featured-products-content").children("div.featured-product:first").addClass("current");
		$(btnPrev).addClass("disabled");
		$("ul.slide-goto li:first").addClass("current");
		//EVENTS
		$(btnNext).bind("click", this.nextBanner);
		$(btnPrev).bind("click", this.prevBanner);
		timeOutBanner = setTimeout("FeaturedProducts.slideShow()", this.timeout);
		$("div#featured-products-content").hover(function(){ //mouse over
			if(timeOutBanner) {clearTimeout(timeOutBanner);}
		},function(){ //mouse out
			timeOutBanner = setTimeout("FeaturedProducts.slideShow()", FeaturedProducts.timeout/2);
		});
	},
	goToBanner : function(posicaoBanner) {
		//reseta banners
		$("div#featured-products-content").children("div.current").removeClass("current").hide();
		//reseta bullets
		$("ul.slide-goto li.current").removeClass("current");
		//ativa banner
		$("div#featured-products-content").children("div").eq(posicaoBanner).fadeIn("slow").addClass("current");
		//ativa bullet
		$("ul.slide-goto li").eq(posicaoBanner).addClass("current");
		//verifica se é ou não o último banner e adiciona/retira classe
		if (posicaoBanner == totalBanner-1) {
			$(btnNext).addClass("disabled");
		} else {
			$(btnNext).removeClass("disabled");
		}
		//verifica se é ou não o primeiro banner e adiciona/retira classe
		if (posicaoBanner === 0) {
			$(btnPrev).addClass("disabled");
		} else {
			$(btnPrev).removeClass("disabled");
		}
	},
	nextBanner : function() {
		if(currentBanner < totalBanner-1) {
			currentBanner++;
			FeaturedProducts.goToBanner(currentBanner);
		}
		if(timeOutBanner) {clearTimeout(timeOutBanner);}
		return false;
	},
	prevBanner : function() {
		if(currentBanner > 0) {
			currentBanner--;
			FeaturedProducts.goToBanner(currentBanner);
		}
		if(timeOutBanner) {clearTimeout(timeOutBanner);}
		return false;
	},
	bulletBanner : function() {
		//currentBanner = parseInt($(this).attr("href").slice(1), 10);
		//currentBanner = $(this).attr("href").slice(1);
		//alert($(this).attr("href"));
		currentBanner = parseInt($(this).attr("target"), 10);
		FeaturedProducts.goToBanner(currentBanner);
		if(timeOutBanner) {clearTimeout(timeOutBanner);}
		return false;
	},
	slideShow :	function() {
		if(currentBanner < totalBanner-1) {
			currentBanner++;
		} else {
			currentBanner = 0;
		}
		FeaturedProducts.goToBanner(currentBanner);	
		timeOutBanner = setTimeout("FeaturedProducts.slideShow()", this.timeout);
	}
};


$(document).ready(function() {
  	FeaturedProducts.init();


	//POPULATE INPUTS
	$('.populateInput').each(function(){
		var e = $(this);
		if (e.attr('title').length =! e.val().length) {
			e.val(e.attr('title'));
		}
		if (e.attr('title') == e.val()) {
			e.addClass('inputLabel');
		}
		e.focus(function(){
			var e = $(this);
			if (e.attr('title') == e.val()) {
				e.val('').removeClass('inputLabel');
			}
		}).blur(function(){
			var e = $(this);
			if (e.attr('title').length =! e.val().length) {
				e.val(e.attr('title')).addClass('inputLabel');
			}
    	});
		$('label[@for='+$(this).attr('id')+']').addClass('hidden');
	});
}); //end jquery
