
/**
 * @author Richard Halupczok
 */
// ADJUST
var motivAdjust = {
    picW: 2000,
    picH: 600,
    maskF: 0,
    picF: 0,
    
    // FUNKTIONEN
    adjust: function(){
        this.get_factor();
        var div_pos1 = document.getElementById("pos1");
        var img_pic1 = document.getElementById("pic1");
        
        var div_pos2 = document.getElementById("pos2");
        var img_pic2 = document.getElementById("pic2");
        
        div_pos1.style.top = this.get_top(0);
        div_pos1.style.left = this.get_left();
        img_pic1.style.width = this.get_width();
        img_pic1.style.height = this.get_height();
        
        div_pos2.style.top = this.get_top(1);
        div_pos2.style.left = this.get_left();
        img_pic2.style.width = this.get_width();
        img_pic2.style.height = this.get_height();
    },
    // INTERNE FUNKTIONEN
    get_factor: function(){
        this.maskF = ML.docW() / (ML.docH() * 0.5);
        this.picF = this.picW / this.picH;
    },
    get_height: function(){
        if (this.picF < this.maskF) {
            var _H = Math.floor(ML.docW() / this.picF);
            return _H + "px";
        }
        else {
            return ML.docH() * 0.5 + "px";
        }
    },
    get_width: function(){
        if (this.picF < this.maskF) {
            return ML.docW() + "px";
        }
        else {
            var _W = Math.floor(ML.docH() * 0.5 * this.picF);
            return _W + "px";
        }
    },
    get_top: function(a){
        if (this.picF < this.maskF) {
            var _H = Math.floor(ML.docW() / this.picF);
            if (a === 0) {
               // var top = Math.floor((ML.docH() * 0.5 - _H) / 2);
                var top = Math.floor((ML.docH() * 0.5 - _H) / 1);
            }
            else {
                var top = Math.floor((ML.docH() * 0.5 - _H) / 2);
            }
            return top + "px";
        }
        else {
            return "0px";
        }
    },
    get_left: function(){
        if (this.picF < this.maskF) {
            return "0px";
        }
        else {
            var _W = ML.docH() * 0.5 * this.picF;
            var _left = Math.floor((ML.docW() - _W) / 2);
            return _left + "px";
        }
    }
};

// LAYOUT
//pic <img> festlegen
var setMotiv = function(){
    if (ML.motiv !== "") {
        document.getElementById("motiv_top").innerHTML = '<div id="pos1"><img id="pic1" src="pic/' + ML.motiv + '_top.jpg"></div>';
        document.getElementById("motiv_bottom").innerHTML = '<div id="pos2"><img id="pic2" src="pic/' + ML.motiv + '_bottom.jpg"></div>';
        motivAdjust.adjust();
    }
};
var adjust = function(){
    //ist motiv schon festgelegt 
    if (ML.motiv !== "") {
        motivAdjust.adjust();
    }
    var info = document.getElementById("info");
    info.innerHTML = "ML.motiv=" + ML.motiv;
    info.innerHTML += "<br/>top: " + motivAdjust.get_top();
    info.innerHTML += "<br/>left: " + motivAdjust.get_left();
    info.innerHTML += "<br/>width: " + motivAdjust.get_width();
    info.innerHTML += "<br/>height: " + motivAdjust.get_height();
};

//LISTENER
var setListener = function(){
    window.onresize = adjust;
};

//FUNCTIONEN AUFRUFE
setMotiv();
setListener();


