$(document).ready(function() {
	
	// Add "js" class to body
	$('body').addClass('js');
	
	// Open new windows
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});

	// Login
	$("#login_link").fancybox();

	// Commercial
	$('a[href="#commercial_video"]').fancybox();

	// Form placeholder text
	$('input[type="text"], input[type="password"], textarea').each(function() {
		
		//var tag = $(this).get(0).tagName;
		var input = $(this);
		var placeholder = $(this).attr('title');
		
		$(input).val(placeholder);
		
		$(this).bind({
			focusin: function() {
				if ( $(input).val() == placeholder ) {$(input).val('');}
			},
			focusout: function() {
				if ( $(input).val() == '' ) {$(input).val(placeholder);}
			}
		});		
	});
	
	// Not really sure what I am using this for... savings calc page?
	$('input[type="text"], input[type="checkbox"], select').each(function() {
		
		var row = $(this).closest('div.input');
		
		$(this).bind({
			focusin: function() {$(row).addClass('focus');},
			focusout: function() {$(row).removeClass('focus');}
		});	
	});
	
	// Grab current link
	var nav_links = $('#nav a');
	var current = $('#nav a.current');
	$(current).addClass('selected');
	
	$('#nav > li').bind({
		mouseenter: function() {
			$(nav_links).removeClass('selected');
			$(this).find('a.main').addClass('selected');
		},
		mouseleave: function() {
			$(this).find('a.main').removeClass('selected');
			$(current).addClass('selected');
		}
	});
});
