$(document).ready(function(){
	
	/* admin */
	$('input:text').setMask();
	$(".admin-formulario").colorbox({width:"760px", height:"90%", iframe:true});
	$(".admin-formulario-geral").colorbox({width:"760px", height:"250px", iframe:true});
	$(".admin-grid").colorbox({width:"80%", height:"80%", iframe:true});
	$("#btn_busca").hide();

	$("#procura").focus(function(){
		if ($(this).val()=="Buscar..."){
			$(this).val("");
			$("#btn_busca").show("slow");
		}
	});
	$("#procura").blur(function(){
		if ($(this).val()==""){
			$(this).val("Buscar...");
			$("#btn_busca").hide("slow");
		}
	});
	
	$("#menu_itens ul li ul").each(function(){
		if ($(this).children().length<=0) $(this).remove();
	});
	
    $('.lightbox').lightbox();
	$('#slider').nivoSlider({
        effect:'random', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:3000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:false, //Only show on hover
        controlNav:true, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });
	
	if ($(".extras").length>0){
		var altura = $(".extras").position().top-500;
		$("#marcadagua").css("top",altura);
		var largura = $(document).width()-450;
		//$("#marcadagua").css("left",largura);
	}
	
	$("#menu_categorias ul li ul").hide();
	
	// Adiciona as funções do menu
	$("#menu_categorias ul li a").click(function(){
		if ($(this).parent("li").children("ul").is(":visible")){
			$(this).parent("li").children("ul").slideUp("normal");
		}else{
		 	$(this).parent("li").children("ul").slideDown("normal");	
		}
	});
	
	// Grid
	$(".tabela tr, .td-opcoes").mouseover(function(){
		$(this).css("background-color","#E9E9E9");									  
	});
	$(".tabela tr").mouseout(function(){
		$(this).css("background-color","#FFF");									 
	});
	$("#btn_pesquisar").click(function(){
	var procura = $("#txt_pesquisa").val();
	location.href='?s=ecomm&p=pesquisa&procura='+procura;
});

	
});

function htmlent(v){
	v = v.replace("&ccedil;","ç");
	
	return v;
}

function clearForm(form){
	$(':input','#'+form)
	 .not(':button, :submit, :reset, :hidden')
	 .val('')
	 .removeAttr('checked')
	 .removeAttr('selected');
	
}

function htmlDecode(input){
    var e = document.createElement('div');
    e.innerHTML = input;
    return e.innerHTML;
}

function preload(imagem){
	preload_image = new Image(25,25); 
    preload_image.src=imagem; 
}

function envia_email(){
	$('#envio_email').slideDown('slow');	
}
