$(document).ready(function() {
    $('#searchTxt').focus(function() {
        if($(this).val() == 'What do you want to find?') {
            $(this).val('');
            $(this).addClass('active');
        }
    });

    if($.cookie("css")) {
	$("#mainStyleSheet").attr("href",$.cookie("css"));
    }
    $("#accessbilityTools li.ss a").click(function() {
            $("#mainStyleSheet").attr("href",$(this).attr('rel'));
            $.cookie("css",$(this).attr('rel'), {expires: 365, path: '/'});
            return false;
    });

    $('#searchTxt').blur(function() {
        if($(this).val() == '') {
            $(this).val('What do you want to find?');
            $(this).removeClass('active');
        }
    });

    var sfEls = document.getElementById("n").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }

    // show text resizing links
    //$(".textsize").show();
    var $cookie_name = "textsize";
    var originalFontSize = $("html").css("font-size");
    var currentFontSizeNum = parseFloat(originalFontSize, 10);
    //alert(originalFontSize);

    if($.cookie($cookie_name)) {
        $("#regFont").removeClass("selected");
        $("#largestFont").removeClass("selected");
        $("#largeFont").removeClass("selected");
        var newFontSize, newNotSoBigFontSize;
        
        var $getSize = $.cookie($cookie_name);
        if($getSize=='large') { $('#largeFont').addClass('selected'); newFontSize = 17; newNotSoBigFontSize = 16.9; }
        if($getSize=='largest') { $('#largestFont').addClass('selected'); newFontSize = 18.5; newNotSoBigFontSize = 16.9; }
        if($getSize=='reg') { $('#regFont').addClass('selected'); newFontSize = 16; newNotSoBigFontSize = 16; }


        $("html").css({fontSize : newFontSize + "px"});
        $(".noresize").css("font-size", newNotSoBigFontSize+ "px");
    } else {
        $.cookie($cookie_name, 'reg',{expires: 365, path: '/'});
    }

    // reset link
    $("#regFont").bind("click", function() {
        convertSize('reg');
        //$(".noresize").css("font-size", newNotSoBigFontSize);
        return false;
    });

    // text "+" link
    $("#largeFont").bind("click", function() {
        convertSize('large');
        //$(".noresize").css("font-size", newNotSoBigFontSize);
        return false;
    });

    // text "+" link
    $("#largestFont").bind("click", function() {

        convertSize('largest');
        //$(".noresize").css("font-size", newNotSoBigFontSize);
        return false;

    });

    function convertSize(newSize) {
        currSelected = $("#resizeTools .selected").attr("id");
        //alert(currSelected);
        var currentFontSize = $("html").css("font-size");
        currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize, newNotSoBigFontSize;

        switch(currSelected) {
            case 'regFont':  
                /* do stuff */
                if(newSize=='large') { newFontSize = 17; newNotSoBigFontSize = 16.9; }
                if(newSize=='largest') { newFontSize = 18.5; newNotSoBigFontSize = 16.9; }
                break;
            case 'largeFont': 
                /* do stuff */
                if(newSize=='reg') { newFontSize = 16; newNotSoBigFontSize = 16; }
                if(newSize=='largest') { newFontSize = 18.5; newNotSoBigFontSize = 16.9; }
                break;
            case 'largestFont': 
                /* do stuff */
                if(newSize=='large') { newFontSize = 17; newNotSoBigFontSize = 16.9; }
                if(newSize=='reg') { newFontSize = 16; newNotSoBigFontSize = 16; }
                break;
        }

        //alert(currentFontSizeNum + " to " + newFontSize);

        $("html").css("font-size", newFontSize+"px");
        $(".noresize").css("font-size", newNotSoBigFontSize+"px");
        $.cookie($cookie_name, newSize, {expires: 365, path: '/'});
        
        $("#regFont").removeClass("selected");
        $("#largestFont").removeClass("selected");
        $("#largeFont").removeClass("selected");
        $("#"+newSize+"Font").addClass("selected");
    }

});
