$(document).ready(function() {
	
	var addthis_config = {
		ui_click: true
	}
	
	$("a.fancybox").fancybox({
		'titleShow'     : false,
		'overlayOpacity' : 0.7,
		'overlayColor' : '#000'
	});
	
	$(".flash-msg").fadeTo(3000,1).fadeOut();
	
	$('.visual .img').hover(function() {
		$('.tools .center-inner').show();
	}, function() {
		$('.tools .center-inner').hide();
	});
	
	$(".join").hover(function() {
		$(this).removeClass("join");
		$(this).addClass("login");
	}, function() {
		$(this).removeClass("login");
		$(this).addClass("join");
	});
	
	$('input[type=text]').focus(function() { 
		if($(this).val() == $(this).attr('placeholder'))
		{
			$(this).val('');
		}
	});

	$('input[type=text]').blur(function(){
		if($(this).val() == '')
		{
			$(this).val($(this).attr('placeholder'));
		} 
	});
	
	var currentFocus = null;
	$('input').focus( function() {
	    currentFocus = this;
		$('input[type=text]').removeClass('focused');
		$(this).addClass('focused');
	}).blur( function() {
	    currentFocus = null;
	});
	
	submitNewsletter = function()
	{
			var email = $("input[name=subscribe_email]").val();

			$.ajax({
			type: "POST",
			url: "/subscribe",
			data: "email="+email,
			dataType: "json",
			beforeSend : function() {
				//$("#job-status-indicator").show();
			},
			success: function(json) {
				if(json.success == true)
				{
					location.hash = 'top';
					// load and show overlay
					$.get('/subscribe/overlay',function(data) {
						$("#overlay-content").html(data);
						$("#overlay").fadeIn();
						$("#overlay-bg").fadeIn();
						Cufon.now();
					});
				}
				else
				{
					alert(json.msg);
				}
			  }
			});

			return false;
	}
	
	$(".mail-form").submit(function() {
		var email = $("input[name=subscribe_email]").val();
		
		$.ajax({
		type: "POST",
		url: "/subscribe",
		data: "email="+email,
		dataType: "json",
		beforeSend : function() {
			//$("#job-status-indicator").show();
		},
		success: function(json) {
			if(json.success == true)
			{
				location.hash = 'top';
				// load and show overlay
				$.get('/subscribe/overlay',function(data) {
					$("#overlay-content").html(data);
					$("#overlay").fadeIn();
					$("#overlay-bg").fadeIn();
					Cufon.now();
				});
			}
			else
			{
				alert(json.msg);
			}
		  }
		});
		
		return false;
	});
	
	$(".cancel-link").live('click',function() {
		$("#overlay").fadeOut();
		$("#overlay-bg").fadeOut();
	});
	
	$(".close-button a").live('click',function() {
		$("#overlay").fadeOut();
		$("#overlay-bg").fadeOut();
	});
	
	$(".overlay-trigger").live('click',function() {
		$("#overlay").fadeIn();
		$("#overlay-bg").fadeIn();
	});
});