//AJAX IMAGES

function cancel_anims()
{
	 $('#work_a_images').cycle('pause');
	 $('#work_b_images').cycle('pause');
	 $('#work_c_images').cycle('pause');
	 $('#work_d_images').cycle('pause');
	 $('#work_e_images').cycle('pause');
	 $('#work_f_images').cycle('pause');
	 $('#work_g_images').cycle('pause');
	 $('#work_h_images').cycle('pause');
	 $('#work_i_images').cycle('pause');
}
$(document).ready(
	function(){
	$("a[@href=#work_a]").click(function(){
		$("#work_a_images").load("includes/work_a_images.php",{},function(){
			cancel_anims();
			$('#work_a_images').cycle('resume');
			$('#work_a_images').cycle({
		    fx:    'fade', 
		    speed:  2000 ,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_b]").click(function(){
		$("#work_b_images").load("includes/work_b_images.php",{},function(){
			cancel_anims();
			$('#work_b_images').cycle('resume');
			$('#work_b_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_c]").click(function(){
		$("#work_c_images").load("includes/work_c_images.php",{},function(){
			cancel_anims();
			$('#work_c_images').cycle('resume');
			$('#work_c_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_d]").click(function(){
		$("#work_d_images").load("includes/work_d_images.php",{},function(){
			cancel_anims();
			$('#work_d_images').cycle('resume');
			$('#work_d_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_e]").click(function(){
		$("#work_e_images").load("includes/work_e_images.php",{},function(){
			cancel_anims();
			$('#work_e_images').cycle('resume');
			$('#work_e_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_f]").click(function(){
		$("#work_f_images").load("includes/work_f_images.php",{},function(){
			cancel_anims();
			$('#work_f_images').cycle('resume');
			$('#work_f_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_g]").click(function(){
		$("#work_g_images").load("includes/work_g_images.php",{},function(){
			cancel_anims();
			$('#work_g_images').cycle('resume');
			$('#work_g_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_h]").click(function(){
		$("#work_h_images").load("includes/work_h_images.php",{},function(){
			cancel_anims();
			$('#work_h_images').cycle('resume');
			$('#work_h_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	$("a[@href=#work_i]").click(function(){
		$("#work_i_images").load("includes/work_i_images.php",{},function(){
			cancel_anims();
			$('#work_i_images').cycle('resume');
			$('#work_i_images').cycle({
		    fx:    'fade', 
		    speed:  2000,
			timeout:  900
		    });
		});
		
	});
	
});

// SLIDING FUNCTIONS

jQuery(function( $ ){
	
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://www.freewebs.com/flesler/jQuery.ScrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	var target = $('#content').get(0);//the scrolled div
	
	/**
	 * restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
	 * could use $(target).scrollTo( 0, {axis:'xy'));
	 * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
	 */
	target.scrollLeft = target.scrollTop = 0;
	
	//scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});
	
	var $last = $([]);//save the last link
	
	/**
	 * NOTE: In the former version of the demo, I called $('#navigation').localScroll()
	 * Now I want to also affect the >> and << links, so I'll use $.localScroll() instead
	 */
	$.localScroll({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1000,
		hash:false,
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
			this.blur();//remove the awful outline
			
		}
	});
});
		
// FORM VALIDATION
       
$(document).ready(function() { 
	$('#validation').hide();
	$('#confirmation').hide();
    var options = { 
        target:        '#confirmation',   // target element(s) to be updated with server response 
        beforeSubmit:  validate,  // pre-submit callback 
        success:       function() { 
        	$('#validation').fadeOut('slow');
        	$('#commentForm').fadeOut('slow');
            $('#confirmation').fadeIn('slow'); 
        }  
    }; 
    $('#commentForm').ajaxForm(options); 
}); 
 
function validate(formData, jqForm, options) { 
    
 	$("#validation").html('');
    var form = jqForm[0]; 
    err="";
    if (!form.name.value)
    {
    	err+="<li>Please tell us your name, or we'll just have to call you Bob!</li>";
    }
    if (!form.email.value)
    { 
    	err+="<li>We'll be needing a valid e-mail address or phone number please.</li>";
    }
    if (!form.comment.value) 
    { 
        err+="<li>Your forget to let us know what you wanted! Please complete the big white box.</li>";
    } 
    if (err>'')
    {
    	$("#validation").append("<ul>" + err + "</ul>");
        $("#validation").slideDown();
        return false; 
    }
     
} 
