var nl_closed = false;
function nl_toggle() {
	$('#nlfooter').slideToggle("slow");
	$('#nlclosed').slideToggle("slow");
}
function nl_close() {
	nl_closed = true;
	$.cookie('mailchimp_session',true, { path: '/' });
}
$(function(){
	$('#nlclosed').css('left',$('#main').offset().left + 1048);
	if ($.cookie('mailchimp_session') == null) { // Check if not already viewed
		// Check if first visit, set cookie counter
		if ($.cookie('mailchimp') == null) $.cookie('mailchimp',0, { path: '/', expires: 365 });
		// Get count #
		var visits = Number($.cookie('mailchimp'));
		// If less than 3 previous visits, show form, set timeout, increase visits
		//if (visits < 3) {
			nl_toggle();
			//window.setTimeout(function() {
				//if (nl_closed == false) {
					//nl_toggle();
					//nl_close();
				//}
			//}, 10000);
			$.cookie('mailchimp',visits+1, { path: '/', expires: 365 });
		//}
	}
});
function nlfooter_submit(form) {
	var name = form.name.value;
	var email = form.email.value;
	if(name=='' || name=='name' || !isEmailAddr(email)) {
		alert("Hey!....we need a name and email address. Thanks!");
	} else {
		$.post("/forms/post-mailchimp.php", { nl: "true",name: name, email: email },function(data){
			if (data=='success') {
				$('#nlform').html('<div>THANKS FOR SUBSCRIBING!<br/><span class="style2">Please check your inbox to confirm your subscription.</span></div>');
			}
		});
	}
	return false;
}
function isEmailAddr(email){
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
    result = true;
  }
  return result;
}