/**  HOWTO use it
*   Function created by: Mathieu Beausoleil
*
*   Put "CGUtilitiesFontSize" class on all container you want to apply the font change
*   To ignore a container, use the class "CGUtilitiesFontSizeIgnore"
*
*   Use CGUtilitiesFontSize(1) to add a pixel to the concerned container.
*   Use CGUtilitiesFontSize(1, bleh) to execute the "bleh" function after the modif.
**/
function CGUtilitiesFontSizeSmaller() {
    CGUtilitiesFontSize(-1);
    new Ajax.Request('/includes/ajax/set-preference.php?iNewSize='+iFontSize);
    return false;
}
function CGUtilitiesFontSizeBigger() {
    CGUtilitiesFontSize(+1);
    new Ajax.Request('/includes/ajax/set-preference.php?iNewSize='+iFontSize);
    return false;
}
function CGUtilitiesFontSize(sizeChange) {
    var aAllObjects = new Array();
    var iTotalSize = false;
    var aoContainers = $$('.CGUtilitiesFontSize', '.CGUtilitiesFontSize *');
    var aoIgnoredContainers = $$('#form-repertory *', '.CGUtilitiesFontSizeIgnore', '.CGUtilitiesFontSizeIgnore *');
    for(i=0;i<aoContainers.length;i++) {
        oContainer = aoContainers[i];
        ignore = false;
        for(z=0;z<aoIgnoredContainers.length;z++) {
            if (aoIgnoredContainers[z] == oContainer) { ignore = true; }
        }
        if (!ignore) {
            if (oContainer.className.indexOf('CGUtilitiesFontSizeIgnore') == -1) {
                iOldSize = oContainer.getStyle('fontSize').replace('px', '');
                if (!oContainer.getAttribute('rel')) { oContainer.setAttribute('rel', iOldSize); }
                iNewSize = parseInt(iOldSize) + sizeChange;
                /*if (oContainer.getStyle('display') != 'none') {
                aAllObjects[aAllObjects.length] = oContainer;
                }*/
                if (oContainer.getStyle('display') != 'none' && (iNewSize - parseInt(oContainer.getAttribute('rel'))) >= 0 && 3 >= (iNewSize - parseInt(oContainer.getAttribute('rel')))) {
                    if (oContainer.firstChild && oContainer.firstChild.nodeValue != null && oContainer.firstChild.nodeValue.strip() != '') {
                        if (iTotalSize === false) {
                            iTotalSize = (iNewSize - parseInt(oContainer.getAttribute('rel')));
                        }
                        iFontSize = iNewSize - parseInt(oContainer.getAttribute('rel'));
                        /*alert(oContainer.firstChild.nodeValue);*/
                        oContainer.style.fontSize = iNewSize+'px';
                    }
                }
            }
        }
    }
    // Fix pour bug de position absolute bottom sous IE6
    if (navigator  && navigator.appVersion && (navigator.appVersion).indexOf("MSIE 6.")!=-1) {
        iHeight = $($('footer').parentNode).getHeight();
        $('footer').setStyle({
            top: iHeight+'px'
        });
    }
}
