//DOCUMENT IS READY
$(document).ready(function() {
		
	// ##### YOUTUBE #####
	
	// Update a particular HTML element with a new value
	function updateHTML(elmId, value) {
		document.getElementById(elmId).innerHTML = value;
	}
	
	// This function is called when an error is thrown by the player
	function onPlayerError(errorCode) {
		alert("An error occured of type:" + errorCode);
	}
	
	
	// ##### VIDEOS UI CONTROLS #####
	$('#content .container .videos-list .video .controls div a.play').click(
		function() {
			$(this).css('display', 'none');
			$(this).parent().find('.pause').css('display', 'block');
	});
	
	$('#content .container .videos-list .video .controls div a.pause').click(
		function() {
			$(this).css('display', 'none');
			$(this).parent().find('.play').css('display', 'block');
	});
	
	$('#content .container .videos-list .video .controls div a.stop').click(
		function() {
			$(this).parent().parent().find('.pause').css('display', 'none');
			$(this).parent().parent().find('.play').css('display', 'block');
	});
	
	$('#content .container .videos-list .video .controls div a.mute').click(
		function() {
			$(this).css('display', 'none');
			$(this).parent().find('.unmute').css('display', 'block');
	});
	
	$('#content .container .videos-list .video .controls div a.unmute').click(
		function() {
			$(this).css('display', 'none');
			$(this).parent().find('.mute').css('display', 'block');
	});
	
	
	
	$("#content .container .about .txt-column.values p a, #content .container .about .txt-column.mission p span a").hover(
		function() {
						
			var selector = $(this).attr('rel');
						
			$(selector).stop().fadeTo('slow', 1);
			
		},
		function() {
			
			var selector = $(this).attr('rel');
			
			$(selector).stop().fadeTo('slow', 0);
			
		}
	);
	
	
	
	// ##### NEWS HOVER EFFECT #####
	/*$('#content .container .news-list .slide-news .panes-list .pane .news, #content .container .works-list .slide-works .panes-list .pane .work, #content .container .news-show .other-news .news').hover(
		function () {
			$(this).find('.info').stop().animate({ 
				bottom: '0' 
			}, 200);
		}, 
		function () {
			$(this).find('.info').stop().animate({ 
				bottom: '-100px' 
			}, 200);
		}
	);*/
	
	
	// ##### FORM INPUTS #####
	$("#contacts-form .inputs p input[name=name]").focus(function() {
	 
		var value = $(this).val();
		
		if(value == "Nome")
			$(this).val('');
		
	}).blur(function() {
	 
		var value = $(this).val();
		
		if(value == "")
			$(this).val('Nome');
		
	});
	
	$("#contacts-form .inputs p input[name=email], #newsletter-form .inputs p input[name=email]").focus(function() {
		 
		var value = $(this).val();
		
		if(value == "Email")
			$(this).val('');
		
	}).blur(function() {
	 
		var value = $(this).val();
		
		if(value == "")
			$(this).val('Email');
		
	});
	
	$("#contacts-form .inputs p input[name=subject]").focus(function() {
		 
		var value = $(this).val();
		
		if(value == "Assunto")
			$(this).val('');
		
	}).blur(function() {
	 
		var value = $(this).val();
		
		if(value == "")
			$(this).val('Assunto');
		
	});
	
	$("#contacts-form .inputs p textarea").focus(function() {
		 
		var value = $(this).val();
		
		if(value == "Mensagem")
			$(this).val('');
		
	}).blur(function() {
	 
		var value = $(this).val();
		
		if(value == "")
			$(this).val('Mensagem');
		
	});
	
	$("#newsletter-form .inputs p input[name=attribute1]").focus(function() {
		 
		var value = $(this).val();
		
		if(value == "Nome")
			$(this).val('');
		
	}).blur(function() {
	 
		var value = $(this).val();
		
		if(value == "")
			$(this).val('Nome');
		
	});
	
	$("#newsletter-form .inputs p input[name=attribute2]").focus(function() {
		 
		var value = $(this).val();
		
		if(value == "Empresa")
			$(this).val('');
		
	}).blur(function() {
	 
		var value = $(this).val();
		
		if(value == "")
			$(this).val('Empresa');
		
	});
	
	
	// ##### FORM VALIDATOR LOCALIZED ####
	
	$.tools.validator.localize("pt", {
		'*'			   : 'Corrija este valor',
		':email'  	   : 'Introduza um email v&aacute;lido',
		':number' 	   : 'Introduza um valor num&eacute;rico',
		':url' 		   : 'Introduza um URL v&aacute;lido',
		'[max]'	 	   : 'Introduza um valor menor que $1',
		'[min]'		   : 'Introduza um valor maior que $1',
		'[required]'   : 'Campo obrigat&oacute;rio'
	});
	
	
	// ##### FORM SUBMIT - CONTACTS #####
	$("#contacts-form").submit(function(e) {
		
		if (!e.isDefaultPrevented())
		{
			var action = $(this).attr('action');
			
			$.ajax({
				type: 'POST', 
				data: $('#contacts-form').serialize(), 
				url: action, 
				success: 
					function(msg){ 
						if(msg)
						{							
							$('#contacts-form input[name=name]').val('Nome');
							$('#contacts-form input[name=email]').val('Email');
							$('#contacts-form input[name=subject]').val('Assunto');
							$('#contacts-form textarea').val('Mensagem');
							
							$.notifyBar({
								html: "Mensagem enviada com sucesso!",
							    delay: 10000,
							    animationSpeed: "normal",
							    cls: "success"
							});
						}
						else
						{
							$.notifyBar({
								html: "Houve um problema a enviar a mensagem. Tenta novamente!",
							    delay: 10000,
							    animationSpeed: "normal",
							    cls: "error"
							});
						}
				}
			});

			e.preventDefault();
		}
		
	});
	
	
	// ##### FORM SUBMIT - NEWSLETTER #####
	$("#newsletter-form").submit(function(e) {
		
		if (!e.isDefaultPrevented())
		{
			var action = $(this).attr('action');
			
			$.ajax({
				type: 'POST', 
				data: $('#newsletter-form').serialize(), 
				url: action, 
				success: 
					function(msg){ 
						if(msg)
						{							
							$('#newsletter-form input[name=attribute1]').val('Nome');
							$('#newsletter-form input[name=attribute2]').val('Empresa');
							$('#newsletter-form input[name=email]').val('Email');
							
							$.notifyBar({
								html: "Foste inscrito com sucesso! Vais receber um email para confirmares a tua inscri&ccedil;&atilde;o.",
							    delay: 10000,
							    animationSpeed: "normal",
							    cls: "success"
							});
						}
						else
						{
							$.notifyBar({
								html: "J&aacute; te encontras inscrito ou houve um problema. Tenta novamente!",
							    delay: 10000,
							    animationSpeed: "normal",
							    cls: "error"
							});
						}
				}
			});

			e.preventDefault();
		}
		
	});
	
});
