﻿/**
 * @author Tim
 */

var isW3C = false;
var isIE = false;
    if (document.addEventListener) {
        isW3C = true;
    }
    else {
        isIE = true;
    }
var AlbumName = "";
function galerie(e){
    var obj2;
    
    if (isW3C) {
        obj2 = e.target;
    }
    else 
        if (isIE) {
            e = window.event
            obj2 = e.srcElement;
        }
    if (obj2.id == "AlbumImage") {
        AlbumName = obj2.title;
        
    }
    else 
        if (obj2.id == "AlbumTitle") {
            AlbumName = obj2.innerHTML;
        }
        else 
            if (obj2.id == "linker") {
                AlbumName = obj2.getElementById("AlbumTitle").innerHTML;
            }
    var satz_array = new Array();
    satz_array = AlbumName.split(" ");
    AlbumName = satz_array.join("");
    satz_array = AlbumName.split(".");
    AlbumName = satz_array.join("");
    satz_array = AlbumName.split("ö");
    AlbumName = satz_array.join("o");
    satz_array = AlbumName.split("Ö");
    AlbumName = satz_array.join("O");
    satz_array = AlbumName.split("ä");
    AlbumName = satz_array.join("a");
    satz_array = AlbumName.split("Ä");
    AlbumName = satz_array.join("A");
    satz_array = AlbumName.split("ü");
    AlbumName = satz_array.join("u");
    satz_array = AlbumName.split("Ü");
    AlbumName = satz_array.join("U");

    window.startOverlay(AlbumName);
    return false;
}
function startOverlay(AlbumName) {
//add the elements to the dom
$("body")
.append('<div class="overlayer"></div><div class="contain"></div>')
.css({"overflow-y":"hidden"});
//animate the semitransparant layer
$(".overlayer").animate({"opacity":"0.6"}, 400, "linear");
//add the lightbox image to the DOM
$(".contain").html('<div class="obj" id="obj"></div>');
losgehts("/182.htm","obj");

}

function dorest() {
    //position it correctly after downloading
    var imgWidth = $(".contain .obj").width();
    var imgHeight = $(".contain .obj").height();
    $(".contain")
    .css({
    "top": "20px",
    "left": "50%",
    "width": imgWidth,
    "height": imgHeight,
    "margin-left":-(imgWidth/2) //to position it in the middle
})
.animate({"opacity":"1"}, 400, "linear");
// you need to initiate the removeoverlay function here, otherwise it will not execute.

$("#slide-inner").pwi({
    username: 'saloppe.dresden',
    mode: 'album',
    album: AlbumName,
    thumbSize: 160,
    showAlbumDescription: false,
    maxResults: 10000
    });

window.removeOverlay();
}

function removeOverlay() {
// allow users to be able to close the lightbox
$(".overlayer").click(function(){
$("body").css({"overflow-y":"visible"});
$(".contain, .overlayer").animate({"opacity":"0"}, 200, "linear", function(){
$(".contain, .overlayer").remove();
});
});
}
/* fin. */ 
/* Ajax */
function containeroff(wohin) {
    $(wohin).innerHTML = '';
}
var xmlHttp = false;
function losgehts(was,wohin) {
                    
    $(wohin).innerHTML = '';
   
    // IE
    if(window.ActiveXObject)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlHttp = false;
        }
    } else {
        // other
        try
        {
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            xmlHttp = false;
        }
    }
    if(!xmlHttp)
        alert("Error creating the XMLHttpRequest object.");
    
    process(was, wohin);
}
function process(was, wohin)
{
    // 0 - uninitialized
    // 1 - loading
    // 2 - loaded
    // 3 - interactice
    // 4 - complete

    this.handleServerResponse = function () {
        
        if(xmlHttp.readyState == 4)
        {
            if(xmlHttp.status == 200)
            {
                xmlResponse = xmlHttp.responseText;
//                xmlDocumentElement = xmlResponse.documentElement;
//                helloMessage = xmlDocumentElement.firstChild.data;
                document.getElementById(wohin).innerHTML = '' + xmlResponse + '';
                dorest();
            } else {
                alert("There was a problem accessing the server: " + xmlHttp.statusText);
            }
        }    
    }
    
    if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
    {
        xmlHttp.open("GET", was, true);
        xmlHttp.onreadystatechange = handleServerResponse;
        xmlHttp.send(null);
        
    } else
        setTimeout(function () {process(was, wohin);}, 1000);
}
