$(document).ready(function(){	
	
	$.preloadCssImages({statusBarEl: '#statusbar'});
	
	
	
	

	
	
	//contactos
	$('#quotationtag .content .done').hide();
	$('#quotationtag .content .erro').hide();
	$('#quotationtag .content .loading').hide();
	$('#quotationtag .content #submit').click(function () {
		var quot_nome = $('#quotationtag .content input[name="nome"]');
		var quot_email = $('#quotationtag .content input[name="email"]');
		var quot_detalhes = $('#quotationtag .content textarea[name="detalhes"]');
		var quot_ip = $('#quotationtag .content input[name=ip]');
		//Validation
		if (quot_nome.val()=='') {
			quot_nome.effect( "shake", {times:3, distance:10}, 50 );
			$('#quotationtag .content label[for="nome"]').effect( "shake", {times:3, distance:10}, 50 );
			return false;
		}
		if (quot_email.val()=='') {
			quot_email.effect( "shake", {times:3, distance:10}, 50 );
			$('#quotationtag .content label[for="email"]').effect( "shake", {times:3, distance:10}, 50 );
			return false;
		}
		if (quot_detalhes.val()=='') {
			quot_detalhes.effect( "shake", {times:3, distance:10}, 50 );
			$('#quotationtag .content label[for="detalhes"]').effect( "shake", {times:3, distance:10}, 50 );
			return false;
		}
		//organize the data properly
		var quotationString = 'nome=' + quot_nome.val() + '&ip=' + quot_ip.val() + '&email=' + quot_email.val() + '&detalhes='  + encodeURIComponent(quot_detalhes.val());
		//disabled all the text fields
		$('#quotationtag .content .textfield').attr('disabled','true');
		$('#quotationtag .content .textfield, #quotationtag label, #quotationtag #submit').animate({opacity: 0.25},{queue:false, duration:500}, function(){
			$('#quotationtag .content .loading').fadeIn('fast');
		});
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "quotation.php",	
			//GET method is used
			type: "GET",
			//pass the data			
			data: quotationString,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html, status) {				
					//hide the form
					$('#quotationtag .content .formulario').slideUp().hide();					
					//show the success message
					$('#quotationtag .content .done').fadeIn(2000);
				//if process.php returned 0/false (send mail failed)
				//enable all the text fields again
				/*$('quotationtag .content .erro').fadeIn('slow');
				$('quotationtag .content .erro').click(function () {
					$('quotationtag .content .erro').fadeOut('fast');
					$('quotationtag .content .textfield').animate({opacity: 1 },{queue:false, duration:1});
					$('quotationtag .content #submit').animate({opacity: 1 },{queue:false, duration:1});
					$('quotationtag .content .textfield').removeAttr('disabled','true');
				});
				//hide the loading sign
				$('quotationtag .content .loading').hide();
				}
				//alert('Ocorreu um erro. Tente novamente.');*/				
			}		
		});
		return false;
	});

});

	
$(window).load(function(){
	
	$('#pageloading').fadeOut('normal', function(){
	/***********************
	Entry animation
	***********************/
	$('#header h1').delay(1000).animate({
		opacity:'show',
		marginLeft:'+=170px',
		marginTop:'+=135px'
	}, 'slow' , function(){
		$('#footer').animate({opacity:'show' },'slow');
		$('#navigation').slideDown('slow', function(){
			$('#portfolio-tag').animate({opacity:'show' },'slow');
		});
	});
	});
		
});
