// JavaScript Document
$(window).load(function(){
	// escondendo dropdown
	$('div#master div#header div#header-1-2 div#hForm div#wrap_dropdown').fadeOut();
	// Header DropDown
	$('div#header-1-2 div#hForm div#input_select_bt').click(function(){
		$('div#master div#header div#header-1-2 div#hForm div#wrap_dropdown')
			.slideToggle(800);
	});
});

$(document).ready(function(){
	
	//Banner
	var $banners = $('.banners');
	
	if($banners.length){
		$banners.cycle({
			fx: 'fade', 
			speed: 800, 
			timeout: 5000, 
			next: '.next', 
			prev: '.prev'
		});
        
        $banners.find('a').hover(function(){
            $('.top').stop().animate({ top:-85 });
            $('.bottom').stop().animate({ bottom:-75 });
        }, function(){
            $('.top').stop().animate({ top:0 });
            $('.bottom').stop().animate({ bottom:0 });
        })
        
	};
	
    // Receitas
    var $receitasContent = $('#content-receitas');
    
    if($receitasContent.length){
        
        var $receitas;
        var childrens;
        var receitaHeight;
        
        $receitasContent.find('.receita').each(function(){
            if($(this).children().size() > 2){
                $(this).parent().css({ height:120, overflow:"hidden" })
            } else { 
                console.log($(this).parent().parent().find(".abrir"))
                $(this).parent().parent().find("a").hide();
            }
        });
        
        $(this).find('.abrir').toggle(function(){            
        
            $receitas = $(this).parent().find('.receitas');
            children = $receitas.children().size();
            receitaHeight = (children * $receitas.find(".receita").height()) + children * 40;
        
            $(this).parent().find('.receitas').animate({height:receitaHeight});
        }, function(){
            $(this).parent().find('.receitas').animate({height:120});
        })
        
    };
    
	// Imprensa
    
    var $imprensa = $("#content-imprensa")
    
    if($imprensa.length){
        $(this).find('a.pic-link').fancybox({
            padding:0,
            width:"auto",
        });
    };
    
    
	// Box Header Login
	// .click() no hLogon
	$('div#master div#header div#header-1-2 div#hLogbox1-2 p a.logon')
	.click(function(){
		$(this).fadeOut(500);
		$('div#master div#header div#header-1-2 div#hLogbox1-2 p span.pipe, div#master div#header div#header-1-2 div#hLogbox1-2 p a.cadastrar').fadeOut(500);
		$('div#master div#header div#header-1-2 div#hLogbox1-1').slideDown(1000);
		$('div#master div#header div#header-1-2 div#hLogbox1-2')
			.animate({ 
				marginTop:"+=130px"
			}, 1000 );
		$('div#master div#header div#header-1-2 div#hLogbox1-1 #hLogbox1-1-1').fadeIn(2000);
		$('div#master div#header div#header-1-2 div#hLogbox1-2 p a.cadastrar').fadeIn(1000);
	})//fim .click Logon
	

//hover do li
	$('div#header-1-2 div#hForm ul#dropdown li')
	.hover(
		function () {
			$(this).css('background-color','#5b4d38');
		}, 
		function () {
			$(this).css('background','none');
	});
	// click no li
	$('div#master div#header div#header-1-2 div#hForm ul#dropdown li').click(function(){
		var selectCidade = $(this).attr("id");
		//alert(selectCidade);		
		$('div#hForm input#input_select').val(selectCidade);
		$('div#master div#header div#header-1-2 div#hForm div#wrap_dropdown')
			.slideUp(800);
	});
	
	// GALERIA IMG DESTAQUE DA HOME
	$('div#content-1.home #content-1-1 #dImage #thumbs .item').click(function(){
		var srcimgDestaque = $(this).find("img").attr("src");
		//alert(srcimgDestaque);
		//alert(hrefimgDestaque);
		
		$('div#content-1.home #content-1-1 #dImage #destaque *').fadeOut(800);
		
		$('div#content-1.home #content-1-1 #dImage #destaque')
		.html(
		"<img src="+srcimgDestaque+" class='newfadeIn' />"
		);
		
		$('div#content-1.home #content-1-1 #dImage #destaque img.newfadeIn').fadeIn(1200);
	})
	

	
	
	
	if (!$.browser.opera) {

        $('select.assunto').each(function(){
            var title = $(this).attr('title');
            if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
            $(this)
                .css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
                .after('<span class="select">' + title + '</span>')
                .change(function(){
                    val = $('option:selected',this).text();
                    $(this).next().text(val);
                    })
        });

    };
	
    
    swapValue = [];
      $('input[type="text"], textarea').each(function(i){
        swapValue[i] = $(this).val();
        $(this).focus(function(){
          if ($(this).val() == swapValue[i]) { $(this).val(""); }
          $(this).addClass("focus");
        }).blur(function(){
          if ($.trim($(this).val()) == "") {
            $(this).val(swapValue[i]);
            $(this).removeClass("focus");
          }
        });
      });
	
});//fim ready
