﻿// Font EnLarger / Shrinker

//
// Config Variables
//
var baseSize = 12;
var maxSize = 14;
var minSize = 12;

//
// Call on Page Load
// window.onload = function()     (removed to make function toggleFont() work)
function toggleFont()
{ 
    var cookieSize = readCookie("fontSize");
    
    var newFontSize = (cookieSize != null)? cookieSize : baseSize ; 
    
    $("body").style.fontSize = newFontSize + "px";
    $("ISI").style.fontSize = newFontSize + "px";
    
    var onPage = false;
    
    if ($("caption") != null) { onPage = true; $("caption").style.fontSize = newFontSize + "px";}
    
    var displayHTML = "Adjust text size: <a id=\"small\" onclick=\"shrink(); return false;\" href=\"#\"><img src=\"\/images/minus.gif\" alt=\"-\" /></a>";
    displayHTML += "<a id=\"large\" onclick=\"grow(); return false;\" href=\"#\"><img src=\"\/images/plus.gif\" alt=\"+\" /></a>";
    
    Element.hide("fontChange");
    Element.update("fontChange",displayHTML);
    checkFontSize(newFontSize);
    new Effect.Appear("fontChange");
}
            
function grow()
{
    var fontSize = $("body").style.fontSize.replace(/px/,"");
    fontSize++;
    if( checkFontSize(fontSize) ) 
    {
        $("body").style.fontSize = fontSize + "px";
        $("ISI").style.fontSize = fontSize + "px";
    }
}
function shrink()
{
    var fontSize = $("body").style.fontSize.replace(/px/,"");
    fontSize--;
    if( checkFontSize(fontSize) ){
         $("body").style.fontSize = fontSize + "px";
         $("ISI").style.fontSize = fontSize + "px";
    }
}
function normal()
{
    if( checkFontSize(baseSize) ){
         $("body").style.fontSize = baseSize + "px";
         $("ISI").style.fontSize = baseSize + "px";
    }
}
            
function checkFontSize(fontSize)
{

    var returnVal = true;

    if( fontSize > maxSize )
    {
        Element.hide("large");
        returnVal = false;
    }
    else if( fontSize == maxSize )
    {
        Element.hide("large");
        returnVal = true;
    }
    else
        Element.show("large");
            
    if( fontSize < minSize )
    {
        Element.hide("small");
        returnVal = false;
    }
    else if( fontSize == minSize )
    {
        Element.hide("small");
        returnVal = true;
    }
    else
        Element.show("small");
                
    if( returnVal )
        createCookie("fontSize",fontSize,10);
    
    return returnVal;
}
            
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 nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
	    var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
		            
		if (c.indexOf(nameEQ) == 0) 
		    return c.substring(nameEQ.length,c.length);
    }
    return null;
}