$(function(){
	$("ul#nav li").hover(function(){
		var ul = $('.storage-locations .content'); 
		var pos = $(this).css("background-position");
		
		var maxleft = (parseInt($("body").css("width"))/2)-382;
		if (pos == 'undefined' || pos == null) {
			pos = $(this).css("background-position-x"); //die in hell
		} else {
			pos = pos.split(" ")[0];
		}

		$(this).css('background-position', pos+' -55px')

		if($(this).hasClass('storage-locations')){
			if (ul.is(":animated")) {
				//alert('Animated');
				ul.stop()
				ul.css("left", maxleft);
				ul.css("height", "auto");
				ul.slideDown("normal");
			} else {
				//alert('Normal');
				//ul.css("display", "none");
				ul.hide();
				ul.css("left", maxleft);
				ul.slideDown("normal");
			}
		}
	},
	function(){
		var ul = $(this).children("div"); 
		var pos = $(this).css("background-position");
    if (pos == 'undefined' || pos == null) {
        pos = $(this).css("background-position-x"); //die in hell
    } else {
        pos = pos.split(" ")[0];
    }
	
		if(ul.is(":animated")){
			ul.stop()
			.css("height", "auto")
			.slideUp("fast");
		}
		else{
			ul.slideUp("fast");
		}
		
		$(this).css('background-position', pos+' 0px')
	});		
});

$(function(){
	$("#chosen").click(function(){
		var content = $('#holder .content'); 
		if (content.attr('rel')==1) {
			content.attr('rel',0)
			content.stop();
			content.slideUp("normal");
		} else {
			$("#holder").click(function(e) {
				e.stopPropagation(); 
			});
			$("body").click(function() {
				var content = $('#holder .content'); 
				content.attr('rel',0)
				content.stop();
				content.slideUp("normal");
			});
			content.attr('rel',1)
			content.hide();
			content.slideDown("normal");
		}
	});
	$("#holder a").click(function(){
		var content = $('#holder .content');
		content.attr('rel',0)
		content.stop();
		content.slideUp("normal");
		$("#location").val($(this).attr("href"));
		$("#chosen").html($(this).html());
		return false;
	});
});

