﻿/// <reference path = "jquery-1.3.2-vsdoc.js" />

/* sets the ID of the body selector to a specified value, used to facilitate current page indication*/
function setBodyId(name) {
    $("body").attr("ID", name);
}


function setStyle(titleName) {
    var hasTitle = false;
    $("link[rel*=style][title]").each(
				function() {
				    this.disabled = true;
				    if (this.title == titleName) {
				        this.disabled = false;
				        hasTitle = true;
				    }
				});
    if (hasTitle)
        createCookie("style", titleName, 365);
}

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 var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var searchName = name + "=";
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
        var c = cookies[i];
        while (c.charAt(0) == ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(searchName) == 0)
            return c.substring(searchName.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    writeCookie(name, "", -1);
}

//this should look for #textSizer and obly do something if it finds it
//if IE browser only run if greater than 6
function fontResizer(tag, minsz, maxsz) {
    var version = 7;
    if ($.browser.msie) {
        version = $.browser.version.substring(0,1);
    }
    if (version >= 7) {
        if (tag == null) tag = "body";
        if (!minsz) minsz = 6;
        if (!maxsz) maxsz = 35;
        var baseSize = parseFloat($(tag).css('font-size'), 10);
        $("<ul class='ulSizer'><li><span class='szLabel'>Text Size</span></li></ul>").appendTo("#textSizer");

        $("<li><a href='#' class='sizer' id='larger'  title='increase'>+</a></li>").appendTo("#textSizer .ulSizer");
        $("<li><a href='#' class='sizer' id='smaller' title='decrease'>-</a></li>").appendTo("#textSizer .ulSizer");
        $("<li><a href='#' class='sizer' id='reset' title='reset'>o</a></li>").appendTo("#textSizer .ulSizer");

        $(".sizer").click(function(event) {
            var originalSize = $(tag).css('font-size');   //returns eg. 15px
            var sizeValue = parseFloat(originalSize, 10);   //get the numeric value
            var sizeType = originalSize.slice(-2);         //get the type eg. px

            if (this.id == "larger" && (sizeValue * 1.4) <= maxsz) {
                $(tag).css('font-size', sizeValue * 1.4 + sizeType);
            }
            else if (this.id == "smaller" && (sizeValue / 1.4) >= minsz) {
                $(tag).css('font-size', sizeValue / 1.4 + sizeType);
            }
            else if (this.id == "reset") {
                $(tag).css('font-size', baseSize);
            }
            return false;
        });
    }
}




