$(function(){
	
	// An attempt at an animated loading data message - more below PS PS 081030.
	$("#leftnavMenu a.subnavLinks, #leftnavMenu a.headline, #globalNavmain a").click(function(){
		$("div#standardPage.loading").fadeOut();
		$("div#ajaxloading").fadeIn();
	});
	
	// Hook to the delete-buttons/links in the basket.
	$("a.basketdeleterow").click(function(){
		$("input", $(this).parent().parent().get(0)).get(0).value = "0";
		$("form#basketform").each(function(){
			this.action = "?_com=_basket&_act=_updatebasket";
			this.submit();
		});
	});
	
	// Validate all forms that we're supposed to validate.
	$("form.validate").validate({
		// Place the error message last in the parent element to make checkboxes and such look good.
		errorPlacement: function(error, element){
			element.parent().append(error);
			element.parent().addClass("contains" + element.get(0).type.toLowerCase());
		}
	});
	
jQuery.validator.addMethod("alphanumeric", function(value, element) {
	return this.optional(element) || /[A-Za-z0-9]\S+$/i.test(value);
}, "a-z A-Z 0-9");
	 
	$("form.validateajax input#Email").each(function(){
		$(this).rules("add", {
			required: true,
			email: true,
			remote: "ajax.php"
		});
	});
	
	$("form.validateajax input#Login").each(function(){
		$(this).rules("add", {
			required: true,
			remote: "ajax.php"

		});
	});
	
	$("form.validateajax input#Password").each(function(){
		$(this).rules("add", {
			required: true
		});
	});
	

	
	// Show the loading-thing when we're loading stuff with ajax.
	$("div#ajaxloading").ajaxStart(function(){
		// This is where you'd want to reposition div#ajaxloading maybe..
		$("div#ajaxloading").fadeIn();
	}).ajaxStop(function(){
		$("div#ajaxloading").stop().fadeOut();
	});
	
	
	// Make the products an accordion.
	$("div.product h2,div.product a.moreinfo").bind("click", function(){
		$("div.productdetails:visible").slideUp("slow");
		$(this).parents("div.product").next("div.productdetails").slideDown("slow");
	});

	// More info - Less info toggle thingie PS 081023.
	$('div.less').hide();

	$("div.infocontainer a.moreinfo").bind("click", function(){
		$(this).parents("div.infocontainer").children("div.more").hide();
		$(this).parents("div.infocontainer").children("div.less").show();
		$(this).parents("div.infocontainer").next("div.infodetails").slideDown("slow");
	});
	
	$("div.infocontainer a.lessinfo").bind("click", function(){
		$(this).parents("div.infocontainer").next("div.infodetails").slideUp("slow");
		$(this).parents("div.infocontainer").children("div.less").hide();
		$(this).parents("div.infocontainer").children("div.more").show();
	});
	
	$("div.infodetails a.lessinfo").bind("click", function(){
		$(this).parents("div.infodetails").slideUp("slow");
		$(this).parents("div.infodetails").prev("div.infocontainer").children("div.less").hide();
		$(this).parents("div.infodetails").prev("div.infocontainer").children("div.more").show();
	});
	

	// Map Link Hover - to replace MM code extravaganza PS 081029.
	$('a.map').hover(function() {

		var getLan = "/pics/sweden_map_"+this.id+".gif";
	
		$('img#swemap').attr("src", getLan);
			}, function() {
		$('img#swemap').attr("src","/pics/sweden_map.gif");
	});
	
	
	// Always submit the payment form right away.
	// We don't need this any more.
	//$("form#paymentform").submit();	
	
	// Add zebra striping to tables that wants it.
	$("table.zebra tbody tr:odd").addClass("udda");

	// The tabber 
	$("div.tabber").addClass("tabberlive");
	// Add the tab list and store in a variable to speed things up a notch
	$("div.tabberlive").prepend("<ul class=\"tabbernav\"></ul>");
	var ul = $("div.tabber ul");
	// Add the tabs
	$("div.tabberlive div.tabbertab").each(function(){ul.append("<li><a href=\"#\">" + $("h2", this).html() + "</a></li>");});
	$("div.tabberlive ul.tabbernav li a").click(function(){
		$("div.tabberlive div.tabbertab").addClass("tabbertabhide");
		$("div.tabberlive ul.tabbernav li").removeClass("tabberactive");
		$(this).parent().addClass("tabberactive");
		$($("div.tabberlive div.tabbertab").get($(this).parents("li").prevAll().length)).removeClass("tabbertabhide");
	});
	$("div.tabberlive ul.tabbernav li:first a").click();

	// An attempt at an animated loading data message - end bit PS PS 081030.
	$("div#ajaxloading").fadeOut();
	$("div#standardPage").fadeIn();
});