jQuery(document).ready(function(){

     // Login Button
    var login_box = jQuery('#login-popout');
    var login_button = jQuery('.login-button');
    //var login_button_text = login_button.html();
    
    //jQuery('.login-button, #main .not-logged-in .whatnow .col-right .faux-login a').bind('click',function(event){					  
    jQuery('.login-button').bind('click',function(event){					  
		if(login_box.css('display') == 'none'){
			//login_button.addClass('login-button-alternative');
			login_box.slideDown(200);
			//jQuery('#login-popout input#userid').focus();
		} else {
			//login_button.removeClass('login-button-alternative');
			login_box.slideUp(200);
		}
	return false;
    });
    jQuery('.logout-button').bind('click',function(event){	
		document.location='ajaxLogout';
	return false;
    });
  
	$("#login_form").submit(function() {

			$("#msgbox").removeClass().addClass('messagebox').text('Validating user...').fadeIn(1000);
			$.post("ajaxLogin",{ username:$('#username').val(), password:$('#password').val(), rand:Math.random() },function(data)
			{
			  $("#msgbox").removeClass().addClass('messagebox').text('Validation passed...').fadeIn(1000);
			  if(data=='yes') //if correct login detail
			  {
					$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
					{
					  //add message and change the class of the box and start fading
					  $(this).html('Logging in...').addClass('messageboxok').fadeTo(900,1,function()
					  {
						 //redirect to secure page
						 document.location='viewer';
					  });
					});
			  } else {
					$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
					{
					  //add message and change the class of the box and start fading
					  $(this).html(data).addClass('messageboxerror').fadeTo(900,1);
					});
			  }
		   });
		   return false;
	});
	
});



