$(document).ready(function(){
		
	function showNewContent() {
		
			$('#siteContent').show('normal');
			
			
		}
		
	function hideLoader() {
		
			$('#loader').fadeOut('normal',showNewContent);

		}
//////////////check for login
	$.post('isloggedin.php',function(data){
									 if(data=="1")
									 {
									 $('#login').hide("fast");
									 }
									 else
									 {
									 $('#logout').hide("fast");
									  $('#leader').hide("fast");
									 }
									 });
	
	///////////////when logout button is clicked
	$('#logout').click(function(){
								$.post('logout.php',function(data){
																							
								$('#siteContent').append("Succesfully Logged Out");
								$('#logout').hide("fast");
								 $('#leader').hide("fast");
								$('#login').slideDown("slow");
								
								//$('#header').load('headercontent.php');
															 });
								});
	
	/////////////when login button is clicked
	$('#uloginbut').click(function(){
			$('#siteContent').html("");
	
		$('#siteContent').hide('slow',getNewContent);
		
		$('#loader').remove();
		$('#wrapper').append('<div id="loader"></div>');
		$('#loader').fadeIn('normal');
					   
								   
		function getNewContent(){
			$.post('ucheck.php',{
					uname:$('#uname').val(),
					pass:$('#pass').val()
				},
				function(data){
					
					if(data==1)
					{
						
						$('#login').slideUp("slow");
					
						$('#siteContent').html("<p>Succesfully Logged in</p><p>Click Start to Continue</p>");
					
						$('#logout').show();
						 $('#leader').show();
					}
					else if(data==0)
					{
						$('#uname').val("");
						$('#pass').val("");
						$('.loginBar span').css("color","red");
						$('#siteContent').html("<p>Login Failed</p><p>Invalid Username OR Password</p>");
					}
					
				});}
	});

});
