/*
 *  @filename     cafe_functions.js
 *  @title        Cafe Function API
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @created      01.01.2006
 *  @modified     01.09.2008
 *
 *  @description  Cafe website function API.
 */
 
/*
 *  @function     getOSName
 *
 *  @description  Retrieves the name of the operating system the browser is
 *                currently running on.
 *
 *                Possible return values include:
 *
 *                  Windows
 *                  Macintosh
 *                  X11
 *
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *  @author       Nicholas Swierczek <nicholas.swierczek@tribaldawn.com>
 *
 *  @return       OSName          Name of the OS in string format.
 */
function getOSName(){
  var userAgent = navigator.userAgent;
  userAgent = userAgent.toLowerCase();
  var OSName;

  if(userAgent.match("windows")) OSName =  'Windows';
  else if(userAgent.match("mac")) OSName =  'Macintosh';
  else if(userAgent.match("x11")) OSName =  'X11';
  else OSName =  'Unknown';

  return OSName;
}// end function getOSName()

/*
 *  @function     getBrowser
 *
 *  @description  Retrieves the name of the browser currently in use.
 *
 *                Possible return values include:
 *
 *                  IE6
 *                  IE7
 *                  Opera
 *                  Konqueror
 *                  Safari
 *
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @return       browser     Name of browser in string format.
 */
function getBrowser(){
  var userAgent = navigator.userAgent;
  userAgent = userAgent.toLowerCase();
  var browser;

  if(userAgent.match("msie 6")) browser = 'IE6';
  else if(userAgent.match("msie 7")) browser = 'IE7';
  else if(userAgent.match("opera")) browser = 'Opera';
  else if(userAgent.match("konqueror")) browser = 'Konqueror';
  else if(userAgent.match("safari")) browser = 'Safari';
  else browser = 'Unknown';

  return browser;
}// end function getBrowser()

/*
 *  @function     fixIEPlugins
 *
 *  @description  Re-renders all OBJECT and EMBED tags within a given webpage
 *                to accommodate Internet Explorer's new court-ruled handling
 *                of active content.
 *
 *                THIS FUNCTION MUST BE CALLED ONLY AFTER THE LAST EMBED OR
 *                OBJECT TAG IN A GIVEN PAGE.  IT IS RECOMMENDED THAT IT BE
 *                RUN IN THE PAGE FOOTER.
 *
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @return       true            Boolean true.
 */
function fixIEPlugins(){
  objects = document.getElementsByTagName("object");
  for(var i=0;i<objects.length;i++){
    objects[i].outerHTML = objects[i].outerHTML;
  }// end for(var i=0;i<objects.length;i++)
  
  embeds = document.getElementsByTagName("embed");
  for(var i=0;i<embeds.length;i++){
    embeds[i].outerHTML = embeds[i].outerHTML;
  }// end for(var i=0;i<objects.length;i++)

  return true;
}// end function fixIEPlugins()

/*
 *  @function     playGame
 *
 *  @description  Starts gameplay, either via making the overlay visible or
 *                loading the game in a pop-up window, for Macintosh systems,
 *                to address a concurrent-rendering slowdown issue.
 *
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @return       true            Boolean true.
 */
function playGame(){
  var OSName = getOSName();
  var browser = getBrowser();

  if(OSName=='Macintosh') window.open('game_client_popup.php','gamewindow','width=766,height=557,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
  else if(browser.match("IE")) window.open('game_client_popup.php','gamewindow','width=766,height=557,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
  else{
/*
    openCloseByID('game_shader');
    openCloseByID('flash_title');
    openCloseByID('noflash_title');
    openCloseByID('nav_hider');
*/
    $("#game_shader, #flash_title, #noflash_title, #nav_hider").toggle();
  }// end else

  return OSName;
}// end function playGame()

/*
 *  @function     closeGame
 *
 *  @description  Closes the game overlay, if the user affirms this action on
 *                a pop-up prompt.
 *
 *  @author       Kevin Barsotti <kevin.barsotti@tribaldawn.com>
 *
 *  @return       true            Boolean true.
 */
function closeGame(){
  var closeIt = confirm("If you close the game, game play progress will be lost!");
  
  if(closeIt){
/*
    openCloseByID('game_shader');
    openCloseByID('flash_title');
    openCloseByID('noflash_title');
    openCloseByID('nav_hider');
*/
  $("#game_shader, #flash_title, #noflash_title, #nav_hider").toggle();
  }// end if(closeIt)
  
  return true;
}// end function closeGame()
