// JavaScript Document

// preload images function
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
//preload images
$.preloadImages("images/templates/contact_btn_over.gif", "images/templates/query_btn_over.gif", "images/templates/arrow_over.gif");

// shortcut for the $(document).ready(callback) notation
$(function() {

	// rollover function
	$(".rollover").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".gif","_over.gif#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.gif#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.gif#hover",".gif");
				$(this).attr("src",oldSrc);
			}
		}
	);
	
	$('#image_alt').css('opacity',0.6)
	
	$('#image_cycle').cycle({ 
    	fx:    'fade',
		timeout: 8000,
    	speed:  1500,
		before:  onBefore, 
    	after:   onAfter 
	});
	
	function onBefore() { 
    	$('#image_alt').animate({'bottom': -30}, 'fast');	
	} 
	function onAfter() { 
    	$('#image_alt').html('<p>' + this.alt + '</p>');
		$('#image_alt').animate({'bottom': 0}, 'fast');
	}
	
	// validate forms
	if ($("#contact").length > 0 || $("#get_a_quote").length || $("#training_contact").length) {
		$("#form").validate();
	}
	
	// secure forms
	$(".warning").remove();
	$.get('http://www.denbytransport.co.uk/scripts/token.php',function(txt) {
		$('.secure').append('<input type="hidden" name="ts" value="'+txt+'" />');
	});
	
	
	
});