// A2Z Damp Proofing Functions
// Author: Christopher Hill
// Company: Chill Web Designs
// Contact: chris@chillwebdesigns.co.uk

(function($){
		  
	$(function(){
			   
		// Reset the last link margin.
		$('#nav ul li:last').css({margin:'0'});	
		
		// Set Copyright year "All Rights Reserved - A2Z Damp Proofing İYEAR"
		$('a#copyright').append('All Rights Reserved - A2Z Damp Proofing &copy;' + new Date().getFullYear());
		
		$('.product_container img:eq(1)').css({float:'right', height:'180px', marginRight:'50px', marginTop:'85px'});
		
		
		$('.product_container form:eq(1)').css({width:'250px'});
		
		
		// Preload images function
		var cache = [];
		
  		// Arguments are image paths relative to the current page.
  		$.preLoadImages = function() {var args_len = arguments.length;for (var i = args_len; i--;) {var cacheImage = document.createElement('img');cacheImage.src = arguments[i];cache.push(cacheImage);}}

		// Preload pay button and css / xhtml hover images.
		jQuery.preLoadImages('images/validXHTML-hover-trans.png', 'images/validCSS-hover-trans.png', 'images/button-hover-trans.png', 'images/directions-hover-trans.png');
		
		// Postcode onload function.
		$("#dir_val").val("Enter your postcode").css({color:"#666", fontStyle:'italic'});
	 
	 	if ($.browser.msie){$("#dir_val").css({paddingLeft:'5px', width:'120px'});}
	 
		// Postcode Input Box Clear Function		
		$('#dir_val').focus(function(){
			if($("#dir_val").val() == "Enter your postcode"){ 
			$("#dir_val").val("").css({color:"#333", fontStyle:'normal',borderColor:"red"});
			}
			});
	
		// Postcode Input Box Update Function
		$('#dir_val').blur(function(){
	
		if($("#dir_val").val() == ""){$("#dir_val").val("Enter your postcode").css({borderColor:"#ccc",color:"#666", fontStyle:'italic'});}});
		
		$('#dir_but').click(function(){
		
		if(($("#dir_val").val() == "Enter your postcode") || ($("#dir_val").val() == "") || ($("#dir_val").val().length < 4)){
		$("#dir_val").css({borderColor:"red",color:"#333"}).focus();
		return false;}
		});
	
		// Top navigation animation function.
		$("#nav").each(function(){
								  
			var me = $(this); 
			var	noop = function(){};
			
			if ($.browser.msie && $.browser.version == 7 ){
			var $back = $('<li class="slider"></li>').prependTo(me);
			}
			
			else{
			var $back = $('<li class="slider"></li>').appendTo(me);
			}
			
			var $li = $("li", this);
			var curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
			
			$li.not(".slider").hover(function(){move(this);}, noop);
	
			$(this).hover(noop, function(){move(curr);});
	
			setCurr(curr);
	
			function setCurr(el){$back.css({"marginLeft":el.offsetLeft + "px", "width":"100px"});curr = el;};
	
			function move(el){$back.each(function(){$.dequeue(this, "fx");}).animate({width: 100, marginLeft: el.offsetLeft}, 350, "linear");};
	
		});
	
	});		
})(jQuery);

