$(document).ready(function(){
	//external link setup
	$("a[href^='http://']").each(function(){
		$(this).attr({
			href: "javascript:visit('" + $(this).attr('href') + "')"
		});
	});
	//find current
	var cDir = window.location.pathname.topLevelDir();
	$("#mainMenu li a").each(function(){
		if( $(this).attr("href").topLevelDir() == cDir ){
			$(this).css("background-position","0px -130px").addClass("current");
		}
	});
	
	//background rollovers setup
	$(".rollover").not(".current").hover(
		function () {
			var h = "0px -" + $(this).css("height");
			$(this).css("background-position",h);
		},
		function () {
			$(this).css("background-position","0px 0px");
		}
	);
	//mailto setup
	$(".mailto").each(function(){
		var name = $(this).attr("title");
		var html = "<a href='mailto:" + name + "@ainsliewear.com'>" + name + "@ainsliewear.com</a>";
		$(this).html(html);
	});
	
	$("#bannerTabWrapper,#mapWrapper").pngFix();
	
	//map
	$("#locationDisplay").click(function(){
		$("#mapWrapper").show()
	}).keyup(function(){
		$(this).val("");
	});
	
	var mT;
	
	$("#mapPopup").mouseout(function(){
		mT = setTimeout(function(){
			$("#mapWrapper").hide();
		},400);
	});
	
	$("#mapWrapper").contents().mouseover(function(){
		clearTimeout(mT);
	});
	
	$("#mapList li a").hover(
		function(){
			var t = $(this).attr("rel");
			$("#mapGraphic img").css("display","none").filter("."+t).css("display","block");	
		},
		function(){
			$("#mapGraphic img").css("display","none").filter(".map0").css("display","block");
		}
	).click(function(){		
		var x = $(this).text();
		$("#locationDisplay").val(x);
		var y = $(this).attr("rel");
		y = y.replace(/map/,"");
		$("#location").val(y)
		$("#mapWrapper").hide();
	});
	
	$("#searchResults tr:has(td):odd").addClass("odd");
	
	//events
	$("#right.events .item:first").css("paddingTop","25px");
	
	//login
	var l = getQueryVariable("login");
	if( l == "nomatch" ){
		$("#reg_form fieldset").prepend("<p class='error'>Your username/password is incorrect</p>")
	}
	
	var l = getQueryVariable("username");
	if( l == "nomatch" ){
		$("#reg_form fieldset").prepend("<p class='error'>That username is not on file.</p>")
	}
	
	if( l == "match" ){
		$("#reg_form fieldset").prepend("<p class='error'>Your password has been emailed to you.</p>")
	}
	

});