$(function() {
	//carousel inicial
	if ($("#carousel").length > 0) {
		$("#carousel").carouFredSel({	
			circular	: true,
			infinite	: false,
			auto 		: false,					
			scroll: {
				fx		: false,
				duration: 1000
			},
			prev: '#carousel_prev',
			next: '#carousel_next',
			pagination: "#carousel_pag"				
		});	
	}
	//links nav 
	if ($("#lista").length > 0) {
		$("#lista a, #lista li div").hover(function(){
			if($(this).hasClass('active')){
				$(this).stop().animate({marginLeft:'0px'},150);
			}else{
				$(this).stop().animate({marginLeft:'15px'},150);
			}
		},function(){
			$(this).stop().animate({marginLeft:'0px'},150);
		});			
		$("#lista li div").click(function(){
			if(!$(this).next().is(':visible')) {
				$('#lista li ul').animate({opacity: 'hide', height: 'hide'}, 'slow');								
				$('#lista li div').removeClass("active");
				$("#subsublista ul").animate({opacity: 'hide', height: 'hide'}, 'slow');
				$('#subsublista li').removeClass("active");	
				$("#subsublista > li > span").css('text-align', 'right');
			}
			if(!$('#sublista').is(':visible')) {
			}			
			$(this).next().animate({ opacity: 'toggle', height: 'toggle' }, 'slow');	
			$(this).toggleClass("active").siblings().removeClass("active");				
		});					
	}
	$('ul#sublista').each(function() {
		if ($(this).hasClass('open')) {
			$(this).show();
			$(this).prev('div').addClass('active');
		}	
	});

	if ($("#subsublista").length > 0) {
		$("#subsublista li span").click(function(login){
			login.preventDefault();	 
			if ($("#subsublista ul").is( ":visible" )){
				$("#subsublista ul").animate({opacity: 'hide', height: 'hide'}, 'slow');				
				$('#subsublista li').removeClass("active");			
				$("#subsublista > li > span").css('text-align', 'right');	
			} else {	
				$("#subsublista ul").animate({ opacity: 'toggle', height: 'toggle' }, 'slow');	
				$("#subsublista > li").toggleClass("active").siblings().removeClass("active");		
				$("#subsublista > li > span").css('text-align', 'left');			
			}
		});	
	}

	//links nav rodape
	if ($("#lista03").length > 0) {
		$("#lista03 a").hover(function(){
			$(this).stop().animate({marginLeft:'5px'},150);
		},function(){
			$(this).stop().animate({marginLeft:'0px'},150);
		});	
	}
	
	$('input[type=text], select, textarea').each(function(n, element){  
		if ($(element).val() !== '') {  
		  $(element).css('background-color', '#0c1824');
		}  
	});  	
	
	//efeito highlight no form
    $("input,select,textarea").focus(function () {
		$(this).stop().animate({backgroundColor: '#0c1824'}, 'slow');
    });
    $("input,select,textarea").blur(function () {
		if ($.trim($(this).val()) == '') $(this).stop().animate({backgroundColor: "#172c3d"}, 'slow');
    });
    $("input,select,textarea").change(function () {
		$(this).stop().animate({backgroundColor: '#0c1824'}, 'slow');
    });
    $("input,textarea").select(function () {
		$(this).stop().animate({backgroundColor: '#0c1824'}, 'slow');
    });
    $("#login input").focus(function () {
		$(this).stop().css('background-color', '#ffffff');
    });
    $("#login input").blur(function () {
		$(this).stop().css('background-color', '#ffffff');
    });
    $("#login input").select(function () {
		$(this).stop().css('background-color', '#ffffff');
    });	
	//accordion ajuda
	if ($("#accordion").length > 0) {
		$("#accordion li div").click(function(){
			$('html, body').animate({scrollTop: $(this).offset().top}, 300);
			if(!$(this).next().is(':visible')) {
				$('#accordion ul').animate({opacity: 'hide', height: 'hide'}, 'slow');
				$('#accordion li div').removeClass("active");
				$('#accordion li div span').removeClass("active");
			}
			$(this).next().animate({ opacity: 'toggle', height: 'toggle' }, 'slow');
			$(this).toggleClass("active").siblings().removeClass("active");	
			$(this).find("span").toggleClass("active").siblings().removeClass("active");				
		});	
	}
	
function initialize() {	
	if ($("#mapa").length > 0) {
		var lat 		= document.getElementById('MLat').value;
		var lon 		= document.getElementById('MLon').value;
		var nav 		= document.getElementById('MNav').value;
		var typeVisible = document.getElementById('MTypeVisible').value;
		var icone 		= document.getElementById('MIcon').value;

		if(nav == 'P') 
			var nav = {style: google.maps.NavigationControlStyle.SMALL}; 
		else if ( nav == 'G') 
			var nav = {style: google.maps.NavigationControlStyle.ZOOM_PAN};
		else
			var nav = {style: google.maps.NavigationControlStyle.SMALL};

		if(typeVisible == 'S') 
			var typeVisible = true; 
		else if ( typeVisible == 'N') 
			var typeVisible = false;
		else
			var typeVisible = true;
			
		var myOptions = {
			zoom: 15,
			center: new google.maps.LatLng(lat, lon),
			mapTypeControl: typeVisible,
			navigationControl: true,
			navigationControlOptions: nav,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var map = new google.maps.Map(document.getElementById("mapa"), myOptions);

		var myLatLng = new google.maps.LatLng(lat, lon);
		var beachMarker = new google.maps.Marker({
			position: myLatLng,
			map: map,
			icon: icone
		});
	}			
}
	if ($("#mapa").length > 0) {
		google.maps.event.addDomListener(window, 'load', initialize);	
	}

	$('input').keypress(function (e) {
		var code = null;
		code = (e.keyCode ? e.keyCode : e.which);
		return (code == 13) ? false : true;
	});	
	if ($('#loginButton').length > 0) {
		$("#loginButton").click(function(login){
			login.preventDefault();	 
			if ($("#loginBox").is( ":visible" )){
				$("#loginBox").slideUp('normal');	
				$("#passBox").slideUp('normal');		
			} else {	
				$("#loginBox").slideDown('normal');	 
			}
		});
		$("#passButton").click(function(event){
			event.preventDefault();	 
			if ($("#passBox").is( ":visible" )){
				$("#passBox").slideUp('normal');	 
			} else {	
				$("#passBox").slideDown('normal');	 
			}
		});
	}
	if ($(':input[placeholder]').length > 0) {
		$('input, textarea').placeholder();
	}
	
	$('form').submit(function(){
        $(this).find('[placeholder]').each(function() {
            var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
			}
         });	
	});	
	
	if ($('#form-login').length > 0) {
		$('#form-login').validateField({url:'enviar.php'});
	}
	if ($('#form-pass').length > 0) {
		$('#form-pass').validateField({url:'enviar.php'});
	}
	if ($('#form-cliente').length > 0) {
		$('#form-cliente').validateField({url:'enviar.php'});
	}
	if ($('#form-contato').length > 0) {
		$('#form-contato').validateField({url:'enviar.php'});
	}
	if ($('#form-newsletter').length > 0) {
		$('#form-newsletter').validateField({url:'enviar.php'});
	}
	if ($('#form-profissional').length > 0) {
		$('#form-profissional').validateField({url:'enviar.php'});
	}
	if ($(".tab_content").length > 0) {
		$(".tab_content").hide();
		$("ul.tabs_nav li:first").addClass("active").show();
		$(".tab_content:first").show();
		
		$("ul.tabs_nav li.tab").click(function() {
			$("ul.tabs_nav li").removeClass("active");
			$(this).addClass("active");
			$(".tab_content").hide();
			var tabs = $(this).find("a").attr("rel");
			$(tabs).show()
			return false;
		});	
	}
	if ($("input[name='area_profissional[]']").length > 0) {
		$("input[name='area_profissional[]']").click(function(){
			var selecionados = $("input[name='area_profissional[]']").filter(":checked").length;
			if (selecionados != 0 ) {
				$('input#outros').attr('disabled', true);	
				$('input#outros').attr('value', '');
				$('input#outros').css('color','#3b4c5a');
			}else{
				$('input#outros').removeAttr('disabled');	
				$('input#outros').css('color','');
			}	
		});	
	}
	var selecionados = $("input[name='area_profissional[]']").filter(":checked").length;
	if (selecionados != 0 ) {
		$('input#outros').attr('disabled', true);	
		$('input#outros').attr('value', '');
		$('input#outros').css('color','#3b4c5a');
	}	
});
