$(document).ready(function(){
	
	$("#depots ul li").hover(function(){
		$("#map .pin#depot_pin_" + $(this).attr("id").substr(11)).addClass("highlighted");
	}, function(){
		$("#map .pin#depot_pin_" + $(this).attr("id").substr(11)).removeClass("highlighted");	
	});
	
	$("#map .pin").hover(function(){
		$("#depots ul li#depot_link_" + $(this).attr("id").substr(10)).addClass("highlighted");
	}, function(){
		$("#depots ul li#depot_link_" + $(this).attr("id").substr(10)).removeClass("highlighted");	
	});
	
	$(".vehicle").click(function(){
		location.href = $(this).find("a").attr("href");
	});
	
	$('#banners').cycle({
		fx: 'fade',
		speed:  2000,
		timeout:  5000,
		pause: 1
	});
	
	$('#newsTicker').cycle({
		fx: 'scrollUp',
		speed:  1000,
		timeout:  5000,
		pause: 1
	});
	
	$("#accountForm select#customer_type").change(function(){
		if ($(this).val()) {
			if ($(this).val()=="Limited Company") {
				$("#fieldsInd").hide();	
				$("#fieldsLtd").slideDown();
			}
			else
			{
				$("#fieldsInd").slideDown();	
				$("#fieldsLtd").hide();
			}
		}
		else
		{
			$("#fieldsInd,#fieldsLtd").slideUp();
		}
	});
		
	$("#accountForm").submit(function(){
		error = false;
		
		
		if ($("#accountForm #credittermsConfirm:checked").val() == null) {
			$("#accountForm #credittermsLabel").css("color", "#f00");
			error = true;		
		}
		else
		{
			$("#accountForm #credittermsLabel").css("color", "#000");
		}
		
		$("#accountForm *.required:visible").each(function(index, field){
			$(this).siblings(".error").remove();
			if ($(this).val()) {
				
			}
			else
			{
				error = true;
				$(this).parent().append('<p class="error">' + 'Required' + '</p>')	
			}
		});		
			
		if (error) {
			alert("Please complete all required fields.");
			return false;
		}
		else
		{
			return true;	
		}
	});
	
});
