// JavaScript-Library
// Projekt: thomascook-reisen.de
// (c)2003 Denkwerk GmbH

//--------------------------------------------------------------------------------
// Umgebungsvariablen definieren
//--------------------------------------------------------------------------------

var ns = (document.layers)? true : false;
var ie = (document.all)? true : false;
var w3c = ((document.getElementById) && (!document.all))? true : false; // ie5 kennt getElementById auch

//Variablen je nach Browser und Version mit Werten belegen
var version = parseInt(navigator.appVersion);
var agent = navigator.userAgent.toLowerCase();

if ((agent.indexOf("compatible") == -1) && (version >= 5)) {
    //alert("Netscape 6");
    var obj = document.getElementById;
       var styleObj = ".style";
       var sichtbar = 'visible';
    var unsichtbar = 'hidden';

    }
if (agent.indexOf("msie") != -1) {
    //alert("IE");
    var obj = document.all;
       var styleObj = ".style";
    var sichtbar ="visible";
    var unsichtbar = "hidden";

    }
if ((agent.indexOf("compatible") == -1) && (version < 5)) {
    //alert("Netscape 4");
    var obj = document.layers;
    var styleObj = "";
       var sichtbar = "show";
    var unsichtbar = "hide";

}


//--------------------------------------------------------------------------------
// Öffnet Fenster (popup) mit freien Parametern
//--------------------------------------------------------------------------------

function openPopup(theURL,winName,features) {
  a=window.open(theURL,winName,features);
  a.focus();
  return false;
}


//--------------------------------------------------------------------------------
// Öffnet Fenster (popup) für TC-Karte Flugziele
//--------------------------------------------------------------------------------

  function openFlugziele() {
    self.window.name="main";
    page = window.open('flugziele2003/index.html','thomascook','status=yes,toolbar=no,location=no,scrolling=no,resizable=no,width=745,height=475');
    page.focus();
    page.moveTo((screen.availWidth - 745) / 2, (screen.availHeight - 475) / 2);
  }


//--------------------------------------------------------------------------------
// Öffnet Presse-Popup und plaziert dieses in der Bildschirmmitte
//--------------------------------------------------------------------------------

function openPressePopup(url){
var parameter = 'width=595,height=550,left='+eval((screen.width-w)/2)+',,resizable=yes,scrollbars=yes,location=no,menubar=yes,toolbar=no';

    a = window.open(url,DruckPresse,parameter);
    a.focus();
    return false;

}

//--------------------------------------------------------------------------------
// Druckt aktuelle Seite
//--------------------------------------------------------------------------------

function printText()
{
 if ((!ns) && (!w3c))
 {
  // Focus auf den Frame lenken welcher gedruckt werden soll
  window.focus();
  // BrowserObject ,,Print Box,, anlegen
  var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box
  WebBrowser1.outerHTML = "";
 }
 else
 {
  window.print();
 }
}

//--------------------------------------------------------------------------------
// Öffnet Fenster (popup) und plaziert dieses in der Bildschirmmitte
//--------------------------------------------------------------------------------

function openContentPopup(url, winName, w, h){

var parameter = 'width='+w+',height='+h+',left='+eval((screen.width-w)/2)+',top=50,scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no';

    a = window.open(url,winName,parameter);
    a.focus();
    return false;

}



//--------------------------------------------------------------------------------
// Öffnet "Reisevideos"-Fenster (popup)
//--------------------------------------------------------------------------------

function openVideoPopup(param) {
  a=window.open('http://www.travelstream.com/popup.php?' + param, 'Travelstream','width=500,height=455,resizable=0');
  a.focus();
  return false;
}



//--------------------------------------------------------------------------------
// Öffnet neues Content-Fenster (popup) und plaziert dieses in der Bildschirmmitte
// inserted by Oliver Klein
//--------------------------------------------------------------------------------

function openTCPopup(url, w, h){

var parameter = 'width='+w+',height='+h+',left='+eval((screen.width-w)/2)+',top=50,scrollbars=1,resizable=no,location=no,menubar=no,toolbar=no';


if (self.window.name != "popupOK" ) {
    self.window.name == "popupOK"
    thomascookwin = window.open(url,'thomascook',parameter);
    window.thomascookwin.focus();
    }
else {
    if (window.thomascookwin.closed == true) {
        thomascookwin = window.open(url,'thomascook',parameter);
        window.thomascookwin.focus();
        }
    else {
        window.thomascookwin.location.href=url;
        window.thomascookwin.resizeTo(w,h);
        window.thomascookwin.focus();
        }
    }
}



/**
*    Dynamisches Menü für das Thomas Cook Web
*   @author <joerg.gutsche@denkwerk.com>
*   Beschreibung:<br>
*   Das Menü liegt in einem sichtbaren relativen Layer (#container)
*   Die Menüpunkte sind im Ausgangszustand versteckt.
*   Jeden neuen Menüpunkt fügt man dem MenuHandler mit addToMain/addToSub hinzu.
*   Beispiel:
*   menuHandler.addToMain(new myDiv("head",0,0,1,true));
*   menuHandler.addToMain(new myDiv("aldiana",0,0,2,true));
*   Die Positionen werden automatisch durch die Content-Höhe der Layer ermittelt
*   Die SubMenüpunkte heißen wie die Hauptmenüpunkte mit dem Präfix "sub"
*   Den Startzustand erreicht man durch Aufruf der init() Methode des MenuHandlers
*   Die Links in den Hauptnavigationspunkten rufen showSubMenu(layerName) auf, wobei layerName der
*   Name des Layers ist (ohne "sub")
*   Die Links in der Subnavigation rufen hideSubMenu(layerName), wieder ohne "sub"
*/

/**
*    minimalistic Browser object
*    checks for ie4, ns4, ns6
*
*/
function thisClient(){
    this.ns = (document.layers)? true : false;
    this.w3c = (document.getElementById) ? true : false;
    this.ms = (document.all)&& (!this.w3c) ? true : false;
}

var nav = new thisClient(); // initialize browser object

var menuInitialOpen = null;


/* constructor function for cross-browser layer (ns4,6, msie > 4) */
function myDiv(id,top,left,zI,isNested){
    this.id = id;
    this.isNested = isNested;

    /* get the browser pointer*/
    if (nav.ns){
        if (this.isNested) {
            this.css = document.layers['container'].document.layers[id];
            this.doc = document.layers['container'].document.layers[id].document;
        } else {
            this.css = document.layers[id];
            this.doc = document.layers[id].document;
        }
    }

    else if (nav.ms) this.css = document.all[id].style;
    else if (nav.w3c) this.css = document.getElementById(id).style;

    if (nav.ms) this.doc = document.all[id];
    if (nav.w3c) this.doc = document.getElementById(id);

    this.contentHeight;
    this.isActive = false;
    this.ActiveIndex = 0;

        /* have the browser point to the right attributes */

        this.css.top = top;
        this.css.left = left;
        this.css.zIndex = zI;
        if (nav.ns || nav.w3c){ this.x = this.css.left; this.y = this.css.top; }
        else if (nav.ms){   this.x = this.css.pixelLeft; this.y = this.css.pixelTop; }

        this.getContentHeight = getContentHeight;
        this.swapVis = swapVis;
        this.moveTo = moveTo;
        this.moveBy = moveBy;
        this.getX = getX;
        this.getY = getY;
        this.getVisibility = getVisibility;
        this.getName = getName;
}

/** verschiebt den Layer im koordinatensystem zur Position x/y*/
function moveTo(x,y){
    this.x = x;
    this.y = y;
    this.css.left = x;
    this.css.top = y;
}

/** verschiebt den Layer im koordinatensystem  um x/y px */
function moveBy(x,y){
    this.x = x;
    this.y = y;

    if (nav.ns){
        this.css.top += this.y;
        this.css.left += this.x;
    } else {
        this.css.top = parseInt(this.css.top) + this.y +'px';
        this.css.left = parseInt(this.css.left) + this.x +'px';
    }
}

/** ändert die Sichtbarkeit */
function swapVis(bol){
    if (nav.ns) visibility = (bol)? "show" : "hide";
    else visibility = (bol)? "visible" : "hidden";
    this.css.visibility = visibility;
}

/** errechnet die Höhe des Layers */
function getContentHeight(){
        if (nav.ns)    return this.contentHeight = this.css.clip.height;
        else if (nav.w3c) return this.contentHeight = document.getElementsByTagName('div')[this.id].offsetHeight;
        else if (nav.ms) return this.contentHeight = document.all[this.id].scrollHeight;//offsetHeight;
}

/** holt die Position auf der x-Achse */
function getX(){
     if (arguments.length > 0) return parseInt(this.css.left) + arguments[0];
    else return parseInt(this.css.left);

 }
/** holt die Position auf der y-Achse */
function getY(){
    if (arguments.length > 0) return parseInt(this.css.top) + arguments[0];
    else return parseInt(this.css.top);
}

/** erfragt die Sichtbarkeit */
function getVisibility(){
    return this.css.visibility;
}

/** erfragt den Namen/Id */
function getName(){
    return this.id;
}

/**
* ist für das Zusammenspielen der einzelnen Mmenüs verantwortlich
*/
function  MenuHandler (){
    this.headerHeight = 20; //Höhe der Überschrift, muß beim Errechnen der Höhe abgezogen werden
    this.arrMainMenuObjects = new Array(0); // die Hauptlayer
    this.arrSubMenuObjects = new Array(0); // die Sublayer
    this.subLength = 0;
    this.mainLength = 0;

    this.addToMain = addToMain;
    this.addToSub = addToSub;
    this.positionAll = positionAll;
    this.showMain = showMain;
    this.showSubMenu = showSubMenu;
    this.hideSubMenu = hideSubMenu;
    this.getSubLength = getSubLength;
    this.getMainLength = getMainLength;
    this.moveFollowUps = moveFollowUps;
    this.hideSubMenues = hideSubMenues;
    this.init = init;

}

/** positioniert die Layer und setzt sie auf Sichtbar */
function init(){
    window.setTimeout("this",300);
    this.positionAll();
    this.showMain();
    if ( menuInitialOpen != null) menuHandler.showSubMenu( menuInitialOpen );
}

/** holt die Anzahl der TopLayer*/
function getMainLength(){
    return this.mainLength;
}

/** holt die Anzahl der Sublayer*/
function getSubLength(){
    return this.subLength;
}

/** fügt einen Hauptlayer hinzu */
function addToMain(inMainItem){
    this.arrMainMenuObjects[inMainItem.getName()] = inMainItem;
    this.mainLength++;
}

/** fügt einen Sublayer hinzu */
function addToSub(inSubItem){
    this.arrSubMenuObjects[inSubItem.getName()] = inSubItem;
    this.subLength++;
}

/** positioniert die Layer */
function positionAll(){
    startTop = 0;
    for (var key in this.arrMainMenuObjects){
        this.arrMainMenuObjects[key].moveTo(0,startTop);
        startTop +=  this.arrMainMenuObjects[key].getContentHeight();
    }
}

/** zeigt alle Hauptlayer */
function showMain(){
    for (var key in this.arrMainMenuObjects){
        this.arrMainMenuObjects[key].swapVis(true);
    }

}

function hideSubMenues(){
    for (var key in this.arrSubMenuObjects){
        this.arrSubMenuObjects[key].swapVis(false);
    }
}

/** tauscht den Haupt- gegen den Sublayer*/
function showSubMenu(layerName){
    this.hideSubMenues();
    this.positionAll();
    this.showMain();
    this.arrSubMenuObjects['sub' + layerName].moveTo(0,this.arrMainMenuObjects[layerName].getY());
    this.moveFollowUps(layerName,true);
    this.arrMainMenuObjects[layerName].swapVis(false);
    this.arrSubMenuObjects['sub' + layerName].swapVis(true);

}
/** tauscht den Sub- gegen den Hauptlayer */
function hideSubMenu(layerName){
    this.arrSubMenuObjects['sub' + layerName].swapVis(false);
    this.moveFollowUps(layerName,false);
    this.arrMainMenuObjects[layerName].swapVis(true);
    this.arrMainMenuObjects[layerName].getY();

}

/** verschiebt alle nachfolgenden Layer. vs: starte mit 2px Versatz zur Vermeidung von Lücken */
function moveFollowUps(startLayer,down){
    height = this.arrSubMenuObjects['sub' + startLayer].getContentHeight() - this.headerHeight - 2;
    distance = (down)? height : height * (-1);
    hasReachedClickedMenu = false;
    for (var key in this.arrMainMenuObjects){
        if (hasReachedClickedMenu){
            this.arrMainMenuObjects[key].moveBy(0,distance);
        }
        if (key == startLayer) hasReachedClickedMenu = true;
    }




}

var menuHandler = new MenuHandler();
