/* Author: 
	
*/

jQuery(function($){


	if ($("#home").size() > 0 ) {
		$('#facebookWall').fbWall({
			id:'coolicious',
			accessToken:'206158599425293|80c3640d86fdb66a3b293b10.1-100000698424225|xNIdroRt_YUp3GQQUK_DncT-kJQ',
			showGuestEntries:false,
			showComments:false,
			max:1,
			timeConversion:24
		});
	};

	// Top navigation
	/*
	$(".top-nav-control").click(function (e){
		if($(".top-nav").height() == 26){
			if ($(".subnav").size() > 0) {
				$("body").animate({"background-position": " 0 27"});
			} else {
				$("body").animate({"background-position": " 0 0"});
			}
			$(".top-nav").animate({height: 0});
			$("header").animate({"padding-top": 45});
			$(this).animate({top : 0});
		} else{
			if ($(".subnav").size() > 0) {
				$("body").animate({"background-position": " 0 50"});
			} else {
				$("body").animate({"background-position": " 0 26"});
			}
			$(".top-nav").animate({height: 26});
			$(this).animate({top : 26});
			$("header").animate({"padding-top": 71});
		}
		e.preventDefault();
	});
	*/
	//Social media section

	$(".social nav a").live("click", function (e){
		e.preventDefault();
		if (!$(this).hasClass("on")) {
			$(".social nav a.on").removeClass("on")
			$(this).addClass("on");
			var media = $(this).attr("id");
			$(".social article").hide();
			$(".social article."+media).fadeIn();
		};
	});


	// Products accordian
	$(".product-desc .accordian article").hide();
	$(".product-desc .accordian.trade article.active").show();

	$(".product-desc .accordian h4").click("live", function (){
		if (!$(this).next("article").hasClass("active")) {
			$(".accordian article:visible").slideUp();
			$(".accordian article").removeClass("active");

			$(this).next("article").slideDown();
			$(this).next("article").addClass("active");
		}else{
			$(this).next("article").removeClass("active");
			$(this).next("article").slideUp();
		};
	});

	//product fade
	$('.product-fade img:not(":first")').hide();
    var count=0;
    var countImages = $('.product-fade img').size();

    if(countImages>1){
      setInterval(nextImage,4000); //The number here dictates the length of time between the animation
    }

    function nextImage() {
      $('.product-fade img:eq('+count+')').fadeOut(1500); //Length of FadeOut transition
      if(count<countImages-1){
        count++;
      } else {
        count=0;
      }
      $('.product-fade img:eq('+count+')').fadeIn(1500); //Length of FadeIn transition
    }

	//contact form
	$("#contactForm input").focus(function(){
		if ($(this).val() == $(this).attr("name") || $(this).val() == "first name") {
			$(this).val("");
		};
	});

	$("#contactForm input").blur(function(){
		if ($(this).val() == "") {
			if($(this).attr("name") == "address-address1"){	
				$(this).val("address 1");
			} else if($(this).attr("name") == "address-address2"){	
				$(this).val("address 2");
			} else if($(this).attr("name") == "address-town"){	
				$(this).val("town");
			} else if($(this).attr("name") == "address-postcode"){	
				$(this).val("post code");
			} else if($(this).attr("name") == "address-county"){	
				$(this).val("county");
			} else if($(this).attr("name") != "forename"){	
				$(this).val($(this).attr("name"));
			} else{
				$(this).val("first name");
			}
		};
	});

	$("#contactForm-comments").focus(function(){		
		if ($(this).text() == "comments") {
			$(this).text("");
		};
	});

	$("#contactForm-comments").blur(function(){
		if ($(this).text() == "") {	
			$(this).text("comments");
		};
	});
	
	$("#contactForm-phone").focus(function(){		
		if ($(this).text() == "phone") {
			$(this).text("");
		};
	});

	$("#contactForm-phone").blur(function(){
		if ($(this).text() == "") {	
			$(this).text("phone");
		};
	});
	
	$("#contactForm-address-address1").focus(function(){				
		if ($(this).val() == "address 1") {
			$(this).val("");
		};
	});

	$("#contactForm-address-address2").focus(function(){				
		if ($(this).val() == "address 2") {
			$(this).val("");
		};
	});

	$("#contactForm-address-town").focus(function(){				
		if ($(this).val() == "town") {
			$(this).val("");
		};
	});

	$("#contactForm-address-county").focus(function(){				
		if ($(this).val() == "county") {
			$(this).val("");
		};
	});

	$("#contactForm-address-postcode").focus(function(){				
		if ($(this).val() == "post code") {
			$(this).val("");
		};
	});


	$("#signupform input").focus(function(){
		if ($(this).val() == "enter name" || $(this).val() == "enter email address") {
			$(this).val("");
		};
	});

	$("#signupform input").blur(function(){
		if ($(this).val() == "") {
			if($(this).attr("name") == "forename"){	
				$(this).val("enter name");
			}else{
				$(this).val("enter email address");
			}
		};
	});

});
