$(document).ready(go);

function go()
{		
	$(".top-level.section").html('<form id="password-form"><input id="password-box" maxlength="50" type="password" /></form><p id="faq" class="fadey-bits"><a href="#" id="mail" class="open-wide">Mail</a> &middot; <a href="#" id="profiles" class="open-wide">Profiles</a> &middot; <a href="#" id="album" class="open-wide">Album</a> &middot <a href="#" id="choosing" class="open-wide">Choosing A Secure Password</a></p><div id="open"></div>');
	$("#open").hide();
	$("#password-box").focus();
	$("form#password-form").after('<div class="password-strength"></div>');
	$("#password-box").keydown(function(e)
	{
		if (e.keyCode == 13 || e.charCode == 13)
		{
			return false;
		}
	});
	$("#password-box").keyup(function(e){passwordCheck(this, e);});
	$("#password-box").click(function(){$("#open").slideUp();$("a.open-wide").removeClass('current-clicked');});
	
	$(".open-wide").click(function(){clicky(this);return false;});
	
	// Konami Code!
	// http://paulirish.com/2009/cornify-easter-egg-with-jquery/
	
	var kkeys = [];
	var konami = "38,38,40,40,37,39,37,39,66,65";
	
	$(document).keydown(function(e)
	{
	kkeys.push( e.keyCode );
	
	if ( kkeys.toString().indexOf( konami ) >= 0 )
	{
		$(document).unbind('keydown',arguments.callee);
		$('h1 span.how').html('How Secure Is');
		$('h1 span.password').html('My Konami Code?');
		$('a').css({color:'transparent', textShadow:'0 0 20px black'});
		$('h1').css({color:'transparent', textShadow:'0 0 50px black'});
		$('html').css({color:'transparent', textShadow:'0 0 20px black'});
	}
});
}

function clicky(that)
{
	var string = '';
	
	$("a.open-wide").removeClass('current-clicked');
	$(that).addClass('current-clicked');
	
	switch($(that).attr('id'))
	{
		case 'mail':
		{

			string = '<img src="http://services.nexodyne.com/email/icon/ozu4UfoGUE2nxd8%3D/xImFRhA%3D/R01haWw%3D/0/image.png">';
			break;
		}
		case 'profiles':
		{
			string = '<p>move to <a class="more" href="https://profiles.google.com/cocobear.cn">Google Profile</a></p>';
			break;
		}
		case 'album':
		{
			string = '<p><a class="more" href="https://picasaweb.google.com/cocobear.cn">Album</a></p>';
			break;
		}
		case 'choosing':
		{
			string = '<a href="http://wolfram.org/writing/howto/password.html">Clicky</a>';
			break;
		}
	
	}
	$('div#open').html(string).slideDown().delay(1500).slideUp();
}

function passwordCheck(that, e)
{
	if (e.keyCode == 27 || e.charCode == 27)
	{
		$(that).val("");
	}
	
	var password = $(that).val();
	
	if (password != "")
	{		
		$(".fadey-bits").hide();
	}
	else
	{
		$("div.password-strength").hide();
		$(".fadey-bits").fadeIn(500);
	}
}

