
// ----------------------- popin manager class -------------------------------
// class instance is created at the bottom of this page

//function faderclass() {
//    this.obj;
//    this.startopacity;
//    this.endopacity;
//}

//faderclass.prototype.getticks = function () { return new Date(); }
//faderclass.prototype.fade = function (obj, startopa, endopa) {
//    this.obj = obj;
//    this.startopacity = startopa
//    this.endopacity = endopa;
//}

//faderclass.prototype.setopacity = function (opa) {
//    if (this.obj.MozOpacity != null) { this.obj.MozOpacity = (opa / 100) - .001; }
//    else if (this.obj.opacity != null) { this.obj.opacity = (opa / 100) - .001; }
//    else if (this.obj.filter != null) { this.obj.filter = "alpha(opacity=" + opa + ")"; }
//}


//-------------------------

function popinmanagerclass() {
    this.mousex = 100
    this.mousey = 100
    this.lastclickid = -1
    this.lastChooserType = ""
    this.usedimming = true;
    this.hidepopinbyrefresh = false; //true = popin fjernes ved at reloade siden. Altid 'one-shot' -> resettes ved reload

    this.obj;


    //fading
    this.fadeinprogress = false
    this.startTime = new Date();
    this.fadestartticks;
    this.fadeendticks;
    this.fadeduration = 150;
    this.fromopacity;
    this.toopacity;
    this.closewhendone;

    this.init()

    this.maininterval = setInterval("popinmanager.updatefading()", 60) //setInterval('popinmanager.updatefading()', 40);
}



popinmanagerclass.prototype.init = function () {
    var sty = 'z-index:1023;position:absolute;left:0;top:0;height:100%;width:100%;background-color:white;visibility: hidden;filter: alpha(opacity=60);-moz-opacity:.60;opacity:.60;';
    var str = '<div name="popinmanagerdimmerdiv" id="popinmanagerdimmerdiv" style="' + sty + '" onclick="popinmanager.hidepopin();"></div>';
    sty = 'z-index:1024;position:absolute;top:100px;left:100px;width:500px;height:280px;visibility:hidden;background-color:white;border-top:1px solid #333333;border-left:1px solid #333333;border-right:2px solid #333333;border-bottom:2px solid #333333;';
    str += '<iframe style="' + sty + '" id="popinmanageriframe" name="popiniframe" scrolling="no" src="/sharedResources/class_popinmanagerEmpty.htm" noresize frameborder="0"></iframe>';
    document.write(str);
    this.obj = document.getElementById('popinmanageriframe').style;
}

popinmanagerclass.prototype.empty = function () { }

popinmanagerclass.prototype.setusedimming = function (booval) { this.usedimming = booval; }
popinmanagerclass.prototype.setusehidebyrefresh = function (booval) { this.usedhidepopinbyrefreshimming = booval; }

popinmanagerclass.prototype.setxy = function (e) {
    if (document.all) { // grab the x-y pos.s if browser is IE
        mousex = event.clientX + document.body.scrollLeft
        mousey = event.clientY + document.body.scrollTop
    } else {  // grab the x-y pos.s if browser is NS
        mousex = e.pageX
        mousey = e.pageY
    }
    // catch possible negative values in NS4
    if (mousex < 0) { mousex = 0 }
    if (mousey < 0) { mousey = 0 }
    return true
}

//traditional
popinmanagerclass.prototype.showpopin = function (url, x, y, w, h) {
    this.preparepopin(url, x, y, w, h)
    this.makevisible()
}


//showpopin	. call x/y with : -1 (centered) 'm' (centered on mousepos) , anyval (specific location)
popinmanagerclass.prototype.preparepopin = function (url, x, y, w, h) {
    var sty = this.obj
    var wh = this.getwidthheightarray()
    var clientwh = this.getclientwidthheightarray()
    var lt = this.getscrolllefttoparray()
    if (x == 'm') {
        x = mousex - (w / 2);
        if (x < lt[0]) { y = lt[0] }
    }
    else { if (x == -1) { x = (clientwh[0] / 2) - (w / 2) + lt[0]; } }

    if (y == 'm') {
        y = mousey - (h / 2);
        if (y < lt[1]) { y = lt[1] }
    }
    else { if (y == -1) { y = (clientwh[1] / 2) - (h / 2) + lt[1]; } }

    document.getElementById('popinmanageriframe').src = url
    sty.left = x + 'px';
    sty.top = y + 'px';
    sty.width = w + 'px';
    sty.height = h + 'px';
    if (this.usedimming) {
        var dimsty = document.getElementById('popinmanagerdimmerdiv').style
        dimsty.width = wh[0] + 'px';
        dimsty.height = wh[1] + 'px';
    }
    if (FLVhideall) { FLVhideall() } //hide flv below - to avoid bleeding
}


//resizepopin	    
popinmanagerclass.prototype.resizepopin = function (w, h) {
    if (document.getElementById('popinmanageriframe')) {
        var sty = this.obj;
        sty.width = w + 'px';
        sty.height = h + 'px';
        //alert('w ' + w + ' after ' + this.obj.width)
    }
}

//resizepopin med automatisk centrering	    
popinmanagerclass.prototype.resizepopincentered = function (w, h) {

    if (document.getElementById('popinmanageriframe')) {
        var sty = this.obj;
        var wh = this.getwidthheightarray()
        var clientwh = this.getclientwidthheightarray()
        var lt = this.getscrolllefttoparray()
        x = (clientwh[0] / 2) - (w / 2) + lt[0];
        y = (clientwh[1] / 2) - (h / 2) + lt[1];
        sty.left = x + 'px';
        sty.top = y + 'px';
        sty.width = w + 'px';
        sty.height = h + 'px';
    }
}

popinmanagerclass.prototype.movepopinto = function (w, h) {
    if (document.getElementById('popinmanageriframe')) {
        var sty = this.obj;
        sty.left = w + 'px';
        sty.top = h + 'px';
    }
}

popinmanagerclass.prototype.getpopinleft = function () {
    if (document.getElementById('popinmanageriframe')) {
        return parseInt(this.obj.left);
    }
}

popinmanagerclass.prototype.getpopintop = function () {
    if (document.getElementById('popinmanageriframe')) {
        return parseInt(this.obj.top);
    }
}


//hidepopin
popinmanagerclass.prototype.hidepopin = function () {
    if (this.usedhidepopinbyrefreshimming) {
        document.location.reload();
    }
    else {
        document.getElementById('popinmanagerdimmerdiv').style.visibility = 'hidden';
        this.startfading(100, 0, true);

    }
}

//fader - start
popinmanagerclass.prototype.getticks = function () { return new Date(); }

popinmanagerclass.prototype.makevisible = function () {
    if (this.usedimming) { document.getElementById('popinmanagerdimmerdiv').style.visibility = 'visible'; }
    this.startfading(0, 100, false);
}

popinmanagerclass.prototype.updatefading = function () {
    if (!this.fadeinprogress) { return; } //no fading in progress
    var prog = this.getticks() - this.fadestartticks
    var useopa = this.fromopacity + parseInt((prog / this.fadeduration) * ((this.toopacity - this.fromopacity)))
    if (this.toopacity > this.fromopacity && useopa > this.toopacity) { useopa = this.toopacity }
    if (this.toopacity < this.fromopacity && useopa < this.toopacity) { useopa = this.toopacity }
    this.setopacity(useopa);
    if (useopa == this.toopacity) { this.endfading() }
}

popinmanagerclass.prototype.endfading = function () {
    this.fadeinprogress = false;
    if (this.closewhendone) {
        document.getElementById('popinmanageriframe').src = '/sharedResources/class_popinmanagerEmpty.htm';
        this.obj.visibility = 'hidden';
        if (FLVshowall) { FLVshowall() } //show flv below again - hidden on showpopin to avoid bleeding
    }
}

popinmanagerclass.prototype.startfading = function (from, to, closewhendone) {
    this.fromopacity = from;
    this.toopacity = to
    this.closewhendone = closewhendone;
    this.setopacity(this.fromopacity);
    this.obj.visibility = 'visible';  //'visible';
    this.fadestartticks = this.getticks();
    this.fadeinprogress = true;
}

popinmanagerclass.prototype.setopacity = function (opa) {
    if (this.obj.MozOpacity != null) { this.obj.MozOpacity = (opa / 100) - .001; }
    else if (this.obj.opacity != null) { this.obj.opacity = (opa / 100) - .001; }
    else if (this.obj.filter != null) { this.obj.filter = "alpha(opacity=" + opa + ")"; }
}

//fader - end


popinmanagerclass.prototype.popinishidden = function () {
    return (this.obj.visibility == 'hidden') ? true : false;
}

popinmanagerclass.prototype.getwidthheightarray = function () {
    var x = 0, y = 0;
    if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
        //DOM compliant
        x = document.body.scrollWidth
        y = document.body.scrollHeight
    } else if (document.documentElement && (document.documentElement.scrollWidth || document.documentElement.scrollHeight)) {
        //IE6 standards compliant mode
        y = document.documentElement.scrollHeight;
        x = document.documentElement.scrollWidth;
    }
    return [x, y];
}

popinmanagerclass.prototype.getclientwidthheightarray = function () {
    var w = -1, h = -1;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        w = window.innerWidth;
        h = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    return [w, h]
}

popinmanagerclass.prototype.getscrolllefttoparray = function () {
    var x = 0, y = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        y = window.pageYOffset;
        x = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    }
    return [x, y];
}


//autocreate object - after declarations
var popinmanager = new popinmanagerclass()













