

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString());
    return c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
    
    
    // Set cookie
    entryURL = getCookie('entryURL');
    if(entryURL == null || entryURL == "")
    {
        setCookie("entryURL",document.location.href,1);
    }
    else
    {
        // Do nothing, since the cookie already exists.
    }

$(document).ready(function() {
    $('body').css('font-size', '10px'); // CAXY: Required for IE

    // $("a.lightbox").lightBox(); // Causing a delay in IE -- moving to the page itself for now BLEGH!

    // Initialize the suckerfish menu system.
    $("ul.nav").superfish({
        animation: { height: "show" },
        speed: 'slow',
        delay: 1000
    });

    // Add the 'cycle' to the top images
    $('#CyclingHeader').cycle('fade');

    // Add the 'cycle' to the press release page
    /*var cycleList = $('#CycleList');
    $('#CycleNagation-Total').html(cycleList.children('div').size());
    $('#CycleNavigation-Current').html('1');
    cycleList.cycle({
        fx: 'scrollUp',
        speed: 'fast',
        timeout: 0,
        prev: '#CycleNavigation-Prev',
        next: '#CycleNavigation-Next',
        containerResize: 1,
        prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement) {
            $('#CycleNavigation-Current').html(zeroBasedSlideIndex + 1);
        }
    });*/

    // Initialize the SidebarMenu.ctoggle system
    InitSidebarMenu();

    // Set up the font scaling
    FixFontSizes();

    // Initialize the search feature
    $('#search-text').focus(function() {
        if (this.value == 'Search')
            this.value = '';
    }).blur(function() {
        if (this.value == '')
            this.value = 'Search';
    });
});

// This global variable is used for managing the sidebar menu operation
var moving = false;

function InitSidebarMenu() {
    var COOKIE_NAME = 'sidebar_menu_cookie';

    var listItems = $('#SidebarMenu li');
    var cookie = $.cookie(COOKIE_NAME);

    if (cookie === null || String(cookie).length < 1) {
        //listItems.eq(0).children('ul').show(); // show the first list item only
    }
    else
        $('#' + cookie).children('ul').show(); // show the selected cookie item
        $('#' + cookie).css('list-style-image', 'url(/Design/Images/arrow-down.png)');

    listItems.children('span').click(function() {
        var li = $(this).parent();
        var ul = li.children('ul');

        if (!ul.is(':visible') && moving == false) {
            /*var visible = li.siblings('li').children('ul:visible');
            //moving = true; // We are moving, so don't allow another hover event on the menu to close what we're opening
            visible.slideUp(450).parent().css('list-style-image', 'url(/Design/Images/arrow-up.png)');
            */
            var currentID = li.get(0).id;

            if (String(currentID).length > 0) {
                $.cookie(COOKIE_NAME, currentID);
            }
            /*ul.slideDown(450).parent().css('list-style-image', 'url(/Design/Images/arrow-down.png)');

            //setTimeout("moving = false", 900); // The sliding effect should be done now, so go ahead and allow another selection
            return false;*/
        }
    });
}

function FixFontSizes() {
    // Initialize the grow and reduce functions for the text
    // http://www.shopdev.co.uk/blog/text-resizing-with-jquery/
    // Reset Font Size
    var originalFontSize = $('body').css('font-size');
    $("#text-reset").click(function() {
        $('body').css('font-size', originalFontSize);
    });

    // Increase Font Size
    $("#text-larger").click(function() {
        var currentFontSize = $('body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum * 1.2;
        $('body').css('font-size', newFontSize);
        return false;
    });
    // Decrease Font Size
    $("#text-smaller").click(function() {
        var currentFontSize = $('body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum * 0.8;
        $('body').css('font-size', newFontSize);
        return false;
    });
}