$(document).ready(function(){

    $(".twitter-container").tweet({
        username: "dominiodamoda",
        avatar_size: 0,
        count: 10,
        loading_text: "<img src='/templates/img/others/loader.gif' alt='Carregando...'/>"
    });
	
    $('.accordion .container:last').css('width','575');
    lastBlock = '#al';
    maxWidth = 575;
    minWidth = 41;	
    
    $("#search-footer").submit(function() {
	  window.location.href='/busca?str='+$("#search-footer input[type=text]").val();
	  return false;
	});
   
    $("#search").submit(function() {
	  window.location.href='/busca?str='+$("#search input[type=text]").val();	  
	  return false;
	}); 
    

    $(".accordion li.container").hover(function(){
        $(lastBlock).animate({
            width: minWidth+"px"
        },{
            queue:false,
            duration:400
        });
		
        $(this).animate({
            width: maxWidth+"px"
        },{
            queue:false,
            duration:400
        });
        lastBlock = this;
    });
	
    $(".has-easy-buy").live('mouseover mouseout',function(event){
        if ( event.type == "mouseover" ) {
            $(this).find(".easy-buy").show();
        } else {
            $(this).find(".easy-buy").hide();
        }
    });
	
    $('input').focus(function(){
        if ($(this).val() == $(this).attr('title')){
            $(this).val('');
        }
    });
    $('input').blur(function(){
        if ($(this).val() == ''){
            $(this).val($(this).attr('title'));
        }
    });
	
    $('.has-submenu').hover(function(){				
        $(this).addClass('active');
        $(this).find('.submenu-content').fadeIn(200);
    },function(){
        $(this).removeClass('active');
        $(this).find('.submenu-content').fadeOut(200);
    });
	
    $('#banner .banner-container').nivoSlider({
        effect:'fade',
        controlNavThumbs:false,
        controlNavThumbsFromRel:false,
        slices:1,
        animSpeed:300,
		controlNav:true,
		pauseTime: 5000
    });
	
    $(window).scroll(function () {	
        var position = window.pageYOffset;
		if(navigator.appName == "Microsoft Internet Explorer"){
			position = document.documentElement.scrollTop;
		}
		
		
        if (position < 160){
            $('#floating-category').fadeOut(200);
        }else{
            $('#floating-category').fadeIn(200);
        }
    });
	
    $('.filter-container .title').toggle(function(){
        $(this).parent().find('.filter-content').slideUp();
        $(this).parent().find('.fold').html("+");
        
        
    }, function(){	
        $(this).parent().find('.filter-content').slideDown();
        $(this).parent().find('.fold').html("&#8212;");
    });
    	
    $('.filter-container .checkbox').dgStyle();
	
    function showValues() {
        var dados = $(".filter-form").serialize();
        var ppp = $("#qtd_produtos_pagina").val();
        var ord = $("#ordenacao").val();
        params = dados;
        $.ajax({
            type: "POST",
            cache: false,
            url: "/PaginaDepartamentoAjax.obj?iddepto="+iddepartamento+"&pg="+pg+"&produtos_pagina="+ppp+"&ord="+ord+"&str="+str,
            data: dados,
            beforeSend: function(){
                //$('.lista-de-produtos li').fadeTo(200, 0.3);
                //$('.lista-de-produtos').append('<div class="loader"></div>');
                showLoading();
            },
            success: function(retorno){
                $('.lista-de-produtos').html(retorno);
                
                $(".content-paginador").html($(".paginador-ajax").html());
                $(".paginador-ajax").remove();
                
                //$('.lista-de-produtos li').fadeTo(200, 1);
                $('.lista-de-produtos .loader').remove();
                
                $('#box-marca').remove();
                hideLoading();
            },error: function(ret) {
                hideLoading();
            }
        });
    }
    $('.filter-content li').click(function(){
        showValues();
    });
	
    $('a.easy-buy').live("click",function(){
        var r = $(this).attr('rel');
        var idproduto = r.substr(8, r.length);
        $('.easy-buy-modal').html('');
        $('.easy-buy-modal').fadeIn(200);
        $('.easy-buy-modal').load('/CompraFacil.obj?id='+idproduto);
        return false;
    });
	
    $( "#tabs" ).tabs();
	
    /* Ao clicar para excluir um item, esta função é executada. */
    $(".delete-item").click(function(){
        /* Adiciona opacidade 0.3 ao item que será excluído. */
        $(this).parents('.item-cart').fadeTo('slow', 0.3, function(){
            /* Guarda em uma variável o item que o usuário está excluindo. */
            var thisItem = $(this);
        });
    });
	
	
	$("#navigation a").live("click", function(){
		event.preventDefault();
	});
	
	
	setInterval(function(){
		var e = $("#banner-topo-detalhe-produto .active");
		
		if(e.is("img:last-child")){
			$("#banner-topo-detalhe-produto img").first().fadeIn().addClass("active");			
		}else{
			e.next().addClass("active").fadeIn();					
		}
		
		e.fadeOut().removeClass("active");							
		
	 }, 6000);
	
	
	
});

