$(document).ready(function() {
	var subnav_current;
	var subnav_timeout;
	$.each($("#nav a"), function() {
		if (this.className.length > 0) {		
			var subnav_item = "#subnav_" + this.className;
			var offset_left = (Math.floor($(this).offset().left - $("#container").offset().left) - 20);
			var offset_right = (Math.floor(($(this).offset().left + $(this).width()) - $("#container").offset().left) - 20) - ($(subnav_item).width() - 8);
			if (offset_left < 715) {
				$(subnav_item).css("margin-left", offset_left);
			} else {
				$(subnav_item).css("margin-left", offset_right);
			}
			$("#nav ." + this.className).mouseover(function() {
				var targ = this.className;
				if (targ != subnav_current) {
					$("#subnav_" + targ).fadeIn("fast");
					$("#subnav_" + subnav_current).css('display', 'none');
				}
				subnav_current = targ;
				clearTimeout(subnav_timeout);
			});
			$("#nav ." + this.className).mouseout(function() {
				subnav_timeout = setTimeout(hideSubNav, 500);								
			});
		}						
	});
	$.each($("#subnav a"), function() {
		$(this).mouseover(function() {
			clearTimeout(subnav_timeout);
		});
		$(this).mouseout(function() {
			subnav_timeout = setTimeout(hideSubNav, 500);
		});
	});
	function hideSubNav() {
		$("#subnav ul").fadeOut("fast");
		subnav_current = null;
	}
});

function popWindow(src, name, width, height) {
	var w = 800, h = 600;
	if (screen.width || screen.height) {
		w = screen.width;
		h = screen.height;
	}
	var leftPos = (w-width)/2;
	var topPos = (h-height)/2;
	window.open(''+src+'',''+name+'','width='+width+',height='+height+',toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=' + topPos + ',left=' + leftPos);
	void(0);
}

function playInJukebox(id) {
	var src = "/jukebox/" + id;
	var name = "jukebox";
	var width = 640;
	var height = 340;
	var w = 800, h = 600;
	if (screen.width || screen.height) {
		w = screen.width;
		h = screen.height;
	}
	var leftPos = (w-width)/2;
	var topPos = (h-height)/2;
	var jukebox = window.open(''+src+'',''+name+'','width='+width+',height='+height+',toolbar=no,status=no,menubar=no,scrollbars=no,resizeable=no,top=' + topPos + ',left=' + leftPos);
	jukebox.focus();
	void(0);
}
