
// Preload Images, why this is need - i dont know ... 
var img1 = new Image(16, 16);  
img1.src="images/spinner.gif";
var img2 = new Image(220, 19);  
img2.src="images/ajax-loader.gif";


$(document).ready(function() 
{  




  // Start login submit processing
  $("#status > form").submit(function()
  {  

   $('#ajax_loading').html("<img align='absmiddle' src='images/spinner.gif'>&nbsp;Processing..."); 
   $('#ajax_loading').show();
   var str = $(this).serialize();  

   // -- Start AJAX Call --
   $.ajax
   ({  
       type: "POST",
       url:  "login.php?act=ajax_login", 
       data: str,  
       success: function(msg)
   {  
      
      $("#status").ajaxComplete(function(event, request, settings)
      {  
           // Show 'Submit' Button
          $('#submit').show();

          // Hide Gif Spinning Rotator
          $('#ajax_loading').hide();  

           if(msg == 'OK') // LOGIN OK?
           {  

             $('#ajax_loading').html("Logged, pls wait!"); 
             $('#ajax_loading').show();
             setTimeout('goto_admin()', 250); 
        }  
        else
        {  
           $('#ajax_loading').html("<font color='red'>Error! Try again.</font>"); 
           $('#ajax_loading').show();
        }  
     });  
   }  
   });
   // -- End AJAX Call --


   return false;
 }); 
// End login submit processing


// Start process of showing modal login box
  //when <a> tag named "loginbox" is clicked out:
  $('a[name=loginbox]').click(function(e) 
  {

    //Cancel the link behavior
    e.preventDefault();
                  
    //Get the A tag
    var id = $(this).attr('href');
          
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth  = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    
    //transition effect             
    $('#mask').fadeIn(1000);        
    $('#mask').fadeTo("slow",0.8);  

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2-100);
    $(id).css('left', winW/2-$(id).width()/2);

    //hide loading string ... 
    $('#ajax_loading').hide();

    //transition effect
    $(id).fadeIn(2000); 

  });
  // End process of showing modal login box


  // Make login form post process
  //
        
  //if close button is clicked
  $('.window .close').click(function (e) {
          //Cancel the link behavior
          e.preventDefault();
          
          $('#mask').hide();
          $('.window').hide();
  });             
  
  //if mask is clicked
  $('#mask').click(function () {
          $(this).hide();
          $('.window').hide();
  });                     
        
});

function goto_admin()
{
   window.location = 'admin.php?act=brands'; // Members Area
}