$(document).ready(function(){ 
	
	function validate(formData, jqForm, options) { 
	    // formData is an array of objects representing the name and value of each field 
	    // that will be sent to the server;  it takes the following form: 
	    // 
	    // [ 
	    //     { name:  username, value: valueOfUsernameInput }, 
	    //     { name:  password, value: valueOfPasswordInput } 
	    // ] 
	    // 
	    // To validate, we can examine the contents of this array to see if the 
	    // username and password fields have values.  If either value evaluates 
	    // to false then we return false from this method. 
	 
	    for (var i=0; i < formData.length; i++) { 
	        if (!formData[i].value) { 
	            alert('Please fill out the form completely before proceeding.'); 
	            return false; 
	        } 
	    } 
	}
	
	$("#carter").hide();
	$("#loader").hide();
    $("ul.sf-menu").superfish({
    	animation: {opacity:'show', height:'show'}
    }); 
	$('#slide').cycle({ 
	    fx:      'custom', 
	    cssBefore: {  
	        left: 115,  
	        top:  115,  
	        width: 0,  
	        height: 0,  
	        opacity: 1, 
	        zIndex: 1 
	    }, 
	    animOut: {  
	        opacity: 0  
	    }, 
	    animIn: {  
	        left: 0,  
	        top: 0,  
	        width: 750,  
	        height: 400  
	    }, 
	    cssAfter: {  
	        zIndex: 0 
	    }, 
	    delay: 4000,
	    timeout: 7000,
	    pause: 1
	});
	PEPS.rollover.init();
	$('.ajax').ajaxify({
		target: '#ajax',
		loadHash: true,
        loading_fn: function() { },
		onStart: function(){
			$("ul.sf-menu").hideSuperfishUl();
			
			$("#menu").slideUp("fast");
			$("#loader").slideDown("fast");
		},
		onError: function(){
			window.alert("Sorry, it appears there was a problem with your request. Make sure you are connected to the internet and try again.");
		},
		onComplete: function(){
			PEPS.rollover.init();
			$('input[type=radio]').checkbox({
			  cls:'jquery-checkbox',
			  empty: 'img/empty.png'
			}); 
			$('input[type=checkbox]').checkbox({
			  cls:'jquery-checkbox',
			  empty: 'img/empty.png'
			}); 
			
			$("#loader").slideUp("fast");
			$("#menu").slideDown("fast");
            $('.form').ajaxForm({
            	type: 'post',
            	success: function(responseText) { 
  					$.jGrowl(""+ responseText +"", { header: 'Shopping Cart' });
  					$("#carter").slideDown("fast");
  					return false;   
  				}
            }); 
		    $('.contactform').ajaxForm({
		    	type: 'post',
		    	beforeSubmit: validate,
		    	success: function(responseText) { 
		    			$(".contactform").slideUp("normal");
						$(".contactform").html(""+ responseText +"");
						$(".contactform").slideDown("fast");
						return false;   
					}
		    }); 

		}
	}); 
}); 