jQuery.fn.exists=function(){return jQuery(this).length>0;}
$(document).ready(function() {
	$("#twitter-box").delay(1000).fadeIn(2000);
	twitterboxIt();
	
	//$("#twitter-box .following > span").load("count-population.php");
  setInterval(function() {
    $.get('count-population.php', function(data) {
      $("#twitter-box .following > span").html(data);
    });
  }, 10 * 1000);
	
	$("form").submit(function(){
		subscribe_form();
		return false;
	});
	
	$("form input[name=email]").focus(function(){
		if ($(this).val()=="Your email address"){
			$(this).val("");
		}
	}).blur(function(){
		if ($(this).val()==""){
			$(this).val("Your email address");
		}
	});
});

$(window).resize(function() {
	twitterboxIt();
});

function twitterboxIt(){
	var i=$("#middle h2 > img");
	var position=i.position();
	$("#twitter-box").css({
		left:(position.left+$("#middle h2 > img").width()+20)+'px',
		top:(position.top+$("#middle h2 > img").height()-130)+'px'});
}

function subscribe_form(){
	var formData=$("form").serialize();
	$.ajax({
		type: "POST",
		url: "/emails/",
		data: formData+"&method=AJAX",
		cache: false,
		success: function(resp){
			var json=$.parseJSON(resp);
			$("form").html(json["return"]);
		}
	});
	return false;
}
