var processamento=0;
var apis = [];
$(document).ready(function() 
{
	$("#main_home").fadeIn(600);
	$("#main").fadeIn(600);
	$(".subsel").parent().parent().children("span").addClass("sel");
	$(".subsel").parent().show();

	$("#menu span").click(function(){
		if($(this).next().is(":hidden")){ $(this).next().children().children(":first").click(); }
		// if($(this).next().is(":hidden")){$("#menu ul li ul").slideUp(500);}
		// $(this).next().slideToggle(500);
	});
	
	$("#ptcreative").hover(function(){ $(this).stop().animate({"right":0}, 200); },function(){ $(this).stop().animate({"right":-30}, 200);;});
	$("#menu, .form_bt, .bt_entrar").disableSelection();
	$('a[rel*=facebox]').facebox();
	
	$(".projecto, .projecto_more a").click(function(e){
		e.preventDefault();
	
		$.facebox({ div: '#'+$(this).attr("href") }); 
		var projecto_clicado = ($(this).attr("href")).split("-");
	
		$('.scroll-pane').jScrollPane();		
	});
	
	$("#menu a").click(function(e){
		e.preventDefault();
		var menu_link = $(this).attr("href");
		$("#main").fadeOut(300, function(){
			location.href = menu_link;
		});
	});
	
	$("#bt_send").click(function(){
		$(".form_msg").hide();
		$(this).fadeOut(50);
		
		$(".form_msg").html('&bull;').fadeIn(200);
		setTimeout("$('.form_msg').append('&bull;');", 300);
		setTimeout("$('.form_msg').append('&bull;');", 800);
		
		$.post("http://"+$website_patch+"/processa.php?w=contacta",
		{
			nome:$("#mail_nome").val(),
			email:$("#mail_email").val(),
			telefone:$("#mail_telefone").val(),
			mensagem:$("#mail_mensagem").val()
		},
		function(data)
		{
			$('.form_msg').html("");
			
			var result = data.split("|");
			if(result[0]==1)
			{
				$('.form_msg').fadeOut(100, function(){
					$('.form_msg').html(result[1]).fadeIn(200);
				});
			}
			else if(result[0]==2)
			{
				$("#bt_send").fadeIn(200, function(){
					$('.form_msg').fadeOut(200, function(){
						$('.form_msg').html(result[1]).fadeIn(200);
					});
				});
			}
		});
	
	});
	
	$("#bt_subscrive").click(function(){
		$(".form_msg").hide();
		$(this).fadeOut(50);
		
		$(".form_msg").html('&bull;').fadeIn(200);
		setTimeout("$('.form_msg').append('&bull;');", 300);
		setTimeout("$('.form_msg').append('&bull;');", 800);
		
		$.post("http://"+$website_patch+"/processa.php?w=newsletter",
		{
			nome:$("#news_nome").val(),
			email:$("#news_email").val(),
			termos:$("#news_termos").is(':checked')
		},
		function(data)
		{
			$('.form_msg').html("");
			
			var result = data.split("|");
			if(result[0]==1)
			{
				$('.form_msg').fadeOut(100, function(){
					$('.form_msg').html(result[1]).fadeIn(200);
				});
			}
			else if(result[0]==2)
			{
				$("#bt_subscrive").fadeIn(200, function(){
					$('.form_msg').fadeOut(200, function(){
						$('.form_msg').html(result[1]).fadeIn(200);
					});
				});
			}
		});
	
	});
	
	$('#banner_images').innerfade({ animationtype: 'fade', speed: 750, timeout: 4000, containerheight: '1em' });
	
});

function close_box()
{

	$('.scroll-pane').each(
		function()
		{
			apis.push($(this).jScrollPane().data().jsp);
		}
	);

	if (apis.length) { setTimeout("$.each(apis, function(i) { this.destroy(); } ); apis = [];", 300); }
}

$.fn.disableSelection = function() {
    $(this).attr('unselectable', 'on')
           .css('-moz-user-select', 'none')
           .each(function() { 
               this.onselectstart = function() { return false; };
            });
};

