$(document).ready(function(){

	// Remove No Javascript Tag
	$("body").removeClass("nojs");

	// Main Menu Drop Downs
	$("#nav li")
		.css("cursor","pointer")
		.hover(function(){
			$(this).children("ul").slideDown(25);
			$(this).children("a").focus();
		},function(){
			$(this).children("ul").slideUp("fast");
		})
		.find("a").attr("title","");

	// Main Search Box Filters Creation
	$("#searchfilters fieldset")
		.hide()
		.each(function(){
			$(this).children("select")
				.each(function() {
					// Create Drop Down Containers and Title Container for each HTML Select
					$("#searchfilters").append('<div class="flt_cnt" id="flt_cnt' + $(this).attr("id") + '"><div><span class="flt_cnt_title">&nbsp;&nbsp;&nbsp;' + $(this).parent().find("label").text() + '</span>:<span class="flt_cnt_val">All</span></div><ul></ul></div>');
					
					// Create Link for each Option
					$(this).children("option").each(function() {
						$("#flt_cnt" + $(this).parent().attr("id")).children("ul")
							.append('<li><a onclick="document.getElementById(\'' + $(this).parent().attr("id") + '\').value=\'' + $(this).attr("value") + '\';"' + (($(this).attr("title") == "") ? '' : ' title="' + $(this).attr("title") +'"') + (($(this).attr("selected") == true) ? ' class="current"' : '') + '>' + $(this).html() + '</a></li>');
					
						// Update Title if selected
						($(this).attr("selected") == true) ? $("#flt_cnt" + $(this).parent().attr("id") + " .flt_cnt_val").html($(this).html()) : '';
					});
			});
	});
		
	// Main Search Box Filters Actions
	$("#searchfilters .flt_cnt")
		.css("cursor","pointer")
		.hover(function(){
			$(this).children("ul").show();
		},function(){
			$(this).children("ul").hide();
		})
		.find("li").hover(function(){
			$(this).children("a").focus();
		},function(){
		})
		.find("a")
			.attr("title","")
			.click(function(){
				$(this).parents("ul")
					.hide()
					.find("a").removeClass("current");
				$(this)
					.addClass("current")
					.parents(".flt_cnt").find(".flt_cnt_val").html($(this).html());
				f_flt_grp_w();
			});

	// Trap Lost onMouseOut Events
	$("#searchbox").hover(function(){
		$(".flt_cnt ul").hide();
	},function(){
	});

	// Filter Group Widths
	function f_flt_grp_w() {
		// Max Width Available
		var v_flt_grp_cnt_w_max = ($("#searchfilters").width());
		// Total Width of All Filter Groups and Number of Filter Groups
		var v_flt_grp_all_w = 0;
		var v_flt_grp_all_num = 0;
		// IE needs the DIV overflow visible to calculate contents width
		$("#searchfilters .flt_cnt div").css({width:"",overflow:"visible"}).each(function(){
			v_flt_grp_all_w += $(this).width();
			v_flt_grp_all_num++;
		});
		// Is Total Width Greater Than Max Width Available
		if (v_flt_grp_all_w > v_flt_grp_cnt_w_max) {
			// Max Filter Group Width
			var v_glt_grp_w_max = v_flt_grp_cnt_w_max/v_flt_grp_all_num;
			// Is Any of the Filter Groups wider than (MaxWidth)/(NumGroups)
			$("#searchfilters .flt_cnt div").each(function(){
				//alert($(this).width() + " " + v_glt_grp_w_max);
				if ($(this).width() > v_glt_grp_w_max) {
					$(this).css({width:v_glt_grp_w_max,overflow:"hidden"});
					//alert("here");
				}
			});
		}
	}
	f_flt_grp_w();

	$(window).resize(function(){
		f_flt_grp_w();
	});

	// Main Search Box Submit (to remove grid co-ords from URL submission)
	$("#searchsubmit").click(function(){
		$(this).parents("form").submit();
		return false;
	});





	// Prepare TimeStamp to ensure fresh data
	var d = new Date();
	// Cart
	$.getJSON(v_url_rel + "store/cart/mini/default.codebehind.asp",{
		't':d.getTime()
	},function(data){
		$("#basket .minicart .items")
			.html(data.v_ord_items + " Items")
			.click(function(){
				location.href = v_url_rel + "store/cart/";
				return false;
			});
		$("#basket .minicart .total").html(data.currency_sign + data.v_ord_total.toFixed(2));
	});



























});