// Media Player JavaScript
// Basically does Window Resizing at the minute - ensures everything is correct
// all javascript written afresh by
// Andrew Bowden, http://www.planetbods.org/


/* 
This file basically boils down to "Be Nice to Opera".  
Opera 8.5 seems to open a window of size width x height - where 
width and height INCLUDE the title bar, window frame etc.  Most 
other browsers use width x height as the content area, then add 
on the title bar and window etc.  So what we do, is we check 
what size our window is (including window frame), what our content 
area is, and what our content area should be, and adjust as apporiate.

It's turned on for all browsers which support outerWidth and innerWidth (Opera, Moz, maybe Konq and Safari too?)
*/

function initPlayer() {
  if (document.getElementsByTagName) {
    var em = document.location.href ;
    qS = em.split("?")[1] ;
    for (var i=0 ; i < qS.split("&").length ; i++ ) {
      j = qS.split("&")[i] ;
      j = j.split("=") ;
      if (j[0] == "width") { var width = j[1] ; }
      if (j[0] == "height") { var height = j[1] ; }
    }
    if (self.innerHeight) {
      width = eval(self.outerWidth - self.innerWidth + parseInt(width)) ;
      height = eval(self.outerHeight - self.innerHeight + parseInt(height)) ;

      // Real Audio use RealPlayer - controller height is 36
      if (em.indexOf(".ra") != -1) {
        var height = "150" ;
        width = "300" ;
        target = "media" ;
      }
      // MP3 use Windows Media Player - the controller height is 46
      if (em.indexOf(".mp3") != -1) {
        var height = "150" ;
        width = "300" ;
        target = "media" ;
      }
      // M4U use QuickTime - the controller height is 16
      if (this.href.indexOf(".m4a") != -1) {
        var height = "120" ;
        width = "300" ;
        target = "media" ;
      }
      // MOVs and MPEGs use QuickTime - the controller height is 16
      if (em.indexOf(".mov") != -1 || em.indexOf(".mpg") != -1) {
        var height = eval(height)+16+49 ;
        if (width < 300) { width = 300 ; }
        target = "media" ;
      }
      // RealMedia uses RealPlayer - the controller height is 36
      if (em.indexOf(".rm") != -1 ) {
        var height = eval(height)+36+49 ;
        if (width < 300) { width = 300 ; }
        target = "media" ;
      }
      // WMVs use Windows Media Player - the controller height is 46
      if (em.indexOf(".wmv") != -1 ) {
        var height = eval(height)+46+49 ;
        if (width < 300) { width = 300 ; }
        target = "media" ;
      }
      window.resizeTo(width,height) ;

    } 
  }
  window.focus() ;  
}

YAHOO.util.Event.addListener(window,'load',initPlayer);

