if(!newsletter){
	var newsletter = {}
}

(function($){

	
	newsletter.popup = {
		init: function(){
			/*
				No close box available just now
				See inline content docs here for use http://jquery.com/demo/thickbox/
			*/
			// remove existing error css
			$(".popup").find("form").find("input").removeClass("txt-input-error").addClass("txt-input");
			$(".register").val('#TB_inline?height=502&width=580&scrollbar=no&inlineId=newsLetterForm');
			$("#jsFlag").val('true');
			$(".btn-submit").click(function(e){
				e.preventDefault();
				$(".newsletterForm").submit();
			});		
			$(".newsletterForm").submit(function(e){
				$(".popup").find("form").find("input").removeClass("txt-input-error").addClass("txt-input");
				$("#messages")
				.find("#thanks")
					.hide()
				.end()
				.find("#error")
					.hide()			
				.end()
				e.preventDefault();						
				var data = $(this).serialize();
				$.post("/wp-content/plugins/newsletter/newsletter.submit.php",data,function(json){
					//newsletter.debug.data = json;					
					if(json["formData"]["errorCount"] > 0){
						// highlight error input fields					
						$.each(json["formData"],function(i,val){
							var id = val.id;
							if(id != null && val.error == true){								
								$("#"+id).removeClass("txt-input").addClass("txt-input-error");
							}
						});
						
						/* Not wanted :(
						$("#error")
						.find(".list")
						.html(json["error_message"])
						.end()
						.show("fast");*/
					}else{
						$(".popup").find("form.newsletterForm").hide();
						$(".popup")
// failing to clear all form inputs
/*						.find(".newsletterForm")
						.find("input")
						.val("")
						.end()
						.find('.frame')
						.find('div')
						.removeClass('checkboxAreaChecked')
						.addClass('checkboxArea')
						.end()*/
						.find("#thanks")
						.show("fast");					
					}
				},"json");
			});
		},
		finish: function(){
			newsletter.popup.close();
			$("#formMessage").html("");
			$("#sendToFriendForm input").val("");
			$("#sendToFriendForm textarea").val("");
		},
		adjust: function(){
			$("#overlay").width($(window).width()).height($(document).height());
			$(".popup").css("left",($(window).width() /2)-($(".popup").width()/2));
			$(".popup").css("top",($(window).height() /2)-($(".popup").height()/2));	
		},
		close: function(){
			$(".pop-up").fadeOut("fast",function(){
				$("#overlay").hide(0);
			});		
		},
		open: function(){
			$("#overlay").fadeIn(100,function(){			
				$(".pop-up").fadeIn(100);
			});
		}
	}
	newsletter.debug = {
		data:""
	}
	newsletter.formBtn = {
		init: function(){
			$(".formBtn").each(function(i, item){
				$(item).hover(function(){
					$(this).css({backgroundPosition: '0px -35px'});
				},function(){
					$(this).css({backgroundPosition: '0px 0px'});
				});
			});
		}
	}
	newsletter.searchbar = {
		init:function(){
			var defaultLabel = "Search for:";
			$("#searchform input[type=text]").val(defaultLabel);
			$("#searchform input[type=text]").focus(function(){			
				$("#searchform input[type=text]").val("");
			});

		}
	}
	newsletter.share = {
		init: function(){
			$("#clearSharedExperience").css("display","block").click(function(e){
				e.preventDefault();			
			});		
		}	
	}
	newsletter.share = {
		init: function(){
			$("#clearSharedExperience").css("display","block").click(function(e){
				e.preventDefault();		
				$("#sendexperienceForm input").val("");	
				$("#sendexperienceForm textarea").val("");
				$("#sendexperienceForm :checkbox").attr("checked",false);
			});		
		}	
	}
})(jQuery)
// domready
