$(document).ready(function(){
//slide home
/*
if($('#slide').length) {
	$('#slide').nivoSlider({
		effect:'sliceDown', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav: false, //Next & Prev
		// directionNavHide:true, //Only show on hover
		controlNav: false, //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
	});
}	
*/
//slide home	
if ( $('#slide').length ) {
	$('#slide').cycle({ 
		fx:     'fade', 
		speed:   2000, 
		timeout: 4000,  
		pause:   1,
		pager:  '#nav_imgs'	
	});
}	
if ( $('#midias').length ) {
	$('.externo').attr("target", "_blank");
	
}
// menu hover
  $("#hd nav li a").hover(function(){
      $(this).stop().animate({ height: "30px", top: "-3px" }, 300 );
    },function(){
      $(this).stop().animate({ height: "27px", top: "0" }, 300 );
  });
  
 //sanfona 
 if (  $("#nav-colecoes").length ) {
  $("#nav-colecoes h2 a").click(function() {
	$pai = $(this).parent();
	$lis = $pai.parent().siblings();
	$lis.removeAttr("class");
	$lis.find("ul").slideUp();
	$pai.parent().addClass("current");
	$pai.next().show();
  });
  

  $("#nav-colecoes li ul").hide();
  $("#nav-colecoes li.current ul").show(); 
}

//toggle mural
 if($("#list-mural").length) {
	$("#list-mural li .entry").each(function() {
		$p = $(this).find("p").not("p:first")
		if($p.length){
			$p = $p.detach();
			$pfirst = $(this).find("p:first");
			$pfirst.after('<div class="oculto none" />');
			$pfirst.next(".oculto").append($p);
		}
	});
	
	if ( $(".oculto").length ) {
		$(".oculto").after('<a class="icn-mais" href="javascript:;">Mais</a>');
	}
 }
 
 $(".icn-mais").click(function() {
	$oculto = $(this).prev(".oculto");
	if($oculto.length) {
		$(this).toggleClass("icn-menos");
		$oculto.slideToggle();
	}
 });
 
 
// lightbox home
	$u = window.location.href;
	// fechar lightbox
	if($(".wrap-home").length && $u.indexOf("#") == -1) {	//se tiver #home não exibe o lightbox
		$("body").click(function(event) {
			  var $target = $(event.target);
			  if( $target.is("#overlay") || $target.is("#mimo-light") ) $("#overlay").fadeOut();
		}).append('<div id="overlay"><span id="mimo-light">Mimo - CalÃ§olas</span></div>');
		
		$("#overlay").css({ 'height': $(document).height(), 'width' : $(document).width(), 'opacity' : 0.9 }).fadeIn();
		var hwindow = window.innerHeight ? window.innerHeight : $(window).height();
		mTop = Math.round(hwindow / 2) + "px";
		$("#mimo-light").css("top", mTop);
		
		$("#overlay").delay(2000).fadeOut();
	}
// twitter
if( $("#twitter-feeds").length ) {
	$("#twitter-feeds").tweet({
          username: "mimocalcolas",
          count: 3,
          loading_text: "carregando tweets..."
    });	
}	
// fancy 	
if($(".fancy").length) { // se existe a classe .fancy 

	$(".fancy").fancybox({
		hideOnContentClick : true,
		overlayShow : true,
		zoomSpeedIn : 500, 
		zoomSpeedOut : 500,
		overlayOpacity: 0.8
	});
}	
if($("a[rel=fancy_group]").length) {

	$("a[rel=fancy_group]").fancybox({
		hideOnContentClick : true,
		overlayShow : true,
		zoomSpeedIn : 500, 
		zoomSpeedOut : 500,
		titlePosition : 'over',
		titleFormat   : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Imagem ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});
	
}
// validacao

if($("form.cform").length) {
		/* 
		var validator = $("#form_contato").validate({
			rules: {
				fname: "required",
				fmail: { 
					required : true,
					email : true
				},				
				ffone: "required",
				fmsgn: "required"
			},
			messages: {
				fname: "*",
				fmail: "*",				
				ffone: "*",
				fmsgn: "*"
			},
			// the errorPlacement has to take the table layout into account
			errorPlacement: function(error, element) {
				if ( element.is(":radio") ) {
					error.appendTo( element.parent().next().next() );
				} else if ( element.is(":checkbox") ) {
				  error.appendTo ( element.next() );
				} else { error.appendTo( element.parent().next() ); }
		
			},
			invalidHandler: function(form, validator) {
				// adicionar mensagem de erro
				if(!$("p.alert").length) {
					$("#form_contato fieldset").prepend("<p class=\"alert\">Os campos marcados sÃ£o obrigatÃ³rios</p>");
				}
				if($("p.p_sucess").length) $("p.p_sucess").remove();

			},
			// specifying a submitHandler prevents the default submit, good for the demo
			submitHandler: function() {
				document.forms["form_contato"].submit();
			},
			// set this class to error-labels to indicate valid fields
			success: function(label) {
				//$("label.errado").removeAttr("class");
				// set &nbsp; as text for IE
				label.html("&nbsp;").addClass("checked");
			}
		});
		*/
		$("form.cform li label span").each(function(){
			$val = $(this).text();
			$(this).parent().next().val($val).attr("title", $val);
		});
		
		$(".area").focus(function(){
			if ( $(this).val() == $(this).attr("title")) 
				$(this).val("");
		}).blur(function(){
			if ( $(this).val() == "" )
				$(this).val($(this).attr("title"));		
		});
		
		$(".single").focus(function(){
			if ( $(this).val() == $(this).attr("title")) 
				$(this).val("");
		}).blur(function(){
			if ( $(this).val() == "" )
				$(this).val($(this).attr("title"));		
		});

	}

});
