var $j = jQuery.noConflict();
	
$j(document).ready(function() {

	$j(".recent_tweets_fill").pngFix();
	
	$j(".beta_testers_form").hide();
	
	$j(".beta_testers_form_link, .beta_tester").click(function() {
		$j("#beta_testers_form").dialog("close");
		$j("#beta_testers_form").dialog("open");
		$j("#beta_testers_form").show().dialog({ 
			modal: true,
			height: 300,
			width: 360,
			resizable: false,
			overlay: { 
				opacity: 0.5, 
				background: "white" 
			}
		});
		return false;
	})
	
	function hide_message() {
		$j(".not_logged_in").fadeOut();
	}
	
	setTimeout(hide_message, 3000);
	
	$j(".login_form").append("<div class=\"login_message\"></div>");
	
	
	function processing() {
		$j(".login_message").removeClass("error");
		$j(".login_message").html("<img src=\"./_img/login_loading.gif\" /> Trying to log you in...");
	}
	
	function login(responseText) {
		if(responseText==0){
			$j(".login_form .field, .login_form .buttons").effect("shake", { distance: 5 }, 100); 
			
			$j(".login_message").addClass("error");
			$j(".login_message").html("The username and/or password entered is invalid.");
			$j("#password").val("");
			
			$j(".field input").click( function() {
				$j(".login_message").fadeOut(function() {
					$j(this).html("");
					$j(".login_message").removeClass("error");
				}).fadeIn();
			});
		}
		else if(responseText==1){
			$j(".login_form .field, .login_form .buttons").effect("shake", { distance: 5 }, 100); 
			
			$j(".login_message").addClass("error");
			$j(".login_message").html("Only beta testers are allowed to login at this time.");
			$j("#password").val("");
			
			$j(".field input").click( function() {
				$j(".login_message").fadeOut(function() {
					$j(this).html("");
					$j(".login_message").removeClass("error");
				}).fadeIn();
			});
		}
		else {
			$j(".login_message").html("<img src=\"./_img/login_loading.gif\" /> Username and password accepted. Logging you in..." + responseText);
		}
	}
	
	$j(".login_form").ajaxForm({
		beforeSubmit: processing,
		success: login
	});
	
	
	$j(".beta_testers_form fieldset").append("<div class=\"beta_message\"></div>");
	
	function beta_processing() {
		$j(".beta_message").removeClass("error");
		$j(".beta_message").html("<small>Trying to add you to the list...</small>");
	}
	
	function hide_beta_form(){	
		$j("#beta_testers_form").dialog("close");
		$j(".beta_tester").fadeOut(function() {
			$j(".beta_tester p, .beta_tester img").remove();
			$j(".beta_tester").append("<img src=\"./_img/beta_check_icon.png\" alt=\"\" title=\"Thanks!\" />");
			$j(".beta_tester").append("<p><strong>Thanks for requesting to be a beta tester.</strong></p><p>Watch your inbox for an invite from Twuffer.</p>");
		}).fadeIn();
	}
	
	function beta_login(responseText) {
		
		if(responseText != 1){
			$j(".ui-dialog").effect("shake", { distance: 5 }, 100); 
			
			$j(".beta_message").addClass("error");
			$j(".beta_message").html("<small>" + responseText + "</small>");
			$j("#password").val("");
			
			$j(".beta_testers_form .field input").click( function() {
				$j(".beta_message").fadeOut(function() {
					$j(this).html("");
					$j(".beta_message").removeClass("error");
				}).fadeIn();
			});
				}
		else {
			$j(".beta_message").html("<small>You've been added to the list!...</small>");
			setTimeout(hide_beta_form,1000);
		}
	}
	
	$j(".beta_testers_form").ajaxForm({
		beforeSubmit: beta_processing,
		success: beta_login
	});
	
	$j(".intro .right a").fancybox({
		'overlayShow': true 
	}); 

});