var popOut = "#subscribe"; // The ID of the outermost ad container div.
var adBox = "#subscribead"; // The inner ad div (the one that should move).
var adCookie = "subscribead"; // The name of the cookie associated with this ad.
var openLink = "#open1"; // The open button (i.e., cap, toggler) for this ad.
var closeLink = "#close1"; // The close button.
var adWidth = ''; // This will be set at runtime to ensure we get an accurate number.

function openAd() {
	$(popOut).width(adWidth+"px");
	$(adBox).animate({marginLeft: "0"},1200);
	$.cookie(adCookie, null, {expires: 0, path: '/'});
}

function closeAd() {
	$(adBox).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
		function(){ $(popOut).width($(popOut+" .cap").width() + "px"); }
	);
	$.cookie(adCookie,'closed',{expires: 30, path: '/'});
}

$(document).ready(function() {
	adWidth = $(adBox).width() + $(popOut+" .cap").width();
	$(openLink).click(function() {
		if($.cookie(adCookie) != "closed") {
			closeAd();
		} else {
			openAd();
		}
		return false;
	});	
	$(closeLink).click(function() {
		closeAd();
		return false;
	});	
	
	$(popOut).width($(popOut+" .cap").width() + "px");
	if($.cookie(adCookie) != "closed") {
		$(popOut).animate({opacity: 1.0}, 2000, "linear", openAd);
	}
});
