
var lang   = "d";
var deubtn = null;
var engbtn = null;
var navb   = null;
var ctp    = null;
var btn    = new Array;
var currpg = 1;
var viewsm = false;
var smap   = null;

function getWindowWidth() {
    var w = 0;
    if ( window.innerWidth ) {
        w = window.innerWidth; // - 19;
    }
    else if ( document.documentElement && document.documentElement.clientWidth ) {
        w = document.documentElement.clientWidth;
    }
    else if ( document.body.clientWidth ) {
        w = document.body.clientWidth;
    }
    return w;
}

function getWindowHeight() {
    var h = 0;
    if ( window.innerHeight ) {
        h = window.innerHeight-4;
    }
    else if ( document.documentElement && document.documentElement.clientHeight ) {
        h = document.documentElement.clientHeight;
    }
    else if ( document.body.clientHeight ) {
        h = document.body.clientHeight;
    }
    return h;
}

function resizeHandler( e ) {
    var w = getWindowWidth();
    var h = getWindowHeight();
    if ( w >= 200 ) {
        smap.style.width  = "200px";
    }
    else {
        smap.style.width  = w + "px";
    }
    smap.style.height = ( h - 10 ) + "px";
    if ( w && w >= 480 ) {
        var remain = w - 480;
        if ( remain >= 425 ) {
            navb.style.left  = "480px";
            navb.style.width = ( w - 480 ) + "px";
            ctp.style.left   = "480px";
            ctp.style.width  = ( w - 480 ) + "px";
            ctp.style.height = ( h - 41  ) + "px";
            return;
        }
    }
    navb.style.left  = "0px";
    navb.style.width = w + "px";
    ctp.style.left   = "0px";
    ctp.style.width  = w + "px";
    ctp.style.height = ( h - 41 ) + "px";
}

function init() {
    var uri = location.href;
    var q_x = -1;
    if ( uri ) {
        q_x = uri.indexOf( '?' );
    }
    if ( q_x != -1 ) {
        var q_s = uri.substr( q_x + 1 );
        var nvp = q_s.split( "&" );
        var nvp_cnt = nvp.length;
        var i;
        for ( i=0; i < nvp_cnt; ++i ) {
            var str = nvp[i];
            if ( !str ) continue;
            var n_v = str.split( "=" );
            if ( n_v.length != 2 ) continue;
            if ( n_v[0] == "lang" ) {
                if ( n_v[1] >= "d" && n_v[1] <= "e" ) {
                    lang = n_v[1];
                }
            }
            if ( n_v[0] == "page" ) {
                if ( n_v[1] >= "1" && n_v[1] <= "6" ) {
                    currpg = n_v[1];
                }
            }
        }
    }
    deubtn = document.getElementById( "deutsch" );
    engbtn = document.getElementById( "english" );
    if ( lang == "d" ) {
        deubtn.src = "deutsch-down.png";
    }
    else {
        engbtn.src = "english-down.png";
    }
    deubtn.onmouseover = d_ov;
    deubtn.onmouseout  = d_ou;
    engbtn.onmouseover = e_ov;
    engbtn.onmouseout  = e_ou;
    btn[0] = document.getElementById( "button1" );
    btn[1] = document.getElementById( "button2" );
    btn[2] = document.getElementById( "button3" );
    btn[3] = document.getElementById( "button4" );
    btn[4] = document.getElementById( "button5" );
    btn[5] = document.getElementById( "button6" );
    navb   = document.getElementById( "navbar"  );
    var ary = new Array;
    ary[0] = 1;
    ary[1] = 3;
    ary[2] = 4;
    ary[3] = 5;
    ary[4] = 6;
    ary[5] = 2;
    var i;
    for ( i=0; i <= 5; ++i ) btn[i].src = imgpath( ary[i], false );
    btn[0].onmouseover = function (e) { b_ov( e, ary[0], btn[0] ); };
    btn[0].onmouseout  = function (e) { b_ou( e, ary[0], btn[0] ); };
    btn[1].onmouseover = function (e) { b_ov( e, ary[1], btn[1] ); };
    btn[1].onmouseout  = function (e) { b_ou( e, ary[1], btn[1] ); };
    btn[2].onmouseover = function (e) { b_ov( e, ary[2], btn[2] ); };
    btn[2].onmouseout  = function (e) { b_ou( e, ary[2], btn[2] ); };
    btn[3].onmouseover = function (e) { b_ov( e, ary[3], btn[3] ); };
    btn[3].onmouseout  = function (e) { b_ou( e, ary[3], btn[3] ); };
    btn[4].onmouseover = function (e) { b_ov( e, ary[4], btn[4] ); };
    btn[4].onmouseout  = function (e) { b_ou( e, ary[4], btn[4] ); };
    btn[5].onmouseover = function (e) { b_ov( e, ary[5], btn[5] ); };
    btn[5].onmouseout  = function (e) { b_ou( e, ary[5], btn[5] ); };
    ctp = document.getElementById( "contentpane"  );
    ctp.src = lang + currpg + ".html";
    smap = document.getElementById( "sitemap" );
    resizeHandler( null );
    window.onresize = resizeHandler;
}

function d_ov( e ) { deubtn.src = lang == "d" ? "deutsch-down.png" : "deutsch-over.png"; }
function d_ou( e ) { deubtn.src = lang == "d" ? "deutsch-down.png" : "deutsch-up.png"; }

function e_ov( e ) { engbtn.src = lang == "e" ? "english-down.png" : "english-over.png"; }
function e_ou( e ) { engbtn.src = lang == "e" ? "english-down.png" : "english-up.png"; }

function b_ov( e, i, b ) { if ( b ) b.src = imgpath( i, true  ); }
function b_ou( e, i, b ) { if ( b ) b.src = imgpath( i, false ); }

function loadpg( l, p ) {
    var langclause = "lang=" + l;
    var pageclause = "page=" + p;
    var uri = "index.html?" + langclause + "&" + pageclause;
    location.href = uri;
}

function imgpath( n, o ) {
    var base_str = "nonexistant";
    var modi_str = "";
    var result;
    // home blog project artwork extra contact
    switch ( lang ) {
        case 'd':
            switch ( n ) {
                case 1: base_str = "start"; break;
                case 3: base_str = "blogs"; break;
                case 4: base_str = "projekte"; break;
                case 5: base_str = "kunst"; break;
                case 6: base_str = "extras"; break;
                case 2: base_str = "kontakt"; break;
            }
            break;
        case 'e':
            switch ( n ) {
                case 1: base_str = "home"; break;
                case 3: base_str = "blogs"; break;
                case 4: base_str = "projects"; break;
                case 5: base_str = "artwork"; break;
                case 6: base_str = "extras"; break;
                case 2: base_str = "contact"; break;
            }
            break;
    }
    if ( currpg == n ) {
        modi_str = "-down";
    }
    else if ( o ) {
        modi_str = "-over";
    }
    else {
        modi_str = "-up";
    }
    result = base_str + modi_str + ".png";
    return result;
}

function smclk() {
    if ( smap ) {
        if ( viewsm ) {
            viewsm = false;
            smap.style.display = "none";
            smap.style.zIndex  = -1;
        }
        else {
            viewsm = true;
            smap.style.display = "block";
            smap.style.zIndex  = 2;
        }
    }
}


