//confirmação
function confirma()
{
	msg = "Confirma?";

	return confirm(msg); 
}
//script galeria de imagens
jQuery(document).ready(function(){
	//Larger thumbnail preview 
	$("ul.thumb li").hover(function() {
		$(this).css({"z-index" : "10"});
		$(this).find("img").addClass("hover").stop()
		.animate({
			marginTop: "-110px", 
			marginLeft: "-110px", 
			top: "50%", 
			left: "50%", 
			width: "174px", 
			height: "174px",
			padding: "20px" 
		}, 200);

	} , function() {
		$(this).css({"z-index" : "0"});
		$(this).find("img").removeClass("hover").stop()
		.animate({
			marginTop: "0", 
			marginLeft: "0",
			top: "0", 
			left: "0", 
			width: "100px", 
			height: "100px", 
			padding: "5px"
		}, 400);
	});
	
	/*//Swap Image on Click
	$("ul.thumb li a").click(function() {
		var mainImage = $(this).attr("href"); //Find Image Name
		$("#main_view img").attr({ src: mainImage });
		$("#main_view a").attr({ href: mainImage });
		return false;		
	});
	*/
	
	//menus
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	$("ul.topnav li").hover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).find("ul.subnav").stop(true, true).slideDown('fast').show(); //Drop down the subnav on click
		$(this).hover(function() {
		}, function(){
			$(this).find("ul.subnav").stop(true, true).slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	//mostrar imagem
	$("a#imagem1").fancybox();
	$("a.imagens").fancybox({
		'titlePosition'  : 'over'
	});
	$("a.videos").fancybox({
		'type' : 'iframe'
	});
	//mostrar form tegisto
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
	$("#dialogclik").button();
	$("#dialogclik").click(function() {
		$( ".loginform" ).dialog( "open" );
	});
	$("#emailnews").keyup(function() {
		var email = $( "#emailnews" ).val();
		if(isValidEmailAddress(email)){
			$("#validEmail").html( "<img src='/graficos/validyes.png' alt='yes' />" );
		}else{
			$("#validEmail").html( "<img src='/graficos/validno.png' alt='no' />" );
		}
	});
	$( ".loginform" ).dialog({
		autoOpen: false,
		height: 130,
		width: 400,
		modal: true,
		resizable: false,
		buttons: {
			"Adicionar": function() {
				var email = $( "#emailnews" ).val();
				if(email != 0){
					if(isValidEmailAddress(email)){
						$("#validEmail").html( "<img src='/graficos/validyes.png' alt='yes' />" );
						$.ajax({
							url: "/index.php",
							type: "POST",
							data: {action: "adicionar", email: email},
							success: function(){
								alert("Email adicionado com sucesso");
							},
							error: function(){
								alert("Erro");
							}
						});
						$( this ).dialog( "close" );
					} else {
						$("#validEmail").html( "<img src='/graficos/validno.png' alt='no' />" );
					}
 				}
			},
			"Remover": function() {
				var email = $( "#emailnews" ).val();
				if(email != 0){
					if(isValidEmailAddress(email)){
						$("#validEmail").html( "<img src='/graficos/validyes.png' alt='yes' />" );
						$.ajax({
							url: "/index.php",
							type: "POST",
							data: {action: "remover", email: email},
							success: function(){
								alert("Email eliminado com sucesso");
							},
							error: function(){
								alert("Erro");
							}
						});
						$( this ).dialog( "close" );
					} else {
						$("#validEmail").html( "<img src='/graficos/validno.png' alt='no' />" );
					}
				}
			}
		},
		close: function() {
			$( ".loginform" ).dialog( "close" );
		}
	});
	$("#contactos").submit(function() {
		alert("Contacto enviado com sucesso...");
	});
	
	//ICONES
	$('#icones').hover(function() { //On hover in
			$(this).stop(true,true).animate({width:"84px"}, 1000 );
			$('#icones a').stop(true,true).animate({width:"39px"}, 1200 );
		}, function(){	//On Hover Out
			$(this).stop(true,true).animate({width:"45px"}, 1000 );
			$('#icones a').stop(true,true).animate({width:"0px"}, 1000 );
	});
	
	//loading
	$('#loading').hide();
	$('#loading').ajaxStart(function() {
		$(this).show();
	});
	$('#loading').ajaxStop(function() {
		$(this).hide();
	});
});
