// JavaScript Document
$(document).ready(function() {
     	
	//Website page slider
	var panelHeight = 350;
	var curHeight = $("#web-window").height();
	var totalPages = 5;
	var curSlide = 0;
		
	$("a#viewMore").click(function()
	{
		curSlide ++;
							
		//Slider Animation
		if(curSlide == totalPages)
		{
			curSlide = 0;	
			$("#web-window").animate({top: -(panelHeight * curSlide)}, 500);
		}
			
		else
		{
			$("#web-window").animate({top: -(panelHeight * curSlide)}, 500);
		}
	});
		
    //if submit button is clicked
    $('#submit').click(function () {       
         
        //Get the data from all the fields
        var name = $('input[name=name_input]');
        var email = $('input[name=email_input]');
        var subject = $('input[name=subject_input]');
        var message = $('textarea[name=message]');
 
        //Simple validation to make sure user entered something
        //If error found, add hightlight class to the text field
        if (name.val()=='' || name.val() == "Name") {
			//name.addClass('hightlight');
			alert("Please enter your name.");
            return false;
        } else name.removeClass('hightlight');
         
        if (email.val()=='' || email.val() == "Email") {
            //email.addClass('hightlight');
			alert("Please enter your email.");
            return false;
        } else email.removeClass('hightlight');
		
		if (subject.val()=='' || subject.val() == "Subject") {
            //subject.addClass('hightlight');
			alert("Please enter the subject.");
            return false;
        } else subject.removeClass('hightlight');
         
        if (message.val()=='' || message.val() == "Your Message!") {
            //message.addClass('hightlight');
			alert("Please enter your message.");
            return false;
        } else message.removeClass('hightlight');
         
        //organize the data properly
        var data = 'name=' + name.val() + '&email=' + email.val() + '&subject='
        + subject.val() + '&message='  + encodeURIComponent(message.val());
         
        //disabled all the text fields
        //$('.text').attr('disabled','true');
         
        //show the loading sign
        $('#loader').show();
		$('#done').hide();
         
        //start the ajax
        $.ajax({
            //this is the php file that processes the data and send mail
            url: "http://www.davidvillatoro.com/includes/process-contact.php",
             
            //GET method is used
            type: "GET",
 
            //pass the data        
            data: data,    
             
            //Do not cache the page
            cache: false,
             
            //success
            success: function (html) {             
                //if process-contact.php returned 1/true (send mail success)
                if (html==1) {                 
                    //hide the loading icon
                    $('#loader').fadeOut('slow', function(){
						//show the success message
                    	$('#done').fadeIn('slow');
					});                
                 
                //if process.php returned 0/false (send mail failed)
                } else alert('Sorry, there was an unexpected error. Please try again later.');              
            }      
        });
         
        //cancel the submit button default behaviours
        return false;
    });
}); 
