$(document).ready(function() {
	var adBox = "#ad1"; // Name of the ad container.
	var adName = "#clearance"; // Name of the animated bit of the ad.
	var adCookie = "ad-clearance"; // Name of the cookie to be set.
	var adWidth = $(adName).width() + $(".cap").width(); // Width of the ad container.

	function openAd() {
		$(adBox).width(adWidth+"px");
		$(adName).animate({marginLeft: "0"},1200);
		$.cookie(adCookie, null);
	}
	
	function closeAd() {
		$(adName).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
			function(){ $(adBox).width($(".cap").width() + "px"); }
		);
		$.cookie(adCookie,'off',{expires: 365});
	}

	$("#open1").click(function() {
		if(!$.cookie(adCookie)) {
			closeAd();
		} else {				   
			openAd();
		}
		return false; 
	});
	$("#close1").click(function() {
		closeAd();
		return false;
	});	
	if(!$.cookie(adCookie)) {
		$(adBox).animate({opacity: 1.0}, 1500, "linear", openAd);
	}
});