﻿/* START font.js */
var Font =
{
    current: 13,
    baseSize: 9,
    heightDiff: undefined,
    buttonSmall: undefined,
    buttonMedium: undefined,
    buttonLarge: undefined,
    elem: undefined,
    increase: function(elem) {
        this.current = this.checkInt(Cookies.gc('fs'), this.current);
        this.current += (this.current >= 18 ? 0 : 1);
        this.setSize(elem, this.current);
        Cookies.ac('fs', this.current, 1440, document.domain);
    },
    decrease: function(elem) {
        this.current = this.checkInt(Cookies.gc('fs'), this.current);
        this.current -= (this.current <= 9 ? 0 : 1);
        this.setSize(elem, this.current);
        Cookies.ac('fs', this.current, 1440, document.domain);
    },
    initFont: function(small, medium, large, elemName) {
        this.buttonSmall = { top: document.getElementById(small[0]), bottom: document.getElementById(small[1]), size: small[2] };
        this.buttonMedium = { top: document.getElementById(medium[0]), bottom: document.getElementById(medium[1]), size: medium[2] };
        this.buttonLarge = { top: document.getElementById(large[0]), bottom: document.getElementById(large[1]), size: large[2] };
        this.elem = document.getElementById(elemName);
        var previousSize = Cookies.gc('fontSize');

        if (previousSize != undefined)
            this.setSize(previousSize);
        else	//default to medium
            this.setSize(this.buttonMedium.size);
    },
    setSize: function(v, ev) {
        var ccol = document.getElementById("contentcol");
        if (ccol != undefined && ev != undefined && this.heightDiff == undefined) {
            this.heightDiff = ccol.offsetHeight - this.elem.offsetHeight;
        }
        if (this.elem != undefined && this.elem.style) {
            v = this.checkInt(v, this.current);
            var curSize = this.current;

            if (this.elem.currentStyle) //for IE
                curSize = parseInt(this.elem.currentStyle.fontSize);
            else if (window.getComputedStyle) //for firefox
                curSize = parseInt(window.getComputedStyle(this.elem, "").getPropertyValue("font-size"));

            if (isNaN(curSize)) curSize = this.current;
            this.baseSize = curSize;
            this.applyToChildren(this.elem, v - curSize);
        }
        var rcol = document.getElementById("rghtcol");
        var lcol = document.getElementById("lftcol"); ;
        if (rcol != undefined && lcol != undefined && ccol != undefined && this.elem != undefined) {
            ccol.style.overflow = "visible";
            lcol.style.height = rcol.style.height = ccol.style.height = this.elem.offsetHeight + this.heightDiff;
            ccol.style.overflow = "hidden";
        }

        if (ev != undefined) {
            Cookies.ac('fontSize', v, 525600, "ninemsn.com.au");
            var e = ev.srcElement ? ev.srcElement : ev.target;
            var srcId = e.id;
            this.setSelectedClass(this.buttonSmall, srcId);
            this.setSelectedClass(this.buttonMedium, srcId);
            this.setSelectedClass(this.buttonLarge, srcId);
        }
        else {
            this.setStoredClass(this.buttonSmall, v);
            this.setStoredClass(this.buttonMedium, v);
            this.setStoredClass(this.buttonLarge, v);
        }
    },
    applyToChildren: function(elem, v) {
        if (elem != undefined && elem.style) {
            //set to current element
            var curSize = this.current;
            if (elem.currentStyle) //for IE
                curSize = parseInt(elem.currentStyle.fontSize);
            else if (window.getComputedStyle) //for firefox
                curSize = parseInt(window.getComputedStyle(elem, "").getPropertyValue("font-size"));

            if (isNaN(curSize)) curSize = this.current;
            /*if(elem.parentElement.style.fontSize != "" && elem.style.fontSize == "")
            elem.style.fontSize = (parseInt(elem.parentElement.style.fontSize) + (curSize - this.baseSize)) + "px";
            else
            */
            elem.style.fontSize = (parseInt(curSize + v) >= 9) ? parseInt(curSize + v) + "px" : "9px";

            //go through all children and apply to them
            //for(var currentElem = elem.firstChild; currentElem != undefined; currentElem = currentElem.nextSibling)
            //	this.applyToChildren(currentElem, v);
        }
    },
    checkInt: function(i, dv) {
        if (!dv) dv = 0;
        var iv = parseInt(i);
        return (iv.toString() == "NaN" ? dv : iv);
    },
    setSelectedClass: function(btnSet, srcId) {
        if ((btnSet.top != undefined && btnSet.top.id == srcId) || (btnSet.bottom != undefined && btnSet.bottom.id == srcId)) {
            if (btnSet.top != undefined) btnSet.top.className = "selected";
            if (btnSet.bottom != undefined) btnSet.bottom.className = "selected";
        }
        else {
            if (btnSet.top != undefined) btnSet.top.className = "";
            if (btnSet.bottom != undefined) btnSet.bottom.className = "";
        }
    },
    setStoredClass: function(btnSet, size) {
        if (btnSet.size == size) {
            if (btnSet.top != undefined)
                btnSet.top.className = "selected";
            if (btnSet.bottom != undefined)
                btnSet.bottom.className = "selected";
        }
        return;
    }
}
/* END font.js */







