$.fn.highlight = function(){
  this.each(function(i){
    var that = this,
        opacity = 1,
        step = 9,
        stepper = function(){
          $(that).css("background","rgba(255,255,255,"+(opacity-1-(-step*0.1))+")");
          step -= 1;
          if(step) setTimeout(stepper, 25);
        }
    stepper();
  })
}

$(document).ready(function(){
	
	$("#id_email").one("focus",
		function(){
			$(this).addClass("focus")[0].value = "";
		}
	)[0].value = "enter your email here";
	
	var setLightbulbEvent = function(on){
		var i = 0,
			instructions = [50,800,50,50,50,700,50,200,50,100,50,50,50],
			blink = function(){
				$(on).toggle();
				var blinkTimer = setTimeout(function(){
					i = i+1;
					if(instructions.length > i){
						blink();
					}else{
						$(on).show();
						resetBulb(on.parents("li")[0]);
					}
				}, instructions[i]);
			}
	  on.parent().find(".on, .off").unbind("mouseover").unbind("mouseout");
		blink();
	};
	
	var resetBulb = function(li){
		
		$(li).find(".on").bind("mouseover",function(){
			$(this).hide();
		});
	
		$(li).find(".off").one("mouseout",function(){
			setLightbulbEvent($(this).siblings(".on"));
		});
	
	};
	
	$("#grid li").each(function(i){
		$(this).find(".on").show();
		resetBulb(this);
	});
	
	$("#subscriber_form a.submit").click(function(e){
    var form = $(this).parent();
    $.post(form.attr("action"), {'email': form.find("input#id_email").val()}, function(data, statusText){
      if(statusText!=="success") data = "Something is wrong with the server. Try again later.";
      alert(data);//.show().highlight();
    });
    return false;
  });

	
});
