
$(document).ready(function(){

	/*-------------------------------------------------------------------------------------------*/
	 $('input#newsletter').attr('checked', true);
	/*-------------------------------------------------------------------------------------------*/
	/*----Special offers slideshow */
	if ($('#specialOfferSlideshow').length) {
		$('#specialOfferSlideshow').cycle({ 
			fx:     'fade', 
			timeout: 4500, 
			speed:   10, 
			speedIn: 1000,
			speedOut: 1000
		 });
	 }
	/*---Saves slideshow--*/
	if ($('#slideshow').length) {
		$('#slideshow').cycle({ 
			fx:     'scrollUp', 
			timeout: 5500, 
			speed:   10, 
			speedIn: 1000,
			speedOut: 1000
		 });
	 }
	if ($('#slideshow_small').length) {
		$('#slideshow_small').cycle({ 
			fx:     'scrollUp', 
			timeout: 5500, 
			speed:   10, 
			speedIn: 1000,
			speedOut: 1000
		 });
	 }
	/*--------------------------------------------------------------------------------------------*/
	//----Hovers
	$('#getQuote img, #get_quote_small img').not('#slideshow img').hover(function() {
		var src = $(this).attr("src").match(/[^\.]+/) + "_hover.gif";
        $(this).attr("src", src);	
	},function() {
		var src = $(this).attr("src").replace("_hover", "");
		$(this).attr("src", src);
	});
	/*-----------------------------------------------------------------------------------------------*/
	
	$('#EmailForm table tr').hover(function() {
		$(this).addClass('row_hover');									
	},function () { 
		$(this).removeClass('row_hover');	
	});
	/*--------------------------------------------------------------------------------------------------*/
		//Tooltips
	$('.tooltip').hover(
		function(e) {
		var tip = $(this).next('span').html();
		$('body').append('<div class="toolTipWrapper">'+tip+'<div class="toolTipBottom">&nbsp;</div></div>');
		var myheight = $('.toolTipWrapper').height();
		var pos = $(this).position();
    	$('body').find('.toolTipWrapper').css( { "left": pos.left+7 + "px", "top":pos.top-myheight-50 + "px" } );
		$('.toolTipWrapper').fadeIn('slow');
	},
	function() {
		$('.toolTipWrapper').fadeOut(100);
		$('body').find('.toolTipWrapper').remove();
	});
	if ($('.date-pick').length) {	
		$('.date-pick').datePicker({
				startDate:'01/01/1900',
				clickInput:true
		});
	}
	if ($('.date-pick-noback').length) {	
		$('.date-pick-noback').datePicker({
				clickInput:true
		});
	}
	

	
	$("input[name='main_fleet_activities']").change( function() {
	  if ($(this).val() == 'other') {
	 	$("input[name='main_fleet_activities_other']").removeAttr('disabled');
	  } else {
		$("input[name='main_fleet_activities_other']").val(''); 
		$("input[name='main_fleet_activities_other']").attr('disabled', true);
	  }
	});
	

	$("select[name='drivers']").change( function() {
	  var data = $(this).val();
	   if (data==2) {
		   $("select[name='vehicles']").removeAttr('disabled');
	   } else {
		   $("select[name='vehicles']").attr('disabled', true);
	   }
	});

	
	$("input[name='date_finish']").change( function() {
	  var start = $("input[name='date']").val();
	  var finish = $(this).val();
	  
	    var d1 = Date.parse(start);
		var d2 = Date.parse(finish);
		
		if (d2 < d1) {
		  $(this).val('');
		  $('body').find('#date_validation').html('Finish date can not be before start date!');
		} else {
		  $('body').find('#date_validation').html('');	
		}
	});
 
	$("select#fleet_before").change( function() {
	  if ($(this).val() != '') {
	 	$("textarea#number_of_years").removeAttr('disabled');
	  } else {
		$("textarea#number_of_years").attr('disabled', true);
	  }
	});

	$('#check').click( function () {
		$('form#EmailForm').map(function(){ 
			array = $.makeArray(this.elements);
			for (var i = 0;i<array.length;i++) {
				if ((array[i]).value != '') {
				trigger = true;
				} else {
				trigger = false;
				}
			}
		});
		if (trigger) {
			var name = $("input[name='name']").val();
			var surname = $("input[name='surname']").val();
			var amount_to_pay = $("input[name='amount_to_pay']").val();
			var two = amount_to_pay.substring(amount_to_pay.length-2,amount_to_pay.length);
			var one = amount_to_pay.substring(0,amount_to_pay.length-2)
	
			if (confirm('Please confirm details:\nName: '+name+'\nSurname: '+surname+'\nAmount to pay: \u20AC'+one+'.'+two)) {
				return true;
			} else {
				return false;
			}
			
		} else {
			return true;	
		}
	}); 
	 
	$('#check_cc').click( function () {
		
			var level_of_cover = $("select[name='level_of_cover']").val();
			var cover_start_date = $("input[name='cover_start_date']").val();
			var confirmInput = $("input[name='confirm']");

	if (level_of_cover !='' && cover_start_date !='' && confirmInput.is(':checked') ) {		
			var two = level_of_cover.substring(level_of_cover.length-2,level_of_cover.length);
			var one = level_of_cover.substring(0,level_of_cover.length-2)
	
			if (confirm('Please confirm details:\nLevel of cover: \u20AC'+one+'.'+two)) {
				return true;
			} else {
				return false;
			}
			
		} else {
			return true;	
		}
	}); 
	
	if ($('a.fancy').length) {		
		$("a.fancy").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 800,
			'frameHeight': 550,
			'hideOnOverlayClick': false
		});
	}
					  
}); //Close document.ready

$(window).bind("load", function() {							
    //-----------  Preload images for 
	$('#loading').hide();
	$('#slideshowWrapper').fadeIn('slow');

});
