var loadBigImage = '<br><br><br><center><img src="img/loading.gif" /></center><br><br><br>';

function ajaxLoader(url, id) {
    $(id).innerHTML = loadBigImage;
    setTimeout('ajaxLoad("' + url + '", "' + id + '");', 500);
}

function ajaxLoad(url, id, clbk) {
    if (document.getElementById) {
        var x = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
    }
    if (x) {
        x.onreadystatechange = function () {
            if (x.readyState == 4) {
                el = document.getElementById(id);
                el.innerHTML = x.responseText;
                if (clbk) clbk();
            }
        };
        x.open('GET', url, true);
        x.send(null);
    }
    hs.close();
    if (win) win.close();
}
var win;
var maxW;
var maxH;

function openGalery(url, title, w, h) {
    setResizedDims();
    if (w > maxW) w = maxW;
    if (h > maxH) h = maxH;
    if (win) win.close();
    win = new Window({
        className: 'vista_glass',
        title: title,
        top: 120,
        right: 22,
        width: w,
        height: h,
        destroyOnClose: true,
        resizable: true,
        closable: true,
        minimizable: false,
        maximizable: true,
        minWidth: 100,
        minHeight: 100
    });
    win.setURL(url);
    win.show();
    win.setConstraint(true, {
        left: 10,
        right: 20,
        top: 10,
        bottom: 10
    });
    win.toFront();
}

function setResizedDims() {
    var w = 800;
    var h = 600;
    if (typeof (window.innerWidth) == 'number') {
        w = window.innerWidth;
        h = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    maxW = w;
    maxH = h - 200;
}

function openFirstGalery() {
    setTimeout('galeryCodeHTML("atelier", "Atelier");', 1222);
}

function openFirstArchiv() {
    setTimeout('ajaxLoader("archiv/2011-11-27.html", "ArchivDIV");', 1222);
}

function openPresse(url) {
    setTimeout('presseCodeHTML("' + url + '");', 1222);
}

function openCarmelo() {
    ajaxLoader("carmelo.html", "ContentDIV");
}

function startMap() {
    if (win) win.close();
    setTimeout('loadMap();', 1222);
}

function presseCodeHTML(url) {
    hs.close();
    $("PresseDIV").innerHTML = loadBigImage;
    if (url.indexOf('.html') < 0) setTimeout('$("PresseDIV").innerHTML = "<img src=' + url + ' />";', 500);
    else setTimeout('ajaxLoader("' + url + '","PresseDIV");', 500);
}

function openMarimboGalery() {
    galeryCodeHTML("2009-marimbo", "Marimbo- Jazzduo");
}
