$(document).ready ( function ()
{
	/*var nlSubscribeForm = $("#subscribeNewsletterForm").validate({
		submitHandler: function(form) {
			$("#agbErrorText").hide();
			$.post("index.php?task=nl_subscribe", $("#subscribeNewsletterForm").serialize());
			$("#newsletterTextBox").html('<p style="padding: 0px 10px 0px 10px;">Erfolgreich beim Newsletter angemeldet</p>');
			$("#newsletterBox").slideUp("normal", function () {
				$("#newsletterTextBox").slideDown();
			});
			$("#unsubscribeNewsletterForm").validate().resetForm();
		}
	});

	var nlUnsubscribeForm = $("#unsubscribeNewsletterForm").validate({
		submitHandler: function(form) {
			$("#agbErrorText").hide();
			$.post("index.php?task=nl_unsubscribe", $("#unsubscribeNewsletterForm").serialize());
			$("#newsletterTextBox").html('<p style="padding: 0px 10px 0px 10px;">Erfolgreich vom Newsletter abgemeldet</p>');
			$("#newsletterBox").slideUp("normal", function () {
				$("#newsletterTextBox").slideDown();
			});
			nlSubscribeForm.resetForm();
		}
	});
	
	var tmpVar = [];
	
	$("#newsletterButton").click (function () {
		var nlBox = $("#newsletterBox");
		var nlUsBox = $("#newsletterUnsubscribeBox");
		var nlAgbBox = $("#newsletterAgbBox");
		var nlTextBox = $("#newsletterTextBox");
		
		if ( nlBox.css("display") != "none" || nlUsBox.css("display") != "none" || nlTextBox.css("display") != "none" || nlAgbBox.css("display") != "none")
		{
			nlBox.slideUp();
			nlAgbBox.slideUp();
			nlTextBox.slideUp("normal", function () { $("#newsletterTextBox").html(""); });
			nlUsBox.slideUp();
		}
		else
		{
			nlBox.slideDown();
		}
	});
	
	$("#agbLink").click(function () {
		$("#newsletterBox").slideUp("normal", function () {
			$("#newsletterAgbBox").slideDown();
		});
	});
	
	$("#closeAgb").click(function () {
		$("#newsletterAgbBox").slideUp("normal", function () {
			$("#newsletterBox").slideDown();
		});
	});
	
	$("#unsubscribeLink").click(function () {
		$("#newsletterBox").slideUp("normal", function () {
			$("#newsletterUnsubscribeBox").slideDown();
		});
	});
	
	$("#submitUnsubscribe").click(function () {
		if ($("#newsletterUnsubscribeBox").find("input[name=EMail]").val() == "")
		{
			$("#newsletterUnsubscribeBox").slideUp("normal", function () {
				$("#newsletterBox").slideDown();
			});
		}
		else
		{
			$("#unsubscribeNewsletterForm").submit();
			//tmpVar[1] = $("#newsletterUnsubscribeBox").html();
			//$("#newsletterUnsubscribeBox").html("<p style='padding-left: 12px; padding-top: 10px;'>Sie wurden erfolgreich abgemeldet</p>");
			nlSubscribeForm.resetForm();
		}
	});
	
	
	
	$("#submitSubscribe").click(function () {
		$("#subscribeNewsletterForm").submit();

		if(!$("#subscribeNewsletterForm").valid() && !$("#subscribeNewsletterForm").find("input[name=agb]").attr("checked"))
		{
			$("#agbErrorText").show();
		}
	});*/
	
	$("#newsletterButton").click(function(e){
			e.preventDefault();
			if($("#nlframe").length>0) { $("#nlframe").slideUp("normal",function(){ $(this).remove(); }); return; }
			else { $("#nlframe").remove(); $("#newsletterBox").remove(); }
			$("#newsletterBox").remove();
			$("body").append('<div id="nlframe"><iframe style="width:160px; height:278px; border:0px solid black; overflow:hidden;" src="http://tabasco.tecart.de/news/public/M10/subscribe.html" scrolling="no" frameborder="0" border="0"></iframe></div>');
			$("#nlframe")
				.css("position","absolute")
				.css("left",$(this).offset().left)
				.css("top",$(this).height()+$(this).offset().top)
				.css("z-index","40")
				.css("width","160px")
				.css("height","278px")
				.css("display","none");
			$("#nlframe").find("iframe").load(function(){
				$("#nlframe").slideDown("normal");
			});
			$("#nlframe").append('<div class="close-area"><a href="#" class="script-close">Schlie&szlig;en</a></div>');
			$(".close-area")
				.css("background","#ddd")
				.css("padding","10px");
			$(".close-area").click(function(e){
				e.preventDefault();
				$("#nlframe").slideUp("normal",function(){ $(this).remove(); });
			});
		});
		if(self.location.href.indexOf("#nl-abmelden")!=-1) {
			$("#newsletterButton").click();
			$("#nlframe").find("iframe").attr("src","http://tabasco.tecart.de/news/public/M10/unsubscribe.html");
		}
});
