$(document).ready( function () { 
    var page = {
        /*  0:buttonname de, 1:buttonname en  */
        home: ['home', 'home'],
        kontakt: ['kontakte', 'contact'],
        dienstleistungen: ['dienstleistungen', 'services'],
        referenzen: ['referenzen', 'references'],
        aktuelles: ['aktuelles', 'current'],
        publikationen: ['publikationen','publications'],
        kooperation: ['kooperationen','cooperations'],
        information: ['information', 'information']     
     };
     
    /*  get path to top directory  */ 
 
    var loc =  document.location.href;
    var end = loc.lastIndexOf('/');
    var start = loc.lastIndexOf('/', end-1);
    var dir = loc.substring(start, end);
    end = start;
    start = loc.lastIndexOf('/', end-1);
    var parentDir = loc.substring(start, end);
    var topDir = './';
    if (dir == '/en' || dir == '/de')
        topDir = '../';
    else if (parentDir == '/de' || parentDir == '/en')
            topDir = '../../';
    
    var imgDir = topDir+'grafik';
    var currentBtn = imgDir +'/btn_'+ page[window.currentPage][window.currentLang];

     $('#menu-l1 a img, #menu-l2 a img').each( function () {
        var oldSrc = $(this).attr('src');
        var ext = oldSrc.substring(oldSrc.length-3);
        var base = oldSrc.substring( 0, oldSrc.length-7);
        var loSrc = base + '_lo.' + ext;
        var hiSrc = base + '_hi.' + ext;
        
        if (base != currentBtn ) {
            $(this).hover( 
                function () { $(this).attr('src', hiSrc)} , 
                function () { $(this).attr('src', oldSrc) } );
        } else {
            $(this).attr('src', hiSrc)   
        } 
    }); 
    
    // change href for language buttons so that it links to
    // the page according to the current page
    var hrefStr = '';
    if (window.currentLang==1) {    // if english 
        if (window.currentPage=='home') {
            hrefStr = topDir;  /*  main index.php in top dir */
            // hrefStr = topDir+'de';   /*  main index.php in /de dir */
        } else {
            hrefStr = topDir+'de/'+window.currentPage;
        }
    } else {                        // if german
        if (window.currentPage=='home') { 
            hrefStr = topDir+'en/';
        } else { 
            hrefStr = topDir+'en/'+window.currentPage;
        }    
    } 
    $('#menu-l1 a').eq(1).attr('href', hrefStr ); 
   
});


