var lastPopUpWindow = null;
function pop (sCase){
  // close the last pop-up.
  try {
    lastPopUpWindow.close ();
  } catch(e) {}
  
  
  switch (sCase){
    // DOWNLOADS - Wallpapers
    case "wallpaper":
      var wpPath = pop.arguments[1];
      lastPopUpWindow = window.open(wpPath, "pirates_wallpaper", "width=1024,height=700,scrollbars=1,resizable=1,toolbar=0,status=0,location=0");
      break;
    
    // DOWNLOADS - Buddy Icons
    case "buddy-icon":
      var biPath   = pop.arguments[1];
      lastPopUpWindow = window.open(biPath, "pirates_buddyicons", "width=300,height=600,scrollbars=1,resizable=1,toolbar=0,status=0,location=0");
      break;
      
    // Games - Popups
    case "games":
      var popupPath   = pop.arguments[1];
      var popupWidth  = pop.arguments[2] || "750";
      var popupHeight = pop.arguments[3] || "500";
      lastPopUpWindow = window.open(popupPath, "pirates_game", "width="+popupWidth+",height="+popupHeight+",scrollbars=0,resizable=0,toolbar=0,status=0,location=0");
      break;
  }
    
  // Set Focus
  if (lastPopUpWindow) lastPopUpWindow.focus();
}
