﻿// JScript File
// © Alex Schana.
// NOTE: Dependent on cookie.js.

// defaults
var defaultFontIndex = 3;

// array of font sizes (smallest to largest, add to it as necessary)
// var fontSizes = new Array("xx-small", "x-small", "small", "medium", "large");
var fontSizes = new Array("9px", "10px", "11px", "12px", "13px", "14px", "15px");



// increase the font size
function fontUp()
{
    // locals
    var fontIndex;

    // get the current index or set to default if not found
    (!readCookie("fontIndex") ? fontIndex = defaultFontIndex : fontIndex = readCookie("fontIndex"));
    
    // increase the index, if we havent reached the style array upper bound
    if (fontIndex < (fontSizes.length - 1))
    {
        // increase
        fontIndex = ++fontIndex;
        
        // set style
        setFont(fontIndex);
    }
}


// decrease the font size
function fontDown()
{
    // locals
    var fontIndex;

    // get the current index or set to default if not found
    (!readCookie("fontIndex") ? fontIndex = defaultFontIndex : fontIndex = readCookie("fontIndex"));
     
    // decrease the index if we have not reached the lower bound of the style array
    if (fontIndex > 0)
    {
        // decrease
        fontIndex = --fontIndex;
                        
        // set style
        setFont(fontIndex);
    }
}


// sets the specified font size
function setFont(fontIndex)
{
    // store the font size
    createCookie("fontIndex", fontIndex, 1);

    if (document.body)
    {
       // set the style
       document.body.style.fontSize = fontSizes[fontIndex];
    }
}


// check for cookie before applying a users style pref.
// note: this is run while the script is being parsed, it is required that the page has been
//       loaded up until the beginning body tag in order to run correctly.
if (readCookie("fontIndex"))
{
    setFont(readCookie("fontIndex"));
}
