// MasterStyles.js
// Based on content taken from http://www.dnbnation.com/faq/

var masterStyles = new MasterStyles();

function MasterStyles()
{
    //Members
    var m_MinSize = 10;
    var m_MaxSize = 14;
    
    var m_DefaultFontSize = 10;
    
    var m_PrefsLoaded = false;    
    var m_CurrentFontSize = m_DefaultFontSize; 
   

    //Encapsulation - Public Member variables
    return new function()
    {     
      //Event Handlers
     
      //Called when the Page is Loaded (Accessed)
     this.Load = function()
     {       
      //Update the font size.
         if(!m_PrefsLoaded)
         {
             cookie = masterStyles.ReadCookie("fontSize");
          m_CurrentFontSize = cookie ? cookie : m_DefaultFontSize;
          masterStyles.SetFontSize(m_CurrentFontSize);
       
          m_PrefsLoaded = true;
         }
         
         masterStyles.SetTableHighlighting();
     }
     
     //Called when the Page is UnLoaded (Closed) 
     this.Unload = function()
     {
         masterStyles.CreateCookie("fontSize", m_CurrentFontSize, 365);
     }
     

     //Public Methods
     
        //Increases or decreases the font
        this.ChangeFontSize = function(sizeDifference)
        {
         m_CurrentFontSize = parseInt(m_CurrentFontSize) + parseInt(sizeDifference); 

         if(m_CurrentFontSize > m_MaxSize)
         {
          m_CurrentFontSize = m_MaxSize;
         }
         else if(m_CurrentFontSize < m_MinSize)
         {
          m_CurrentFontSize = m_MinSize; 
         }

         this.SetFontSize(m_CurrentFontSize);
        }
        
        this.Reset = function()
        {
         m_CurrentFontSize = m_DefaultFontSize;
         this.ChangeFontSize(0);
        } 
    
        this.SetFontSize = function(fontSize)
        {
            document.body.style.fontSize = fontSize + 'px';
        }
        
        this.SetTableHighlighting = function()
        { 
   var tables = document.getElementsByTagName("table");
   
   for(var t = 0; t < tables.length; t++)
   {
    var table = tables[t];
          
          if(table.id.search("rolloverTable") > -1 || table.id.search("documentsGrid") > -1  || table.id.search("projectsGrid") > -1 )
          { 
     var rows = table.rows;   
     for(var r = 0; r < rows.length; r++)
              {   
      rows[r].onmouseover = function() 
       {   
        this.className += ' hilite';   
       }   
                      
      rows[r].onmouseout = function() 
       {   
        this.className = this.className.replace('hilite', '');   
       }   
              }   
          }
         }
     }
    
        this.CreateCookie = function(name,value,days)
        {
            if (days) 
            {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
            } 
            else
            {
                expires = "";
            }
            document.cookie = name+"="+value+expires+"; path=/";
        }
        
        this.ReadCookie = function(name)
        {
            var cookie = null;
            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) cookie = c.substring(nameEQ.length ,c.length);
            }
            return cookie;
        }
    }
}