// ***  conf Variablen *** //

// neues HauptFenster: FlashBaumAnsicht
var cFTborder   = 15; // Mindestabstand des Fensters vom Bildschirmrand
// neue Fenster
var wfTimeout = 200; // delay nach dem neu geöffnetes Fenster einen Focus bekommt
var cwVonOben = 20;  // Abstand neu zu öffnender Fenster vom oberen Bildschirmrand
// ScreenShotWindow
var cssBreite   = 820; // größte Breite der ScreenShots
var cssHoehe    = 620; // größte Höhe der ScreenShots
// Pfade
var cssPfad     = '/static';   // absoluter Pfad zu den ScreenShots
var ceiPfad     = '';   // absoluter Pfad zu den ScreenShots


// *** windowFeatures *** //
// Objekt zur Aufnahme/Vordefinition von Optionen der window.open()-Methode
function windowFeatures() {
    this.breite      = 400;   // Fensterhöhe
    this.hoehe       = 500;   // Fensterbreite
    this.directories = 'no';  // LinkLeiste (Personal Toolbar Folder)
    this.location    = 'no';  // AdressEingabe
    this.menubar     = 'no';  // HauptMenü
    this.scrollbars  = 'yes'; // ScrollBalken
    this.status      = 'no';  // StatusZeile (unten)
    this.toolbar     = 'no';  // WerkzeugLeiste
    this.resizable   = 'yes'; // Fenster in der Größe veränderbar?

    this.vonOben     = '0';   // Abstand der linken oberen Fensterecke von oben
    this.vonLinks    = '0';   // Abstand der linken oberen Fensterecke von links
}
// Generierung des Zeichenkette für die Optionen der window.open()-Methode
function windowFeaturesStringTogether() {
    this.ausgabe =  'width='        + this.breite;
    this.ausgabe += ',height='      + this.hoehe;
    this.ausgabe += ',directories=' + this.directories;
    this.ausgabe += ',location='    + this.location;
    this.ausgabe += ',menubar='     + this.menubar;
    this.ausgabe += ',scrollbars='  + this.scrollbars;
    this.ausgabe += ',status='      + this.status;
    this.ausgabe += ',toolbar='     + this.toolbar;
    this.ausgabe += ',resizable='   + this.resizable;

    // NN4+
    this.ausgabe += ',screenX=' + this.vonLinks;
    this.ausgabe += ',screenY=' + this.vonOben;

    // IE4+
    this.ausgabe += ',left=' + this.vonLinks;
    this.ausgabe += ',top='  + this.vonOben;
}
windowFeatures.prototype.stringTogether = windowFeaturesStringTogether;


// weitere Behandlung eines geöffneten Fensters
var aktTitel = "";
function processWindow(winHandleStr, url, titel, bildPfad, winFocus) {
    if (eval(winHandleStr + ".fertig")) { // Fenster schon fertig?
        winHandle = eval(winHandleStr);

	// Inhalt des Fenster entspricht aufgerufener URL?
	if(!winHandle.document.images.iScreenShot) {
		if (winHandle.location.pathname != url) winHandle.location.href = url;
        } else {
		if (winHandle.location.href.indexOf(url) == -1) winHandle.location.href = url;
	}	


        // Titel übernehmen
        if (document.getElementById || document.all) {
            winHandle.document.title = titel;
            aktTitel = titel; // redundante Titelverarbeitung
        }

        // screenShot Spezial
        if (winHandle.location.href.indexOf(cssPfad) != -1 && bildPfad.length > 0) {
	    winHandle.document.images.iScreenShot.src = bildPfad;
        }

        // Focus für das neue Fenster
        if (winFocus && window.focus) setTimeout(winHandleStr + ".focus()", wfTimeout);


    } else { // Fenster noch nicht fertig? -- gleich noch mal probieren
        setTimeout("processWindow(\"" + winHandleStr + "\", \"" +  url + "\", \"" + titel + "\", \"" + bildPfad + "\", " + winFocus + ")", 100);
    }


}

// generelle Funktion für die window.open()-Methode
function openWindow(winHandleStr, url, winName, optionen, titel, bildPfad) {
    if (!bildPfad) var bildPfad = '';
    var oeffnen = true;
    if (eval(winHandleStr) && !eval(winHandleStr + '.closed'))
        oeffnen = false;
 
    // öffnen, falls nötig
    if (oeffnen) {
        optionen.stringTogether();
        eval(winHandleStr + ' = window.open("' + url + '", "' + winName + '", "' + optionen.ausgabe + '");');
    }

    // zusatzFenster weiter verarbeiten
    processWindow(winHandleStr, url, titel, bildPfad, true);
}



// *** Methoden *** //

// makeFlashTreeWindow
// Öffnen eines Fensters für den Flash-Baum
var flashTreeWindow = null;
function makeFlashTreeWindow(url, titel) {
    var optionen = new windowFeatures();
    optionen.breite   = (window.screen.width)? window.screen.width - 2 * cFTborder - 10 : 700; // bißchen schmaler wegen fenster-deko
    optionen.hoehe    = (window.screen.height)? window.screen.height - 2 * cFTborder - 50 : 500; // bißchen niedriger wegen fenster-deko und startleiste
    optionen.scrollbars = 'yes';
	optionen.vonLinks = cFTborder;
    optionen.vonOben  = cFTborder;

    //openWindow('flashTreeWindow', url, 'flashTree', optionen, titel)
	optionen.stringTogether();
    window.open(url, "flashTree", optionen.ausgabe);
    return false;
}

// makeExtendedInfoWindow
// Öffnen eines Fensters zur Anzeige von Zusätzlichen Informationen aus dem System
var extendedInfoWindow = null;
function makeExtendedInfoWindow(url, titel) {
    var optionen = new windowFeatures();
    optionen.breite   = 400;
    optionen.hoehe    = 500;
	optionen.scrollbars = 'yes';
	optionen.vonLinks = (window.screen.width)? Math.ceil((window.screen.width-optionen.breite)/2) : 0;
    optionen.vonOben  = cwVonOben;
		var eiFullURL = ceiPfad + url;

    openWindow('extendedInfoWindow', eiFullURL, 'extended', optionen, titel)
    return false;
}

// showScreenshotWindow
// Öffnen eines Fensters zur Anzeige von Screenshots
var screenshotWindow = null;
function showScreenshot(bildPfad, titel) {
    var optionen = new windowFeatures();
    optionen.breite   = cssBreite;
    optionen.hoehe    = cssHoehe;
    optionen.vonLinks = cwVonOben;
    optionen.vonOben  = cwVonOben;
    var ssFullHtmlURL = cssPfad + '/screenshot.html'

    openWindow('screenshotWindow', ssFullHtmlURL, 'screenshot', optionen, titel, bildPfad);
    return false;
}

// showScreenshotWindow
// Öffnen eines Fensters zur Anzeige von Screenshots
var screenshotWindow = null;
function showScreenshotNeu(screenshotHtml, bildPfad, titel) {
    var optionen = new windowFeatures();
    optionen.breite   = cssBreite;
    optionen.hoehe    = cssHoehe;
    optionen.vonLinks = cwVonOben;
    optionen.vonOben  = cwVonOben;

    openWindow('screenshotWindow', screenshotHtml, 'screenshot', optionen, titel, bildPfad);
    return false;
}

// aktScreenshotWindow
// Aktualisieren der Fensters (Screenshots, extended Info)
function aktWindows(url, bildPfad, titel) {
    if (screenshotWindow && !screenshotWindow.closed) {
		   var ssURL = screenshotWindow.location.href;
		   processWindow("screenshotWindow", ssURL, titel, bildPfad, false)
    }
    if (extendedInfoWindow && !extendedInfoWindow.closed) {
		   var eiFullURL = ceiPfad + url;
       var keinBild  = "";
		   processWindow("extendedInfoWindow", eiFullURL, titel, keinBild, false)
    }
}

// makeNoteEditWindow
// Öffnen eines Fensters zur Bearbeitung einer Notiz
var noteEditWindow = null;
function makeNoteEditWindow(url, titel) {
    var optionen = new windowFeatures();
    optionen.breite   = 400;
    optionen.hoehe    = 400;
    optionen.vonLinks = (window.screen.width)? Math.ceil((window.screen.width-optionen.breite)/2) : 0;
    optionen.vonOben  = cwVonOben;

    openWindow('noteEditWindow', url, 'notedit', optionen, titel)
    return false;
}

// makeExternalLinkWindow
// Öffnen eines Fensters zu einer externen URL
function makeExternalLinkWindow(url, titel) {
    alert('Bitte <a href="' + url + '" target="externLink"> nutzen!');
    return false;
}


var SearchWindow = null;
function makeSearchWindow(url) {
    var optionen = new windowFeatures();
    optionen.breite   = 410;
    optionen.hoehe    = 450;
	optionen.scrollbars = 'yes';
    optionen.vonLinks = (window.screen.width)? Math.ceil((window.screen.width-optionen.breite)/2) : 0;
    optionen.vonOben  = cwVonOben;
  
    openWindow('SearchWindow', url, 'searchwindow', optionen, '')

}
var HelpWindow = null;
function makeHelpWindow(url) {
    var optionen = new windowFeatures();
    optionen.breite   = 320;
    optionen.hoehe    = 420;
   optionen.scrollbars='yes'; optionen.vonLinks = (window.screen.width)? Math.ceil((window.screen.width-optionen.breite)/2) : 0;
    optionen.vonOben  = cwVonOben;
    openWindow('HelpWindow', url, 'helpwindow', optionen, '')
}


// resize
// uebergibt dem Flash die neuen Variablen fuer height und width des flashframes
// funktioniert leider nicht in allen Netscape/Mozilla Versionen, deshalb wird SetVariable 
// nur fuer den InternetExplorer aufgerufen
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function resize(winhandler) {
  if (InternetExplorer) {
    var frameheight = self.frames[0].document.body.offsetHeight;
    var framewidth = self.frames[0].document.body.offsetWidth;
    winhandler.flashmovie.SetVariable("new_flash_h", frameheight);
    winhandler.flashmovie.SetVariable("new_flash_w", framewidth);
    winhandler.flashmovie.SetVariable("new_size", 1);
  }
}

