$(function() {
	if($("#nowLeaving").length)
	{
		// set up outside links
		/*
		$(".outsideLink").click(function() {
			// get link and assign to displayed url and button
			var href = $(this).attr("href");
			if(href)
			{
				openNowLeaving(href);
				return false;
			}
			return true;
		});
		*/
		/*
		$("#chooseRetailer").click(function() {
			var link = $("#chooseRetailerDD option:selected").val();
			if($("#chooseRetailerDD option:selected").hasClass("outsideLink"))
			{
				openNowLeaving(link);
				return false;
			}
			else
			{
				window.open(link);
			}
			return true;
		});
		*/

		$("#nowLeaving .nowLeavingClose").click(function() {
			closeNowLeaving();
		});
		
		// close on overlay as well
		$("#nowLeavingOverlay").click(function() {
			closeNowLeaving();
		});
	}
});

function openNowLeaving(url)
{
	window.location = url;

	/*
	// position
	$("#nowLeavingContents").css({
		"top":  ($(window).height() - $("#nowLeaving").height() ) / 2,
		"left": ($(window).width() - $("#nowLeaving").width() ) / 2
	});

	// scroll to top of page
	window.scrollTo(0, 0);
	
	$("#nowLeaving").fadeIn();
	// disable scrolling
	$("html").css({"overflow": "hidden"});
//	$("body").css({"overflow": "hidden"});
	$("#chooseRetailerDD").hide();
	
	var urlMaxLen = 80;
	
	var urlTxt = url;
	
	if(url.length > urlMaxLen)
	{
		urlTxt = url.substr(0, urlMaxLen) + "...";
	}
	
	$("#bumperURL").html(urlTxt);
	$("#bumperBtn a").attr("href", url);
	//console.log($("#bumperBtn a").attr("href"));
	//return false;
	*/
}

function closeNowLeaving()
{
	$("#nowLeaving").hide();
	$("html").css({"overflow": "auto"});
//	$("body").css({"overflow": "auto"});
	$("#chooseRetailerDD").show();
}