$('[RAW_login]').live('click',function(){
	var check;
	var usr = $.cookie('RAWUSR');
	if(usr != null)
	{ 
		check = 'checked="checked"';
	}
	else
	{ 
		check = ''; usr = "Username";
	}
	var R_overlay = $('<div />').attr('id','R_login_overlay').css('opacity',0)
	var html = '<div id="R_login_container">';
		html += '<div class="R_login_close"></div>'
		html += '<form id="R_login" method="post">'
		html += '<img src="/RAW/images/login.jpg" class="R_login_logo" />'
		html += '<input type="text" class="R_username" name="username" value="'+usr+'" />'
		html += '<input type="password" class="R_password" name="password" value="Password" />'
		html += '<input type="submit" value="Login" class="R_login" />'
		html += '<span class="R_login_remember"><input id="R_remember_check" '+check+' type="checkbox" /> <label>Remember my username</label></span>'
		html += '</form>'
		html += '</div>'
	
	$('body').prepend(R_overlay, html);
	R_overlay.animate({'opacity':0.9},300)
	return false;
});

$('#R_login').live('submit', function(event){
	var usr = $('.R_username').val();
	var pass = $('.R_password').val();
	if($('#R_remember_check').is(':checked'))
	{
		$.cookie('RAWUSR', usr, { expires: 7, path: '/' });
	}
	else
	{
		$.cookie('RAWUSR', null);
	}
	event.preventDefault();
	
	$.post('/RAW/php/RAW.login.php', {'username':usr, 'password':pass},function(data){
		if(data == 'OK'){ window.location = ''; }
		if(data == 'NOTOK'){ 
			$('.R_username, .R_password').css('background-color', '#FFCBCA')
		}															
	})
})

$('#R_login_overlay, .R_login_close').live('click', function(){
	$('#R_login_container').remove();
	$('#R_login_overlay').animate({'opacity':0},300, function(){
		$('#R_login_overlay').remove();										
	})
})

$('.R_username').live('focus',function(){
	if($(this).val() == 'Username'){ $(this).val('') };
}).live('blur', function(){
	if($(this).val() == ''){ $(this).val('Username') };
})

$('.R_password').live('focus',function(){
	if($(this).val() == 'Password'){ $(this).val('') };
}).live('blur', function(){
	if($(this).val() == ''){ $(this).val('Password') };
})
