jQuery(function( $ ){
	//$(".bubble").corner("15px");
	//$(".button_reserve").corner("5px");
		
	$('li.page_item a.click, li.last a.click,button.click').each(function(){
		$(this).click(function(event){
			/*var parent = $('#'+$(this).attr("parent")).find(".contentlist").position();
			var num = parseFloat(parent.top)-88;
			$(window).stop().scrollTo(num,800);*/
			
			//prevent the default action for the click event
	        event.preventDefault();
	 
	        //get the full url - like mysitecom/index.htm#home
	        var full_url = $(this).attr("href");
	 
	        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
	        var parts = full_url.split("#");
	        var trgt = parts[1];
	 
	        //get the top offset of the target anchor
	        var target_offset = $("#content-"+trgt).offset();
	        var target_top = target_offset.top;
	 
	        //goto that anchor by setting the body scroll top to anchor top
	        $('html, body').animate({scrollTop:target_top-60}, 500);	
	     });
	});
	
	
	Cufon.replace('.navigation li a,#logo h1,.story_so_far,h3.view_our_fleet', { 
	    fontFamily: 'Tw Cen MT Condensed'/*,
	     hover: {
	        color: '#C54525'
	    }*/
	});
	
	Cufon.replace('#logo h1,.firsthalf,.tel,.underline', { 
	    fontFamily: 'Helvetica World'
	});
	
	/*Cufon.replace('.underline', { 
	    fontFamily: 'HelveticaNeueLT Com 75 BdOu'
	});*/
	
	Cufon.replace('.reservation h2, .featureslist li', { 
	    fontFamily: 'HelveticaRounded LT Bold'
	});
	
	/*Cufon.replace('.hp_details h2', { 
	    fontFamily: 'Tw Cen MT Condensed'
	});*/
	
	Cufon.replace('#content-about p, .hp_details p', { 
	    fontFamily: 'Georgia'
	});
	
	$("#date,#drop-date").datepicker();

	
	$("#reservation,#contactus").submit(function(){
		var formSub = $(this);
		formSub.find(".response-output").slideUp();
		formSub.find(".required").each(function(){
		  		$(this).attr({value:$(this).val() ? $(this).val() : "This is a required field."});
		  		
		  		if($(this).val()=="This is a required field."){
		  			$(this).addClass("validation-failed");	
		  		}else{
		  			$(this).removeClass("validation-failed");
		  		}		  		
		  });
		  
		 // console.log(check()+" "+formSub.find(".required-entry").length);
		  		  
		  if(check()==formSub.find(".required").length){
		  	  formSub.find('.ajax-loader').show();
			  formSub.find('#submit,#contant_submit').attr({disabled:"disabled"});
			  $.post($(this).attr('action'),$(this).serialize(), function(data){
				   //alert("Data Loaded: " + data);
				   //console.log(data);
				   formSub.find('#submit,#contant_submit').removeAttr("disabled");
				   formSub.find('.ajax-loader').hide();
				   if(data.toLowerCase()!="mail sent"){
				   		clearForm();
				   		$('#dialog #reserve_output').html(data);
				   		var dataLoad = $('#dialog #reserve_output').find("#extraData");
				   		$('#dialog').dialog({
							autoOpen: true,
							width: 450,
							buttons: {
								"Confirm Reservation": function() { 
									if(dataLoad.attr('price')!=""){
										window.location = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&bn=wa_dw_3.0.3&business="+dataLoad.attr('email')+"&item_name="+dataLoad.attr('name')+"  Reservation&item_number="+dataLoad.attr('car')+" Reserve No: "+dataLoad.attr('confirm')+"&amount="+dataLoad.attr('price')+"&currency_code=USD&shipping=0&shipping2=0&handling=0&undefined_quantity=0&no_shipping=1&no_note=0&return="+dataLoad.attr('site')+"&cancel_return="+dataLoad.attr('site')+"&cn=Reservation%20For%20"+dataLoad.attr('name')+"&tax=0&lc=US";
									}
									$(this).dialog("close"); 
								}
							}
						});
				 
				   		
				   }else{
				   		//formSub.find(".response-output").html(data).slideDown();
				   		$('#dialog #reserve_output').html(data);
				   		
				   		$('#dialog').dialog({
							autoOpen: true,
							width: 200,
							buttons: {
								"Ok": function() { 
									$(this).dialog("close"); 
									 clearForm();
								}
							}
						});
				   }
			  });
			  return false;	
		  }else{
		  	 return false;
		  }
		  function clearForm(){
		    formSub.find("input,textarea").each(function(){
		        $(this).val("");
		    });
		  }
		  
		  function check(){
		  	var checker = 0;
		  	formSub.find(".required").each(function(){
		  		if($(this).parent().css("display")!="none")
		  		{
			  		if($(this).val()!="This is a required field."){
			  			 checker++;
			  		}else{
			  			//get the top offset of the target anchor
				        var target_offset = $(this).offset();
				        var target_top = target_offset.top;
				 
				        //goto that anchor by setting the body scroll top to anchor top
				        $('html, body').animate({scrollTop:target_top-60}, 500);
			  		}
		  		}
		  		
		  	});
		  	
		  	//console.log(checker);
		  	return checker;
		  }
		 return false; 
	});
	
	$('input[name=payment]').change(
		function(){
		//alert($(this).val());
			if($(this).val().toLowerCase()=="pay"){
				$(".pay").each(function(){
					$(this).slideDown();
				});
			}else{
				$(".pay").each(function(){
					$(this).slideUp();
				});
			}
			//$('input[name=mode]').val($(this).val());
		}
		
	);
	
	$('input[name=pickupmode]').change(
		function(){
		//alert($(this).val());
			if($(this).val().toLowerCase()=="atairport"){
				$(".pickupmode_ataddress").slideUp(function(){
					$(".pickupmode_atairport").slideDown();
				});
				
				
			}else{
				$(".pickupmode_atairport").slideUp(function(){
					$(".pickupmode_ataddress").slideDown();
				});
			}
		}
		
	);
	
	
	$('input[name=dropmode]').change(
		function(){
		//alert($(this).val());
			if($(this).val().toLowerCase()=="atairport"){
				$(".dropmode_ataddress").slideUp(function(){
					$(".dropmode_atairport").slideDown();
				});
				
				
			}else{
				$(".dropmode_atairport").slideUp(function(){
					$(".dropmode_ataddress").slideDown();
				});
			}
		}
		
	);
	
	$('#reservation input[name=mode]').val("reserve");
	
	$('select[name=quick-car], select[name=quick-location], select[name=quick-drop-location]').change(
		function(){
			if($(this).val()!=""){
				$('#quickprice').html("");
				$.get($('#quickcheck').attr('action'), $('#quickcheck').serialize(), function(data){
					$('#quickprice').html(data);
				});
			}
		}
		
	);
	
	$('select[name=drop-car], select[name=Location], select[name=drop-location]').change(	
		function(){
			if($(this).val()!=""){
				$('#your-price').html("");
				$.get($('#quickcheck').attr('action')+"?drop-car="+$('select[name=drop-car]').val()+"&Location="+$('select[name=Location]').val()+"&drop-location="+$('select[name=drop-location]').val(), function(data){									
					if(data.indexOf("Selection")!=-1){
						$("#estimated-price").fadeOut(function(){
							$("#estimated-price").fadeIn(function(){
								$('#your-price').html(data);
							});
						});
					}
					else{
						$("#estimated-price").fadeOut();
					}
				});
			}
		}
		
	);
	
	$().piroBox({
      my_speed: 300, //animation speed
      bg_alpha: 0.5, //background opacity
      slideShow : 'true', // true == slideshow on, false == slideshow off
      slideSpeed : 3, //slideshow 
      close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
    });
});
