// JavaScript Document

var SITE = window.location.hostname;

function fixFailed() {
	//alert("called from PHP");
	$('.failed')
		//.animate({opacity: 0.5})
		.fadeOut(5000, function() {
			$(this).remove();
		});
}

function passwordBlur() {
	$("input[name='Password'].loginField").blur(function() {
		if($(this).val() == '') {
			//alert("blur");
			name = $(this).attr('name'); // grab name of original
			var className = $(this).attr('class'); // grab class of original
			/* create new password input */
			html = '<input type="text" name="' + name + '" class="' + className + '" value="Password" />';
			$(this)// add new, then remove original input
				.after(html)
				.remove();
			passwordFocus();
		}
	}); 
}

function passwordFocus() {
	$("input[name='Password'].loginField")
		.val('Password')
		.focus(function(){
			//alert("click");
			var name = $(this).attr('name'); // grab name of original
			var className = $(this).attr('class'); // grab class of original
			/* create new password input */
			var html = '<input type="password" name="' + name + '" class="' + className + '" />';
			$(this)// add new, then remove original input
				.after(html)
				.remove();
			passwordBlur();
		});
}

$(function() {
	//alert('in site');
	if(SITE == 'www.greenwaygolfanswers.com') {
		
		$('#siteLinks').width('100%').css({left: -15, bottom: -15});
	}
	
	else if(SITE == 'www.supergreencleaner.com') {
		
		$('#siteLinks').css({left: 20, backgroundImage: 'none'});
	}
	
	$('#Home').focus();
	$("input[name='Username'].loginField")
		.val('Username')
		.focus(function(){
			$(this).val('');
		})
		.blur(function() {
			//alert("blur");
			if($(this).val() == '') {
				$(this).val('Username')
			}
		});
	passwordFocus();
	
	if($('.failed').is(':visible')) {
		//alert('visible');
		fixFailed();
	}
	
	$('#newAccount').click(function(event) {
		event.preventDefault();
		var redirectTo = BASEURL + 'register.php';
		window.location = redirectTo;
	});
	
});