var CPanel1, CPanel2, CPanel_Login, CPanel_Load;
var CPanel_Slide1, CPanel_Slide2, CPanel_SlideLogin, CPanel_SlideLoad;
var TempReq = 0;

//Initialize all of the skin's scripts
function FS_Init(){
 if($('CPanel'))FS_InitMenu();
}

//Initialize the menu animation scripts
function FS_InitMenu(){
 //Save the objects for cpanels
 CPanel1 = $('CPanel');
 CPanel2 = $('CPanel_Guest');
 CPanel_Load = $('CPanel_Loading');
 CPanel_Login = $('CPanel_Login');
 
 //Initialize the login/logout slides
 CPanel_Slide1 = new Fx.Slide('CPanel');
 CPanel_Slide2 = new Fx.Slide('CPanel_Guest');
 CPanel_SlideLoad = new Fx.Slide('CPanel_Loading');
 CPanel_SlideLogin = new Fx.Slide('CPanel_Login');
 
 //Determine which is currently shown, hide the slide
 if(CPanel1.style.height == "0px"){
  CPanel_Slide1.hide();
  CPanel1.style.height = "auto";
 } else{
  CPanel_Slide2.hide();
  CPanel2.style.height = "auto";
 }
 
 //Fix show the loading line
 CPanel_SlideLoad.hide();
 CPanel_Load.style.height = "auto";
 
 //Fix the login form line
 CPanel_SlideLogin.hide();
 CPanel_Login.style.height = "auto";
 
 //Set the logout button to slide into login
 $('CPanel_Logout').href = "#";
 $('CPanel_Logout').addEvent('click', function(e){
  e.stop();
  
  //Make sure we aren't loading
  if(TempReq != 0)return;
  
  //Make the request we need to logout
  TempReq = new Request.HTML({ url:'http://d5robotics.org/Forums/login.php?action=out&amp;id='+_UserID,
   onSuccess: function(html){
    CPanel_Slide2.slideIn().chain(function(){
     CPanel_SlideLoad.slideOut();
     Cookie.dispose("punbb_cookie");
    });
   },
   onFailure: function(){ alert('oops!'); }
  });
  
  //Slide the loading panel out, request logout
  CPanel_SlideLoad.slideIn().chain(function(){
   CPanel_Slide1.slideOut().chain(function(){
    TempReq.send();
   });
  });
  
  //End of click event
 });
 
 //Set the login button to slide out the login form
 $('CPanel_Login_Link').href = "#";
 $('CPanel_Login_Link').addEvent('click', function(e){
  e.stop();
  CPanel_SlideLogin.slideIn();
  $('CPanel_Login_Link').addEvent('click', function(e){
   e.stop();
   $('CPanel_Login_Form').submit();
  });
 });
}

//Call the setup functions as soon as we can
window.addEvent('domready', FS_Init);