// Jquery
$j = jQuery.noConflict();
jQuery(document).ready(function () {
		// Cria a classe selected
		var secondClass = $j("body").attr('class').split(' ')[1];
		var idMenu;
		switch(secondClass) {
			case "blog":
				idMenu = "#menu-item-239"; // home
			break;
			case "page-id-234":
				idMenu = "#menu-item-238"; // quem somos
			break;
			case "page-id-11":
				idMenu = "#menu-item-237"; // meio ambiente
			break;
			case "page-id-38":
				idMenu = "#menu-item-236"; // serviços
			break;
			case "page-id-257":
				idMenu = "#menu-item-295"; // portfolio
			break;
			case "page-id-90":
				idMenu = "#menu-item-235"; // blog
			break;
			case "page-id-158":
				idMenu = "#menu-item-294"; // contato
			break;
		}
		$j(idMenu).addClass('selected');
		$j(idMenu+" a").removeAttr("href");

		// Addthis replace
		if (secondClass=="page-id-257" ||
			secondClass=="page-id-90" ||
			secondClass=="single-post"
			) {
			var rd = $j(".addthis_toolbox").size();
			$j(".addthis_toolbox").css({visibility:'visible'});
			for (i=0;i<rd;i++) {
				var idPai = $j(".addthis_toolbox").eq(i).parent().parent().attr('id');
				$j(".addthis_toolbox").eq(i).appendTo("#"+idPai+" .blog-cmp .addthis-replace");
			}
		}

	// Cria sombra de texto no IE
	if ($j.browser.msie) {
		$j('.rod_sub').textShadow();
	};
	// Hover do menu
	$j('#menu ul li a').hover(function() {
			var label = $j(this).text();
			var efeitoHover = "<div class='appendHover'>";
			var efeitoHover = efeitoHover+label;
			var efeitoHover = efeitoHover+"</div>";
			$j(this).append(efeitoHover);
			$j(".appendHover").stop().animate({opacity:'1'},500);
			$j(this).next().stop().animate({opacity:'1'},500);	}, 
		function() { 
	  		$j(".appendHover").remove();
			$j(this).next().stop().animate({opacity:'0'},200);
	 });
	 //Hover dos serviços	 
	 $j("body[class*='page-id-38'] .bs").hover(function() {
			var botHover = "<div class='bsHover'></div>";
			$j(this).append(botHover);
			$j(".bsHover").stop().animate({opacity:'1'},300);
		 }, function() {
			 $j(".bsHover").remove();
	 });
	 
	 $j("body[class*='home'] .bs").hover(function() {
			var botHover = "<div class='bsHover'></div>";
			$j(this).append(botHover);
			$j(".bsHover").stop().animate({opacity:'1'},300);
		 }, function() {
			 $j(".bsHover").remove();
	 });	 
	 // Retira links (pag selecionada)
		$j(idMenu+" a").unbind("mouseover mouseout");
	// Hover das redes sociais
	$j('#sociais span').hover(function() {
		$j(this).animate({opacity:'1'},500); },
	  function() {
		$j(this).animate({opacity:'0'},500);
	 });
	 
	 $j("span[class*='not-valid']").mouseover(function() {
		 $j(this).css({display:'none'});
	 });
	// Cortinas
	$j("#faleConosco").click(function(){
		$j(".ar_det").slideToggle('slow');
	});
	
	$j("#Categorias").click(function(){
		$j("#CatDet").slideToggle('slow');
	});
		
	$j("#Arquivos").click(function(){
		$j("#ArqDet").slideToggle('slow');
	});	
	var formRicoh = false;
	$j("#Ric1").click(function(){
		$j("#Ric-c1").slideToggle('slow',function(){ fAberto(); });
	});	
	$j("#Ric2").click(function(){
		$j("#Ric-c2").slideToggle('slow',function(){ fAberto(); });
	});
	$j("#Out1").click(function(){
		$j("#Out-c1").slideToggle('slow',function(){ fAberto(); });
	});	
	$j("#Out2").click(function(){
		$j("#Out-c2").slideToggle('slow',function(){ fAberto(); });
	});	
	function fAberto () {
		if(formRicoh) {
			zeraForm();
			formRicoh = false;
		} else {
			formRicoh = true;
		}
	}
	// Boxes da Ricoh
	$j(".box-esp").hover(function() {
		if ($j(this).find(".rs-cont").is(":hidden")) {
		$j(this).animate({opacity:'1'},500); } },
	  function() {
		if ($j(this).find(".rs-cont").is(":hidden")) {
		$j(this).animate({opacity:'0.6'},200); }
	});
	$j(".box-esp").click(function(){
		$j(this).find(".rs-cont").slideToggle('slow', function() {
			if ($j(this).is(":hidden")) { $j(this).parents(".box-esp").animate({opacity:'0.6'},200); }
	});
		$j(this).find(".mostra,.esconde").toggle();
	});
	
	// Formulario contato
	// Funcao apaga retorna
	$j("textarea").click(function(){ $j(this).text(''); });

	var txtOrig;
	var cmpMod = new Array();
	var cmpOrig = new Array();
	
	$j("input[type='text']").each(function (i) { cmpOrig.push($j(this).val());});
	$j("input[type='text']").click(function(){
			if ($j.inArray($j("input[type='text']").index(this),cmpMod)==-1) {
			txtOrig = $j(this).attr('value');
			$j(this).attr('value',''); }
	});
	$j("input[type='text']").focusout(function(){ 
			if ($j(this).val()=='') {
				$j(this).attr('value',txtOrig);
			} else {
				cmpMod.push($j("input[type='text']").index(this)); }	
	});
	
	$j(":reset").click(function(){ zeraForm(); });
	function zeraForm() { 
		$j("input[type='text']").each(function (i) {
		$j(this).attr('value',cmpOrig[i]);
		cmpMod.length = 0;
		txtOrig = '';
		});
	}
	
	var selForm = true;
	$j("#fCon1").click(function(){ 
		if(!selForm) {	
			zeraForm();	
			$j(this).find('h3').find('p').attr('class', 'on');
			$j(".fcbal2").animate({opacity:'0'},300,function(){
					$j(".fcbal1").animate({opacity:'1'},300);
					$j("#fCon1").find('h3, p').attr('class', 'on');
					$j("#fCon2").find('h3, p').removeAttr('class', 'on');
				});	
			$j("#formCont2").slideUp('slow', function(){
				$j("#formCont1").slideDown('slow');
			selForm = true;				
				});
		}
	}); 
	$j("#fCon2").click(function(){ 
		if(selForm) {
			zeraForm();	
			$j(".fcbal1").animate({opacity:'0'},300,function(){
					$j(".fcbal2").animate({opacity:'1'},300);
					$j("#fCon2").find('h3, p').attr('class', 'on');
					$j("#fCon1").find('h3, p').removeAttr('class', 'on');
				});
			$j("#formCont1").slideUp('slow', function(){
				$j("#formCont2").slideDown('slow');
			selForm = false;				
				});
		}
	}); 
		// Funcao escolha o vendedor
		var nClt = $j("#formCont2 input:radio").val();
		var selVend = $j("#formCont2 select[name=vendedor]");
		$j("#formCont2 select[name=vendedor]").attr('disabled','disabled');
		$j("#formCont2 input[name=cliente]").click(function() {
			var mdClt = $j("#formCont2 input:radio:checked").val();
			if (mdClt == nClt) {
				selVend.val($j('option:first', selVend).val());
				$j("#formCont2 select[name=vendedor]").attr('disabled','disabled');
			} else {
				$j("#formCont2 select[name=vendedor]").removeAttr('disabled');
			}
		});
		
	// Scroll ease
		$j(".scrollease").click(function(event){
		event.preventDefault();
		$j('html,body').animate({scrollTop:$j(this.hash).offset().top}, 500);});
		
		
		//$j(".addthis_toolbox").appendTo("#"+$j(".addthis_toolbox").parent().parent().attr('id')+" .blog-cmp .addthis-replace");
	
// Tudo de jQuery deve estar antes desta linha
	if ($j("a[name='fancy']")) {
		$j("a[name='fancy']").fancybox({
					'width'				: 838,
					'height'			: 525,
					'padding'			: 0,
					'overlayShow'		: true,
					'overlayColor'		: '#000',
					'overlayOpacity'	: 0.9,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'type'				: 'iframe'
		});
	};
	if ($j(".entry-content a[href*='.jpg'], .entry-content a[href*='.png']")) {
		$j(".entry-content a[href*='.jpg'], .entry-content a[href*='.png']").removeAttr('disabled');
		$j(".entry-content a[href*='.jpg'], .entry-content a[href*='.png']").fancybox({
					'autoDimensions'	: true,
					'centerOnScroll'	: true,
					'padding'			: 10,
					'overlayShow'		: true,
					'overlayColor'		: '#000',
					'overlayOpacity'	: 0.9,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic'
		});
	};

});
