$(document).ready(function() {

	// slider
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		animSpeed:400, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //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
	});

	// slider2
	$('#slider2').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		animSpeed:400, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //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
	});


	// fontes
	Cufon.replace('h1,h2', { hover:true, fontFamily: 'TitilliumTitle01', textShadow: '#fff 0px 1px' });	
	Cufon.replace('h3', { hover:true, fontFamily: 'TitilliumText14L', textShadow: '#fff 0px 1px' });	
	Cufon.replace('h2 span', { hover:true, fontFamily: 'TitilliumText14L', textShadow: '#fff 0px 1px' });	
	Cufon.replace('#footer h2', { hover:true, fontFamily: 'TitilliumText14L', textShadow: '#000 0px -1px' });	
	Cufon.replace('h4', { hover:true, fontFamily: 'TitilliumText14L', textShadow: '#fff 0px 1px' });	
	Cufon.replace('.home_modulo_white h3', { hover:true, fontFamily: 'TitilliumText14L', textShadow: '#fff 0px 1px' });	
	Cufon.replace('.home_modulo_transparent h3', { hover:true, fontFamily: 'TitilliumTitle01', textShadow: '#fff 0px 1px' });	
	
	// tabs
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	//On Click Event
	$(".bt_servicos").click(function() {
		$("html,body").animate({scrollTop : 0},'slow', function() {
			$("#tab_solucoes").removeClass("active"); //Remove any "active" class
			$("#tab_servicos").addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content

			var activeTab = $("#tab_servicos").find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});

	});
	
	
// produtos detalhes contactar 
$(".verMais_bt").click(function(){
	if ($(this).prev().is(":hidden")){
		$(this).prev().slideDown("slow");
		
		$(".verMais_bt").addClass("invisivel");
		
	}
	else{
		$(this).prev().slideUp("slow");
	}
	
	return false;

/*
	if ($(".verMais_content").is(":hidden")){
		$(".verMais_content").slideDown("slow");
		
		$(".verMais_bt").addClass("invisivel");
		
	}
	else{
		$(".verMais_content").slideUp("slow");
	}
	
	return false;
*/
});

	
	// formulario de contacto
	$.tools.validator.localize("pt", {
		':email'  		: 'email inválido',
		'[pattern]'  	: 'email inválido',
		':number' 		: 'campo numérico',
		'[max]'	 		: 'maximo de $1 caracteres',
		'[min]'	 		: 'mínimo de $1 caracteres',
		'[required]' 	: 'campo obrigatório'
	});
	
	//validar formulario footer
	$("#form_contactos").validator({
		lang: 'pt', 
		position: 'top left', 
		offset: [-12, 0], 
		message: '<div><em/></div>' // em element is the arrow
	})
	.submit(function(e) {

		var boxval = $('#form_contactos').serialize();
		
		// client-side validation OK.
		if (!e.isDefaultPrevented()) {
			$.ajax({
				type: "POST",
				url: "phpnewsletter.php",
				data: boxval,
				cache: false,
				success: function(html, response) {
					$('#success_contacto').fadeIn('fast', function() {
						$('#bt_close').click(function() {
							$("#success_contacto").fadeOut('slow');
							$(':input','#form_contactos')
								.not(':button, :submit, :reset, :hidden')
								.val('')
							return false;
						});
					});
				}
			});
			// prevent default form submission logic
			e.preventDefault();
		}
	});
	
	//validar formulario contactos
	$("#contactos_geral").validator({
		lang: 'pt', 
		position: 'top left', 
		offset: [-12, 0], 
		message: '<div><em/></div>' // em element is the arrow
	})
	.submit(function(e) {

		var boxval = $('#contactos_geral').serialize();
		
		// client-side validation OK.
		if (!e.isDefaultPrevented()) {
			$.ajax({
				type: "POST",
				url: "phpnewsletter.php",
				data: boxval,
				cache: false,
				success: function(html, response) {
					$('#success_contacto_geral').fadeIn('fast', function() {
						$('#bt_close_geral').click(function() {
							$("#success_contacto_geral").fadeOut('slow');
							$(':input','#contactos_geral')
								.not(':button, :submit, :reset, :hidden')
								.val('')
							return false;
						});
					});
				}
			});
			// prevent default form submission logic
			e.preventDefault();
		}
	});

	
	// prettyphoto
	$("a[rel^='gallery']").prettyPhoto({theme:'facebook'});
	$("a.fancybox").prettyPhoto({theme:'facebook'});

});
