/* --  File Paths  -- */
var wpFile        = 'downloads/desktops/desktop.html';
var wpSpecialFile = 'downloads/bonus/bonus.html';
var biFile        = 'downloads/buddyicons/buddyicons.html';
var esFile        = 'downloads/sigs/sigs.html';
var wdFile        = 'downloads/widget/widget.html';
var ssFile        = 'downloads/screensavers/ss.html';
var wgFile        = 'fat/widget/index.html';

/* --  PopUp  -- */
function pop (sCase) {
  // Argument Test
  //alert (sCase + '  ' +  pop.arguments[1]+ '  ' +  pop.arguments[2]);
  
  switch(sCase) {
 	/* --  Downloads   -- */
  // Buddy Icon
  case 'buddyicon' :
    var iconId = pop.arguments[1];
    popup(biFile+'?icon='+iconId, 400, 400, 'buddyicon', 'yes', 'no', 'auto', 'no', 'no', 'no');
    break;
    
  // Email Sig
  case 'sigs' :
    var iconId = pop.arguments[1];
    popup(esFile+'?sigs='+iconId, 400, 540, 'EmailSigs', 'yes', 'no', 'auto', 'no', 'no', 'no');
    break;
	
  // Widget
  case 'widget' :
    var iconId = pop.arguments[1];
    popup(wdFile, 600, 720, 'Widget', 'yes', 'no', 'auto', 'no', 'no', 'no');
    break;
    
    // Find a Theater Widget
  case 'fatwidget' :
    var iconId = pop.arguments[1];
    popup(wgFile, 300, 250, 'findatheater', 'yes', 'no', 'auto', 'no', 'no', 'no');
    break;
  
  // Screensaver   
  case 'ss':
    var os = pop.arguments[1];
    popup(ssFile, 400, 540, 'ss', 'yes', 'no', 'auto', 'no', 'no', 'no');
    break;
  
  // Wallpaper
  case 'wallpaper':
      // Get Image Width And Image Number
      var name = pop.arguments[1];
      var size = pop.arguments[2];
      // Force New Window
      popup (wpFile+'?name='+name+'&size='+size, 850, 500, 'wallpaper', 'yes', 'no', 'yes', 'no', 'no', 'no');
      break;
  
  /* --  GAMES   -- */
  case 'games':
    var gameID = pop.arguments[1];
    // Switch GAME Via GAMEID
    switch (gameID) {
      case "namethat":
        popup ('games/namethat/index.html', 800, 600, 'games', 'no', 'no', 'auto', 'no', 'no', 'no');
        break;
      case "whattype":
        popup ('games/whattype/index.html', 800, 600, 'games', 'no', 'no', 'auto', 'no', 'no', 'no');
        break;
      }
	  // close games
      break;
	
	/* -- Games Returning To Site -- */
	case 'visitHome':
	  var isHomeOpen = window.opener;
	  if (isHomeOpen) {
	    if (window.opener.location == "http://www.imax.com/underthesea") {
	      window.opener.location.reload(true);
	    } else {
	      window.opener.location = "http://www.imax.com/underthesea";
	    }
	  } else {
	    window.open ("../../", "map", "");
	  }
	  break;
	
  } 
}

// Make Popup Windows
function popup (url, w, h, windowName, r, st, s, l, m, t) {
  var win;
  //w = 5;
  //h += 15;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  win = window.open (url, windowName, 'height=' +h+ ', width=' +w+ ', resizable=' +r+ ', status= ' +st+ ', scrollbars=' +s+ ', location=' +l+ ', menubar=' +m+  ', toolbar= ' +t+ ', left='+winl+', top='+wint);
  win.focus();    
}