function placeholder(quem, label){
	$(quem).focus(function(){
		if($(this).val() == label){
			$(this).val('');
		}
	});
	$(quem).blur(function(){
		if($(this).val() == ''){
			$(this).val(label);
		}
	});
}

function icone_search(){
	$('.search label input').focus(function(){
		$('.search label span, .search label input').stop().animate();
		$('.search label span').animate({
			left: -40 + 'px'							
		}, 500);
		$(this).animate({
			paddingLeft: 15 + 'px',
			width: 339 + 'px'
		}, 500);
	});
	$('.search label input').blur(function(){
		$('.search label span, .search label input').stop().animate();
		$('.search label span').animate({
			left: 10 + 'px'							
		}, 500);
		$(this).animate({
			paddingLeft: 60 + 'px',
			width: 294 + 'px'
		}, 500);
	});
}


function aberturaDestaques(){
	$('.produtosDestaque > li').css('top', -208 + 'px');
	if($.browser.msie != true){
		$('.produtosDestaque > li a strong').css('opacity', 0);
	}
	$('.produtosDestaque > li:eq(0)').animate({
		top: 0							
	}, 900, function(){
		if($.browser.msie != true){
			$(this).children('a').children('strong').animate({
				opacity: 1											 
			}, 300);
		}
	});
	setTimeout(function(){
		$('.produtosDestaque > li:eq(1)').animate({
			top: 0							
		}, 900, function(){
			if($.browser.msie != true){
				$(this).children('a').children('strong').animate({
					opacity: 1											 
				}, 300);
			}
		});
	}, 400);
	
	setTimeout(function(){
		$('.produtosDestaque > li:eq(2)').animate({
			top: 0							
		}, 900, function(){
			if($.browser.msie != true){
				$(this).children('a').children('strong').animate({
					opacity: 1											 
				}, 300);
			}
		});
	}, 800);
	
	$('.produtosDestaque > li a').mouseover(function(){
		$(this).children('img').stop().animate();
		$(this).children('img').animate({
			top: -10 + 'px'						
		}, 300);
	});
	$('.produtosDestaque > li a').mouseout(function(){
		$(this).children('img').stop().animate();
		$(this).children('img').animate({
			top: 0						
		}, {duration: 500, easing:'easeOutBounce'});									   
	});
}

function fakeSelect(){
	$('#hgroup > h5').click(function(){
		if($(this).next('.selectFake').css('display') == 'none'){
			$(this).next('.selectFake').slideDown();				
		}else{
			$(this).next('.selectFake').slideUp();
		}
		$(document).mousedown(function(){
			$('#hgroup > h5').next('.selectFake').slideUp();					   
		});
	});
}
function redes(){
	$('.redes li a').mouseover(function(){
		$(this).stop().animate();
		$(this).animate({
			width: 60 + 'px'			
		}, 500);
	});
	$('.redes li a').mouseout(function(){
		$(this).stop().animate();
		$(this).animate({
			width: 0 + 'px'			
		}, 300);
	});
}
anchor = {
	init : function() {
		$(".topo").click(function () {
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 700 );
			return false;
		});
	}
}

function bannerPrincipal(){
	$('.banner #content').cycle({
		fx: 'scrollLeft', 
		speed: 700,
		timeout: 5000,
		pager: '.banner #nav-banner',
		activePagerClass:'active',
		pagerAnchorBuilder: pagerFactory			
	});	
	function pagerFactory(idx, slide) {
		return '<li><a href="#" title="' + (idx+1) + '">' + (idx+1) + '</a></li>';
	};
	$('.banner > .frente').click(function(){
		var indice = $('.activeSlide').parent().prevAll().size();
		if(indice == $('#nav-banner li').size() - 1){
			indice = -1;
		}
		$('.banner #content').cycle(indice + 1);
	});
	$('.banner > .volta').click(function(){
		var indice = $('.activeSlide').parent().prevAll().size();
		if(indice == 0){
			indice = $('#nav-banner li').size();
		}
		$('.banner #content').cycle(indice - 1);
	});
}
function menuInterna(){
    var position = $('.menu-interna ul li.active').position();
    if (position) {
        var posInicial = position.left + $('.menu-interna ul li.active').width() / 2 - $('.menu-interna > span').width() / 2;
        $('.menu-interna > span').css('left', posInicial);

        $('.menu-interna ul li').mouseover(function() {
            $('.menu-interna > span').stop().animate();
            var posTemp = $(this).position();
            var distancia = posTemp.left + $(this).width() / 2 - $('.menu-interna > span').width() / 2;
            $('.menu-interna > span').animate({
                left: distancia
            }, 500);
        });
        $('.menu-interna ul li').mouseout(function() {
            $('.menu-interna > span').stop().animate();
            $('.menu-interna > span').animate({
                left: posInicial
            }, 500);
        });
    }
}

var contador = Math.ceil($('#nav-imagens ul li').size() / 3);
var atual = 0;
function estado(quem, display){
	$(quem).css('display', display);
}
function paginaImg(){
	if(contador == 1){
		estado('#nav-imagens .setas', 'none');
	}else if(atual == 0){
		estado('#nav-imagens .volta', 'none');
		estado('#nav-imagens .frente', 'block');
	}else if(atual == contador - 1){
		estado('#nav-imagens .frente', 'none');
		estado('#nav-imagens .volta', 'block');
	}else{
		estado('#nav-imagens .setas', 'block');
	}
}
function imagemAtual(){
	if($('#nav-imagens ul li:eq(0)').hasClass('active')){
		atual = 0;
		paginaImg();
		$('#nav-imagens ul').animate({
			left: 0			 
		});					   
	}else if($('#nav-imagens ul li:eq(' + (3 * (atual + 1)) + ')').hasClass('active')){
		atual += 1;
		paginaImg();
		$('#nav-imagens ul').animate({
			left: -219 * atual			 
		});	
	}
	
}
function paginacao(){
	$('#nav-imagens ul li').removeClass('active');
	$('#nav-imagens ul li:eq('+ $(this).index() +')').addClass('active');
}

function animaImg(valor){
	$('#nav-imagens ul').animate({
		left: valor	* atual				 
	});
}
function initImagens(){
	$('#nav-imagens > .frente').click(function(){
		atual += 1;
		paginaImg();
		animaImg(-219);
	});
	$('#nav-imagens > .volta').click(function(){
		atual -= 1;
		paginaImg();
		animaImg(-219);
	});
}
	
function imagensDetalhe(){
	$('#imagem').cycle('stop');
	$('#imagem').cycle({
		fx: 'fade', 
		delay: 5000,
		//pager: '#nav-imagens ul',
		after: imagemAtual,
		before: paginacao
		//activePagerClass:'active'
		//pagerAnchorBuilder: paginaBanner			
	});	
	
	$('#nav-imagens ul li').removeClass('active');
	$('#nav-imagens ul li:eq(0)').addClass('active');
	$('#nav-imagens ul').width($('#nav-imagens ul li').size() * 73);
	$('#nav-imagens ul').css('left', 0);
	contador = Math.ceil($('#nav-imagens ul li').size() / 3);
	atual = 0;
	paginaImg();
	$('#nav-imagens ul > li').click(function() {
		$('#imagem').cycle($(this).prevAll().size());
	});
	if($('#nav-imagens ul li').size() == 1){
		$('#nav-imagens').css('display', 'none');
	}
}

function bt_enviar(){
	$('.form .bt').mouseover(function(){
		$('.form .bt span').stop().animate();								
		$('.form .bt span').animate({
			right: 7 + 'px'		
		}, 300);
	});
	$('.form .bt').mouseout(function(){
		$('.form .bt span').stop().animate();
		$('.form .bt span').animate({
			right: 15 + 'px'		
		}, 300);
	});
}
function bt_voltar(){
	$('.button.voltar').mouseover(function(){
		$('.button.voltar span').stop().animate();								
		$('.button.voltar span').animate({
			left: 7 + 'px'		
		}, 300);
	});
	$('.button.voltar').mouseout(function(){
		$('.button.voltar span').stop().animate();
		$('.button.voltar span').animate({
			left: 17 + 'px'		
		}, 300);
	});
}
function pagina(){
	var width = $('.paginacao ul').width();
	$('.paginacao ul').css('display', 'block');
	$('.paginacao ul').css('width', width + 'px');
}

function categorias(){
	$('.banners-homeInterna li').css('opacity', 0.5);
	$('.banners-homeInterna li').mouseover(function(){
		$('.banners-homeInterna li').stop().animate();
		$('.banners-homeInterna li').animate({
			opacity: 0.5													
		}, 500);
		$(this).stop().animate();
		$(this).animate({
			opacity: 1													
		}, 500);
		
	});
	$('.banners-homeInterna li').mouseout(function(){
		$('.banners-homeInterna li:animated').stop().animate();
		$('.banners-homeInterna li').animate({
			opacity: 0.5												
		}, 500);
	});
}
var tempo;
var qtdBanner;
var temporizador;
function bannerHome(){
	tempo = 5000;
	qtdBanner = $('#content .mask').children().size();
	$('#content .mask').width(qtdBanner * 950);
	function paginacao(){
		for(a = 0; a < qtdBanner; a++){
			$('#nav-banner').append("<li><a href='javascript:void(0)' title='" + (a + 1 ) + "'>" + (a + 1) + "</a></li>");
		}
	}
	paginacao();
	$('#nav-banner li:eq(0)').addClass('active');
	$('#nav-banner li').click(function(){
		clearTimeout(temporizador);
		$('#content .mask').stop().animate();
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('bottom', -44 + 'px');
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('bottom', -44 + 'px');
		if($.browser.msie != true){
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('opacity', 0);
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('opacity', 0);
		}
		$('#nav-banner li').removeClass('active');
		$(this).addClass('active');
		var indice = $(this).prevAll().size();
		$('#content .mask').animate({
			left: (indice * 950 * -1) + 'px'				
		}, 900, function(){
			if($.browser.msie != true){
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px',
					opacity: 1											 
				}, 900);
			}else{
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px'
				}, 900);
			}
		});
		temporizador = setInterval('anima(qtdBanner);', tempo);
	});
	$('.banner .volta').click(function(){
		clearTimeout(temporizador);
		$('#content .mask').stop().animate();
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('bottom', -44 + 'px');
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('bottom', -44 + 'px');
		if($.browser.msie != true){
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('opacity', 0);
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('opacity', 0);
		}
		var indice = $('#nav-banner li.active').prevAll().size() - 1;
		if(indice < 0){
			indice = qtdBanner - 1;
		}
		$('#nav-banner li').removeClass('active');
		$('#nav-banner li:eq(' + indice + ')').addClass('active');
		$('#content .mask').animate({
			left: (indice * 950 * -1) + 'px'				
		}, 900, function(){
			if($.browser.msie != true){
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px',
					opacity: 1											 
				}, 900);
			}else{
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px'
				}, 900);
			}
		});	
		temporizador = setInterval('anima(qtdBanner);', tempo);
	});
	$('.banner .frente').click(function(){
		clearTimeout(temporizador);
		$('#content .mask').stop().animate();
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('bottom', -44 + 'px');
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('bottom', -44 + 'px');
		if($.browser.msie != true){
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('opacity', 0);
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('opacity', 0);
		}
		var indice = $('#nav-banner li.active').prevAll().size() + 1;
		if(indice == qtdBanner){
			indice = 0;
		}
		$('#nav-banner li').removeClass('active');
		$('#nav-banner li:eq(' + indice + ')').addClass('active');
		
		$('#content .mask').animate({
			left: (indice * 950 * -1) + 'px'				
		}, 900, function(){
			if($.browser.msie != true){
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px',
					opacity: 1											 
				}, 900);
			}else{
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px'
				}, 900);
			}
		});	
		temporizador = setInterval('anima(qtdBanner);', tempo);
	});
	temporizador = setInterval('anima(qtdBanner);', tempo);
}
function anima(param){
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('bottom', -44 + 'px');
		$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('bottom', -44 + 'px');
		if($.browser.msie != true){
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').prevAll().children('h5').css('opacity', 0);
			$('.item:eq(' + $('#nav-banner li.active').prevAll().size() + ')').nextAll().children('h5').css('opacity', 0);
		}
		var indice = $('#nav-banner li.active').prevAll().size() + 1;
		if(indice == param){
			indice = 0;
		}
		$('#nav-banner li').removeClass('active');
		$('#nav-banner li:eq(' + indice + ')').addClass('active');
		$('#content .mask').animate({
			left: (indice * 950 * -1) + 'px'				
		}, 900, function(){
			if($.browser.msie != true){
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px',
					opacity: 1											 
				}, 900);
			}else{
				$('.item:eq(' + indice + ') h5').animate({
					bottom: 7 + 'px'
				}, 900);
			}
		});
	}

function overBanner(){
	$('.item').mouseover(function(){
		$('.box-title span').stop().animate();
		$('.box-title span').animate({
			paddingRight: 38 + 'px'		
		}, 300);
	});
	$('.item').mouseout(function(){
		$('.box-title span').stop().animate();
		$('.box-title span').animate({
			paddingRight: 30 + 'px'		
		}, 300);
	});
}

$(document).ready(function(){
	bt_enviar();
	bt_voltar();
	overBanner();
	categorias();
	bannerHome();
	pagina();					
	imagensDetalhe();
	initImagens();
	
	fakeSelect();
	placeholder('.search label input', 'digite o que procura');
	placeholder('.news .nome', 'seu nome');
	placeholder('.news .email', 'seu e-mail');
	icone_search();		
	aberturaDestaques();
	redes();
	anchor.init();
	menuInterna();
	
	$('a[rel="zoom"]').colorbox();
});
