// Flip in motion effect
var currentContent = "#content-home";
var zIndex		= 1;

$(document).ready(function() {
	// Page Motion Flow
	 updateFrameSize();
	
	$('#home').click(function(){
		flipIn('#content-home');
	});

	$('#history').click(function(){
		flipIn('#content-history');
	});
	
	$('#video').click(function(){
		flipIn('#content-video');
	});
	
	$('#downloads').click(function(){
		flipIn('#content-downloads');
	});

	$('#production').click(function(){
		flipIn('#content-production');
	});
	
	$('#mailinglist').click(function(){
		flipIn('#content-mailinglist');
	});
	
	$('#friendme').click(function(){
		flipIn('#content-mailinglist');
	});
	
	$('#facebook').click(function(){
		flipIn('#content-facebook');
	});
	
	$('#gallery').click(function(){
		fadeIn("http://www.chestnuts.com.sg/chestnut2012/gallery.php");
	});
	
	$('#window-wrap').click(function(){
		$("#window-wrap").fadeOut(300);
		$("#dialog-wrap").fadeOut(300);
		$("#page-iframe").attr("src","");
	});
	
});

function flipIn(content)
{
	zIndex++;
	$("#navigation").css('z-index', zIndex + 1 );
	$(content).css('z-index', zIndex );
	
	$(content).animate( 
		{ marginLeft : "0px"}, 
		400,
		function(){

		$('#content .content-item').each(function(){
			var tmpIdString	= "#" + $(this).attr("id");
			if(tmpIdString != content)
				$(this).css("margin-left", "791px");
		});
	});
}

function fadeIn(content)
{
	$("#page-iframe").attr("src",content);
	$('#window-wrap').css('filter', 'alpha(opacity=50)');
	$("#window-wrap").fadeIn(300);
	$("#dialog-wrap").fadeIn(300);
}

function updateFrameSize()
{
	$("#window-wrap").css("height",$(window).height());
	$("#window-wrap").css("width",$(window).width());
	$("#dialog-wrap").css("left",($(window).width() - 902) / 2 + "px");

}
//Mailing List Validation and submit

function validate(){

	var validateStatus	= true;
	
	if($('#name').val() == '')
	{
		validateStatus	= false;
	}
	
	if($('#email').val() == '')
	{
		validateStatus	= false;
	}
	
	var heardFromUs			= "";
	$('.heardFromUs').each(function(){
		if($(this).is(':checked')){
			heardFromUs += $(this).val() + ",";
		}
	})
	
	if(validateStatus == true)
	{
		$.ajax({
			  url: "sendmail.php",
			  type: "POST",
			  data: {	// CHANGE SEND DATA PARAMETERS HERE!!	
						salutation : $('#salutation').val(),
						name : $('#name').val(),
						email : $('#email').val(),	
						smsSignNumber : $('#smsSignNumber').val(),	
						attended : $('#attended').val(),
						heardFromUs:  heardFromUs
				  		},
	  	   	  beforeSend : function (xhr) {
				  			$('#emailError').fadeOut('slow');
				  			$('#emailError').css('border','0px none');
				  			$('#emailError').html('Sending..<br/><img width="180px" src="img/ajax-loader.gif"></img>');
				  			$('#emailError').fadeIn('slow');
				  		},
			  success : function(data){
				  			if(data == "success")
							{
					  			$('#emailError').fadeOut('slow');
					  			$('#emailError').css('color','green');
								$('#emailError').html('<p style="font-size:11px">Enquiry Mail have been sended.<br/>We will get back to you shortly!<br/>');
					  			$('#emailError').fadeIn('slow');
							}
							else
							{
					  			$('#emailError').fadeOut('slow');
					  			$('#emailError').css('color','red');
								$('#emailError').html('<p style="font-size:11px">Registration fail,  please email us <br/>at <a href="mailto:team@nowstagethis.com">team@nowstagethis.com</a></p>');
					  			$('#emailError').fadeIn('slow');
							}
				  		},
			  error : function(jqXHR, textStatus, errorThrown){
				  			$('#emailError').fadeOut('slow');
				  			$('#emailError').css('border','1px dotted red');
				  			$('#emailError').css('color','red');
							$('#emailError').html('<p style="font-size:11px">Enquiry Mail fail to send, please contact us via <br/><a href="mailto:team@nowstagethis.com">team@nowstagethis.com</a></p>');
				  			$('#emailError').fadeIn('slow');
			  			}
			});
	}
	else
	{
		alert("Please fill in all required fields(*)");
	}
}
