	$(function() {	
	
		var i = "index.php";
		var index = window.location.pathname.lastIndexOf("/") + 1;
		var thisPage = window.location.pathname.substr(index);
			
		$("#navigation li a").each(function(index) { 
			var el = $(this);
			if (el.attr("href") == thisPage || el.attr("href") == "./" && thisPage == i || el.attr("href") == "./" && thisPage === "") {
				el.parent().addClass("selected");
			}
		});	
		
		$('#signup').hide();
		$("#navigation li.newsletter a span").fadeTo(5, 0);
		$("#navigation li.newsletter a")
			.hover(function() {
				$(this).children('span').stop().fadeTo("fast", 1);
			}, function() {
				$(this).children('span').stop().fadeTo("fast", 0);
			})
			.click(function(e) {
				e.preventDefault();
				if ($(this).hasClass("active")) {
					$('#signup').slideUp("fast");
					$(this).removeClass("active");
				} else {
					$('#signup').slideDown("fast");
					$(this).addClass("active");
				}
			});
		
		$("#navigation li:not(.selected) a.parent").hover(
			function () {
				$(this).stop().animate({ backgroundColor: "#eee" }, 'fast');
			}, 
			function () {
				$(this).stop().animate({ backgroundColor: "#fbfbfb" }, 'fast');
			}
		);
		
		$('#search input[type=text]')
			.focus(function() {
				if ($(this).val() === $(this).attr("title")) {
					$(this).val("");
				}
				$(this).parent().addClass("active");
			})
			.blur(function() {
				if ($(this).val() === "" || $(this).val() === $(this).attr("title")) {
					$(this).val($(this).attr("title"));
				}
				
				$(this).parent().removeClass("active");
			});
		
		$('#search input')
			.val("")
			.liveUpdate('#products')
			.val($('#search input').attr("title"));
			
		$('#reset-search').click(function(e) {
			e.preventDefault();
			$('#search input')
				.val("")
				.keyup()
				.val($('#search input').attr("title"));
			$(this).parent().hide();
		});	

		$(function() {
			$('#slideshow').after('<div id="pager">').cycle({ 
				fx:		 'fade', 
				speed:	 1000, 
				timeout: 7000, 
				pager:	'#pager' 
			});
		});
		
		$('#contact-form').validate({
			errorPlacement: function(error, element){
				if (element.is("textarea")) {
					error.addClass("textarea");
				}
				error.insertAfter(element).hide().slideDown();
			}, 
			messages: {
				email: "Please enter your email address.",
				enquiry: "Please enter your enquiry.",
				name: "Please enter your name."
			}
		});
		
	});
