$(document).ready(function(){

	if(typeof showMailingListOverlay != 'undefined' && showMailingListOverlay){
	
		// add the mailing list promotional graphic to the top of the page
		var adText = "Enter your email for a chance to win a $25.00 gift certificate and also receive our monthly specials."
		
		// adjust the top padding
		$("#centercontent").css({"padding-top":"68px"});
		$wrapperdiv = $("<div></div>").attr({"id":"adwrapper"}).prependTo("#centercontent");
		
		$form = $("<form></form>").attr({"name":"maillistform", "id":"maillistform"}).prependTo($wrapperdiv);
		$closeX = $('<a></a>').addClass('closeX').text('X').attr({'href':'#'}).insertBefore($form).click(function(){$("#adtoggler").trigger("click");});
		
		$firstNameLabel = $("<label></label>").html("First Name: <br />").appendTo($form);
		$firstName = $("<input />").attr({"name":"firstname", "id":"firstname"}).appendTo($firstNameLabel).focus();
	
		$lastNameLabel = $("<label></label>").html("Last Name: <br />").insertAfter($firstNameLabel);
		$lastName = $("<input />").attr({"type":"text","name":"lastname", "id":"lastname"}).appendTo($lastNameLabel);
		
		$emailLabel = $("<label></label>").html("* Your Email Address: <br />").insertAfter($lastNameLabel);
		$email = $("<input />").attr({"type":"text","name":"ue", "id":"ue"}).appendTo($emailLabel);	
		
		$sendLabel = $("<div></div>").insertAfter($emailLabel);
		$send = $("<input />").attr({"type":"button", "value":"enter to win", "id":"sendbt"}).appendTo($sendLabel).click(function(){
				$.ajax({
					url: "mailing_list_email.php",
					data: {"firstname":$firstName.val(), "lastname":$lastName.val(), "ue":$email.val()},
					success: function(msg){
						if(msg == "sent"){
							$close = $("<a></a>").attr({"href":"#"}).text("Close this message").click(function(){
								$("#linkdiv a").trigger("click");
							})
							$sendLabel.html("Form sent! ").append($close);
						}else{
							alert(msg);
						}
					}
				});		
		});
					$cancel = $("<a></a>").attr({"href":"#", "id":"cancelbt"}).text("cancel").appendTo($sendLabel).click(function(){
							$("#adtoggler").trigger("click");
					});
					$cleardiv = $("<div></div>").addClass("c").appendTo($sendLabel);
		$linkdiv = $("<div></div>").attr({"id":"linkdiv"}).appendTo($wrapperdiv);
		$a = $("<a></a>").attr({"href":"#", "id":"adtoggler"}).html(adText).appendTo($linkdiv).toggle(
		function(){
			$wrapperdiv.animate({"top":"0px"});		
		}, 
		function(){
			$wrapperdiv.animate({"top":"-245px"});
		});
	
		$wrapperdiv.css({"top":"-245px"})
	
		if(typeof autoOpenMailingListOverlay != 'undefined' && autoOpenMailingListOverlay){
			$("#adtoggler").trigger("click");	
		}
	
	}

});
