$(document).ready(function(){
	function closePerformancePicker(){
		$("div#overlay").fadeOut();
		$("div#performances-popup").fadeOut("fast");
	}
	
	$("div#performances-popup a.close-link").click(function(){
		closePerformancePicker();
		return false;
	});
	
	$("div#performance-popup-content").append($("table#sm-production-times").clone());
	$("div#performance-popup-content").find(".unbookable-performance").remove();
	
	$("div#performance-popup-content").find("a.buytickets img").each(function(){
		$(this).attr("src", $(this).attr("src").replace("-small.gif", ".jpg"));
	});
	
	$("a#main-buytickets").click(function(){
		var overlay = $("#overlay");
		if(!overlay.length){
			overlay = $("<div id='overlay'></div>");
			$("body").append(overlay);
			overlay.click(function(){
				closePerformancePicker();
				return false;
			})
		}
		overlay.css("opacity", 0);
		overlay.css("display", "block");
		overlay.fadeTo("fast", 0.5);
		overlay.css("height", $(document).height());
		
		$("div#performances-popup").fadeIn("fast");
		
		if(jQuery.browser.version == 6.0 && jQuery.browser.msie){
			$("div#performances-popup").css('position', 'absolute');
			$("div#performances-popup").css('top', parseInt(20 + document.documentElement.scrollTop));
		}
		
		return false;
	});
});
