// Copyright Thomas Schoch, Essen, Germany


var picOnscreen = false  // a picture is displayed on the screen
var w                    // handle for opened picture window

function picture(picture, width, height, title, color) {

    // close open window if present
    if (picOnscreen == true) {
        if (!w.closed) w.close()
        picOnscreen = false;
    }

    // load appropriate style sheet and calculate window size 
    // and position depending on the screen resolution

    if (screen.availHeight < 715) {
        var res = "lo"
        var wwidth  = width + 100
        var wheight = height + 60
    } else {
        var res = "hi"
        var wwidth  = width + 200
        var wheight = height + 200
    }

    var mleft = (screen.availWidth - wwidth) / 2
    var mtop  = 5
    var border = ""

    if (color)
        // if background is not white, don't draw a border
        border = 'style=\"border-style:none\"'
    else
        // default color is white
        color = 'white'

    // open separate window
    w = window.open('','',' \
    screenY=' + mtop + ',screenX=' + mleft + ', \
    top=' + mtop + ',left=' + mleft + ', \
    width=' + wwidth + ',height=' + wheight + ', \
    resizable=no,scrollbars=no,scrolling=no,menubar=no');


    if (!w) {

        // popup window blocked?
        location.replace("index-no-popup.html")

    } else {

        w.document.open()
        picOnscreen = true

        w.document.writeln("<head><title>"+title+"</title>")
        w.document.writeln("<meta http-equiv=\"imagetoolbar\" content=\"no\">")
        w.document.writeln("<meta name=\"generator\" content=\"javascript\">")
        w.document.writeln("<link rel=\"STYLESHEET\" href=\"picture_"+res+"res.css\" type=\"text/css\">")
        w.document.writeln("</head>")
        w.document.writeln("<body style=\"background-color:"+color+"\"><div align=center>")
        w.document.writeln("<a href=\"javascript:self.window.close()\"")
        w.document.writeln("onfocus=\"if (this.blur) this.blur()\">")
        w.document.writeln("<img class=pic src=\"pic/"+picture+"\"")
        w.document.writeln("width="+width+" height="+height+" "+border+"")
        w.document.writeln("title=\"Zum Schlie&szlig;en klicken\"></a>")
        w.document.writeln("<div class=back>Fenster")
        w.document.writeln("<a href=\"javascript:self.window.close()\"")
        w.document.writeln("onfocus=\"if (this.blur) this.blur()\">")
        w.document.writeln("<img src=\"close-light.gif\" width=19 height=19 border=0")
        w.document.writeln("style=\"vertical-align:middle;border-style:none\"")
        w.document.writeln("title=\"Fenster schlie&szlig;en\" name=\"CL\"")
        w.document.writeln("onMouseOver=\"document.images['CL'].src = 'close-dark.gif';\"")
        w.document.writeln("onMouseOut=\"document.images['CL'].src = 'close-light.gif';\"></a>")
        w.document.writeln("schließen</div></div></body></html>")

        w.document.close()
    }
}

function book() {
    var b = window.open('../bilderbuch/index.html#Titel','',' \
    screenY=5,screenX=5,top=5,left=5,width=1000,height=600, \
    menubar=no,status=no,toolbar=no,scrollbars=no,scrolling=no')
    // popup window blocked?
    if (!b) location.replace("../bilderbuch/index.html#Titel")
}

function loadcss(path) {

    // load appropriate style sheet depending on the screen resolution
    if (screen.availHeight < 768)
        var css = path + "_lores.css"
    else
        var css = path + "_hires.css"
    document.writeln("<link rel=\"stylesheet\" href=\"" +
    css + "\" type=\"text/css\">");
}
