// JavaScript Document

// Listens for the document to be loaded
$(document).ready(function() {
	// Set the initial person counter
	var person = 0;
	var image = 1;
	
	// Set the array of people
	var people = Array("steve", "brian");
	
	
	
	/**
	* Changes the persons details
	*/
	function change_person() {
		if (person == (people.length - 1)) person = 0;
		else person ++;
		
		$("#person").load("/templates/people/"+people[person]+".php", function(){
			// Animate the person in
			$("#person").animate({ 
				top: "0"
			}, 1000);
			
			// Re-bind the listener for the change of person
			$("a.next-person").click(function(event) {
				event.preventDefault();
				
				$("#person").animate({ 
					top: "480px"
				}, 1000, false, change_person);
			});
		});
	}
	
	// Listener for the change of person
	$("a.next-person").click(function(event) {
		event.preventDefault();
		
		// Animate the person out
		$("#person").animate({ 
			top: "480px"
		}, 1000, false, change_person);
	});
	
	
	
	/**
	* Changes the works portfolio image and tag
	*/
	
	// Listener for the change of portfolio image
	$("a#works-button-prev").click(function(event) {
		event.preventDefault();
		
		// Get the number of images
		num_images = $("#images > div.image").size();
		
		// Only scroll if in range
		if (image > 1 && image <= num_images) {
			// Decrease the image counter
			image --;
			if (image < 1) image = 1;
			
			// Animate the person out
			$("#images").animate({ 
				marginLeft: "+=940px"
			}, 1500, false, false);
		}
	});
	
	// Listener for the change of portfolio image
	$("a#works-button-next").click(function(event) {
		event.preventDefault();
		
		// Get the number of images
		num_images = $("#images > div.image").size();
		
		// Only scroll if in range
		if (image > 0 && image < num_images) {
			// Increase the image counter
			image ++;
			if (image > num_images) image = num_images;
			
			// Animate the person out
			$("#images").animate({ 
				marginLeft: "-=940px"
			}, 1500, false, false);
		}
	});
	
	
	
	/**
	* Send the enquiry form
	*/
	$("#enquiry-submit").click(function(event) {
		event.preventDefault();
		
		// Get the form field values
		name 		= document.enquiry_form.name.value;
		email 		= document.enquiry_form.email.value;
		telephone 	= document.enquiry_form.telephone.value;
		enquiry 	= document.enquiry_form.enquiry.value;
		
		// Load the correct form label message		
		$("#label").load("index.php?action=quick-send-contact", { name: name, email: email, telephone: telephone, enquiry: enquiry }, function() {
			// Make sure the label is displayed
			$(".label").css({'display' : 'block'});
			
			// Re-bind the listener for the label close
			$("a#label-close").click(function(event) {
				event.preventDefault();
				$(".label").css({'display' : 'none'});
			});
		});
	});
	
	
	
	/**
	* Send the send to a friend form
	*/
	$("#send-to-friend-submit").click(function(event) {
		event.preventDefault();
		
		// Get the form field values
		friend_email = document.send_to_friend_form.friend_email.value;
		
		// Load the correct form label message		
		$("#label").load("index.php?action=quick-send-to-a-friend", { friend_email: friend_email }, function() {
			// Make sure the label is displayed
			$(".label").css({'display' : 'block'});
			
			// Re-bind the listener for the label close
			$("a#label-close").click(function(event) {
				event.preventDefault();
				$(".label").css({'display' : 'none'});
			});
		});
	});
	
});
