/* ================================================================================

   RADIO DRS - WEBPLAYER

   Switch der angezeigten Fenster/ Divs
   
   ----------------------------------------------------------------------
   2007-09-xx  hahnax  init
   hahnax: Axel Hahn (webmaster@srdrs.ch)
   ================================================================================
*/

// ----------------------------------------------------------------------
// CONFIG
// ----------------------------------------------------------------------
var i=-1;
var aDivs = new Array();

// Namen der DIVs - s. /lib/player/radio.php

  i++;
  aDivs[i]=new Object();
    aDivs[i]["div"]="mini";
    aDivs[i]["menu"]="bmin";    
  i++;
  aDivs[i]=new Object();
    aDivs[i]["div"]="playerinfos";
    aDivs[i]["menu"]="bmax";    
  i++;
  aDivs[i]=new Object();
    aDivs[i]["div"]="mediaerror";
    aDivs[i]["menu"]="bmediaerror";
  i++;
  aDivs[i]=new Object();
    aDivs[i]["div"]="einstellungen";
    aDivs[i]["menu"]="bsettings";    


var sLastPlayerDiv="playerinfos";

// ----------------------------------------------------------------------
// Zeige ein bestimmtes DIV an ... blende die anderen aus
function showDiv(sDivID){
  // Sichtbarkeit der DIVs
  for (var i=0; i < aDivs.length; i++ ) {
     if (aDivs[i]["div"]==sDivID) {
        if (document.getElementById(aDivs[i]["div"]).style.display == 'none') {
          // if (!IsMSIE()) $('#'+sDivID+'').fadeIn(500);
          document.getElementById(aDivs[i]["div"]).style.display = 'block';
          
       }
       if (aDivs[i]["menu"]) {
          document.getElementById(aDivs[i]["menu"]).className="active";
          // document.getElementById(aDivs[i]["menu"]).childNodes[0].style.backgroundImage = 'url(transparent url(/static/global/service_navigation_right_100.png)';
       }
     } else {
        if (document.getElementById(aDivs[i]["div"]) && document.getElementById(aDivs[i]["div"]).style.display == 'block')
          document.getElementById(aDivs[i]["div"]).style.display = 'none';
        if (document.getElementById(aDivs[i]["menu"]) && aDivs[i]["menu"])
          document.getElementById(aDivs[i]["menu"]).className="";
     }
  }
  // letztes PlayerDiv merken
  if (sDivID=="playerinfos" || sDivID=="mini" || sDivID=="mediaerror") {
    sLastPlayerDiv=sDivID;
  }
  updateWindowSize(false);
  //if (sDivID=="mini" || sDivID=="mediaerror" || sDivID=="einstellungen") updateWindowSize(false);
  // else  updateWindowSize(true, iWindowHeight);

} // function showDiv(sDivID)


// inner width+height
function getViewportDimensions() {
    var intH = 0, intW = 0;

    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    }
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }
    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}

// Groesse des Fensters anpassen - nur FF kann innerHeight setzen
function updateWindowSize(bBiggerOnly, iMinHeight){
  if (!iMinHeight || iMinHeight<270) iMinHeight=270;
  var iRandUnten=45;
  var iRand2=70; // Aufschlag fuer Funktion window.resizeTo (Titelleiste, ggf. Adresszeile)
  var iW1;
  var iPopupWidth=424; // ggf. durch window-Variable belegbar
  var iH1; // aktuelle Fensterhöhe innen
  var iH2; // neue Fensterhöhe innen
  // var iH2Max=700; // max. Hoehe des Fensters

  iTmp=getViewportDimensions();
  if (iTmp.height){
    iH1=iTmp.height;
    // if (window.outerHeight) iRand2=window.outerHeight-iH1;
  }

  if (iTmp.width) iW1=iTmp.width;
  if (!iW1 || iW1<iPopupWidth) iW1=iPopupWidth;

  if (document.getElementById("containerPlayer"))
    iH2=document.getElementById("containerPlayer").scrollHeight + document.getElementById("containerPlayer").offsetTop + iRandUnten;

  if (iMinHeight && iH2<iMinHeight) iH2=iMinHeight;
  // if (iH2>iH2Max) iH2=iH2Max;
  if (iH2>(screen.height-iRand2)) iH2=screen.height-iRand2;
  if ( iH1<iH2  || !bBiggerOnly) {

    window.resizeTo(iW1, iH2 + iRand2); // zuerst die sichere Variante: Aussenhöhe des Fenster
    window.innerHeight=iH2; // falls es ein Browser kann: innerHeight setzen - ist die sichere Variante
  }
}

