// Initialize the arrays containing our size info.

var pixelArray = new Array('7px','9px','11px','13px','15px','17px'); // Possible font px sizes p , b, a
var pixelArray2 = new Array('11px','13px','15px','17px','19px','21px'); // Possible font px sizes H1
var pixelArray3 = new Array('10px','12px','14px','16px','18px','20px'); // Possible font px sizes H2
var pixelArray4 = new Array('9px','11px','13px','15px','17px','19px'); // Possible font px sizes H3
var pixelArray5 = new Array('8px','10px','12px','14px','16px','18px'); // Possible font px sizes H4
var pixelArray6 = new Array('7px','9px','11px','13px','15px','17px'); // Possible font px sizes H5
var pixelArray7 = new Array('6px','8px','10px','12px','14px','16px'); // Possible font px sizes H6
var countOfPixels = pixelArray.length-1;
var initSize = 3; // Array position of inital px size

function fontSizer(inc) {
        /*if (!document.getElementById) return;*/

        var size = readCookie('size');
        size = parseInt(inc)+parseInt(size);
        if (size < 0 ) { size = 0; }
        if (size > countOfPixels ) { size = countOfPixels; }

        doFontSizing(size);

        createCookie("size", size, 365);
}

function fontSizerOnLoad(preferredSize) {
        /*if (!document.getElementById) return;*/

        var size = readCookie('size');

        if (size < 0 ) { size = 0; }
        if (size > countOfPixels ) { size = countOfPixels; }

        /*switchPic();*/
        doFontSizing(size);
}

function doFontSizing(theFontSize) {
        // Bugfix: Elements inside table would not resize with only the code below, so we do them seperatly.
        // NOTE: This only resizes the font, nothing else.
        // Resize by ID does not work with this.
        aTables = document.getElementsByTagName('p');
        for(i = 0; i < aTables.length; i++){
              if (aTables[i].parentNode.className != 'news' && aTables[i].parentNode.parentNode.parentNode.id != 'rechter_bereich')
                        aTables[i].style.fontSize = pixelArray[theFontSize];
        }

        aTables = document.getElementsByTagName('code');
        for(i = 0; i < aTables.length; i++){
              if (aTables[i].parentNode.className != 'tx-onetrandomcontent-pi1' && aTables[i].parentNode.parentNode.parentNode.id != 'rechter_bereich')
                        aTables[i].style.fontSize = pixelArray[theFontSize];
        }

        aTables = document.getElementsByTagName('a');
        for(i = 0; i < aTables.length; i++){
               if (aTables[i].parentNode.className != 'wechsel'&& aTables[i].parentNode.className != 'news' && aTables[i].parentNode.className != 'hauptnavigation_normal' && aTables[i].parentNode.className != 'navi' && aTables[i].parentNode.className != 'navi_act' && aTables[i].parentNode.className != 'subnavi' && aTables[i].parentNode.parentNode.className != 'subnavi_act' && aTables[i].parentNode.parentNode.parentNode.className != 'footer' && aTables[i].parentNode.parentNode.parentNode.parentNode.parentNode.id != 'hmenu' && aTables[i].parentNode.className != 'search' && aTables[i].parentNode.className != 'klickpfad' && aTables[i].parentNode.parentNode.id != 'toptensuche' && aTables[i].parentNode.parentNode.parentNode.parentNode.id != 'rechter_bereich' && aTables[i].parentNode.parentNode.parentNode.parentNode.parentNode.id != 'rechter_bereich' && aTables[i].innerHTML != 'Mehr...')

                        aTables[i].style.fontSize = pixelArray[theFontSize];

       }

       aTables = document.getElementsByTagName('table');
        for(i = 0; i < aTables.length; i++){
              if (aTables[i].parentNode.id != 'menu')
                        aTables[i].style.fontSize = pixelArray[theFontSize];
        }

        aTables = document.getElementsByTagName('b');
        for(i = 0; i < aTables.length; i++){
                        if (aTables[i].id != 'fett')

                        aTables[i].style.fontSize = pixelArray[theFontSize];
        }


        aTables = document.getElementsByTagName('li');
        for(i = 0; i < aTables.length; i++){
                        aTables[i].style.fontSize = pixelArray[theFontSize];
        }

        aTables = document.getElementsByTagName('h1');
        for(i = 0; i < aTables.length; i++){
                        aTables[i].style.fontSize = pixelArray2[theFontSize];
        }

        aTables = document.getElementsByTagName('h2');
        for(i = 0; i < aTables.length; i++){
                if (aTables[i].parentNode.parentNode.className != 'news')
                        aTables[i].style.fontSize = pixelArray3[theFontSize];
        }

        aTables = document.getElementsByTagName('h3');
        for(i = 0; i < aTables.length; i++){
                        aTables[i].style.fontSize = pixelArray4[theFontSize];
        }

        aTables = document.getElementsByTagName('h4');
        for(i = 0; i < aTables.length; i++){
                        aTables[i].style.fontSize = pixelArray5[theFontSize];
        }

        aTables = document.getElementsByTagName('h5');
        for(i = 0; i < aTables.length; i++){
                        aTables[i].style.fontSize = pixelArray6[theFontSize];
        }

        aTables = document.getElementsByTagName('h6');
        for(i = 0; i < aTables.length; i++){
                        aTables[i].style.fontSize = pixelArray7[theFontSize];
        }


        // if you rather want to size an individual element by ID, use this:
        // resizeContainer = document.getElementById('nameOfConainingElement');
        // and uncomment the if statements at the start of each function
        //resizeContainer = document.getElementsByTagName('body')[0];
        //resizeContainer.style.fontSize = pixelArray[theFontSize];

        //alert(theFontSize);

}

function normalSize() {
        /*if (!document.getElementById) return;*/

        var size = 3;

        doFontSizing(size);
        createCookie("size", size, 365);
}

function normalSizePrint() {
        /*if (!document.getElementById) return;*/

        var size = 3;

        doFontSizing(size);
}

/*function switchPic(size){
        theImage = document.getElementById('dIndexBanner').firstChild;
        imagePath = theImage.src;

}*/

function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "expires="+date.toGMTString();
        }
        else {
                expires = "";
        }
        var c=name+'='+value+'; '+expires+'; path=/';
        document.cookie = name+'='+value+'; '+expires+'; path=/';
}

function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' '){
                        c = c.substring(1,c.length);
                }
                if (c.indexOf(nameEQ) == 0) {
                        return c.substring(nameEQ.length,c.length);
                }
        }
        return initSize;
}

window.onload = function(e) {
        fontSizerOnLoad(readCookie("size"));
        //fontSizerOnLoad(4);
}
