﻿List = function() {
    this.control;
    this.inter = null;
    this.Objektinter = null;
    this.ShowObjektInfo = null;
    this.objektContainerControl;
    this.timeOut = null;
    this.Stop = true;;
    this.GUID = ""
    this.ImageOpacity = 1;
    this.PopupOpacity = 0;
    this.TimeLoop = 20;
    this.imageurl;
    this.number;
    this.tempGUID;
    this.isActive = false;
}

List.prototype.ShowObjectInfo = function(imageurl, GUID, number) {
    this.imageurl = imageurl;
    this.number = number;
    this.tempGUID = GUID;

    if (this.GUID == GUID && !this.Stop) {
        this.ShowInfoAfterTimeOut()
    } else {
        clearTimeout(this.timeOut);
        if (this.GUID != '') {
            this.HideInfo();
        }
        this.ShowObjektInfo = $setTimeout(this, this.ShowInfoAfterTimeOut, 500);
        if (this.GUID != '') {
            this.setOpacity(document.getElementById("ObjektInfo" + this.GUID), 0);
        }
    }
}


List.prototype.ShowInfoAfterTimeOut = function() {
imageurl = this.imageurl;
    
    GUID = this.tempGUID;
    number = this.number;
    if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
        this.TimeLoop = 10;
    }

    if (this.GUID != GUID && this.GUID != "") {
        this.setOpacity(document.getElementById("ObjektInfo" + this.GUID), 0);
        document.getElementById("ObjektInfo" + this.GUID).style.display = "none";
        this.ImageOpacity = 1;
        this.PopupOpacity = 0;
    }

    clearTimeout(this.timeOut);
    this.control = document.getElementById("ObjektItem" + GUID);
    this.Stop = false;

    this.objektContainerControl = document.getElementById("ObjektInfo" + GUID);

    if (number <= 3) {
        this.objektContainerControl.style.top = ((this.control.offsetTop - 20) + "px");
    } else {
        this.objektContainerControl.style.top = ((this.control.offsetTop - 200) + "px");
    }


    if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
        this.objektContainerControl.style.display = "inline";
    }
    else {
        this.objektContainerControl.style.display = "table";
    }
    this.inter = $setTimeout(this, this.SetListOpacity, this.TimeLoop);
    this.Objektinter = $setTimeout(this, this.SetObjektContainerOpacity, this.TimeLoop);
    var textContainer = document.getElementById("ObjektInfoIMG" + GUID);
    if (textContainer.childNodes.length == 0 && imageurl != "") {
        var img = document.createElement('img');
        img.src = imageurl + "&q=100&cornerradius=10&cornercolor=white&width=300&height=220&ScaleAndClipMode=FitAndClip";
        textContainer.appendChild(img);
    }
}



List.prototype.HideObjectInfo = function(GUID) {
    this.GUID = GUID;
    this.timeOut = $setTimeout(this, this.HideInfo, 50);
}

List.prototype.HideInfo = function() {
    this.control = document.getElementById("ObjektItem" + this.GUID);
    clearTimeout(this.inter);
    clearTimeout(this.Objektinter);
    clearTimeout(this.ShowObjektInfo);
    this.inter = null;
    this.Objektinter = null;
    this.ShowObjektInfo = null;
    this.setOpacity(document.getElementById("ObjektInfo" + this.GUID), 0);
    document.getElementById("ObjektInfo" + this.GUID).style.display = "none";
    this.ImageOpacity = 1;
    this.PopupOpacity = 0;
    this.Stop = true;
    this.GUID = "";
    for (var i = 0; i < this.control.parentNode.childNodes.length; i++) {
        if (this.control.parentNode.childNodes[i].className == "ObjektItem")
            this.setOpacity(this.control.parentNode.childNodes[i], 1);
    }
}

List.prototype.SetListOpacity = function() {
if (!this.Stop) {
    this.ImageOpacity = this.ImageOpacity - 0.05;
        for (var i = 0; i < this.control.parentNode.childNodes.length; i++) {
            if (this.control.parentNode.childNodes[i].className == "ObjektItem" && this.ImageOpacity > 0.3) {
                this.setOpacity(this.control.parentNode.childNodes[i], this.ImageOpacity);
            }
            else if (this.control.parentNode.childNodes[i].className == "ObjektItem" && this.control.parentNode.childNodes[i].style != "undefined") {
            if (this.ImageOpacity <= 0.3)
                clearTimeout(this.inter);
            }
        }
        if(this.ImageOpacity > 0.3){
            this.setOpacity(this.control, 1);
            this.inter = $setTimeout(this, this.SetListOpacity, this.TimeLoop);
        }
    }
}

List.prototype.SetObjektContainerOpacity = function() {
if (!this.Stop) {
        if (this.PopupOpacity <= 1) {
            this.PopupOpacity += 0.03;
            this.setOpacity(this.objektContainerControl, this.PopupOpacity);
            this.Objektinter = $setTimeout(this, this.SetObjektContainerOpacity, this.TimeLoop);
        }
    }
}

List.prototype.setOpacity = function(element, opacity) {
if( element != null ){
    if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
        opacity *= 100;
        element.style.filter = 'alpha(opacity=' + opacity + ')';
    }
    else if (Sys.Browser.agent === Sys.Browser.Firefox) {
        element.style.MozOpacity = opacity;
    }
    else {
        element.style.KhtmlOpacity = opacity;
        element.style.opacity = opacity;
    }
    }
}