﻿
function initMenu() {

    level0config = {
        sensitivity: 3,
        interval: 100,
        timeout: 100,
        over: function() {
            $(this).children('ul.level1').slideDown('fast'); 
        },
        out : function() {
            $(this).children('ul.level1').slideUp('fast');
        }
    }

    $('.MainMenu ul.level0').children('li').hoverIntent(level0config);

    level1config = {
        sensitivity: 2,
        interval: 90,
        timeout: 90,
        over: function() {

            
            $(this).children('ul.level2').animate({ width: 187 }, 'fast', function() {
                $(this).show();
            });

        },
        out: function() {
        $(this).children('ul.level2').animate({ width: 0 }, 'fast', function() {
            $(this).hide();
        });
            

        }
    }

    $('.MainMenu ul.level1').children('li').hoverIntent(level1config);

    leftNavconfig = {
        sensitivity: 3,
        interval: 100,
        timeout: 100,
        over: function() {


            $(this).children('ul.level1').animate({ width: 187 }, 'fast', function() {
                $(this).show();
            });

        },
        out: function() {
            $(this).children('ul.level1').animate({ width: 0 }, 'fast', function() {
                $(this).hide();
            });
        }
    }

    $('.LeftNav ul.level0').children('li').hoverIntent(leftNavconfig);

    // balance navs
    var leftNavHeight = $('.LeftNav .Wrapper').height();
    var rightColumnHeight = $('.RightColumn').height() + 25;
    if (leftNavHeight < rightColumnHeight) {
        $('.LeftNav .Wrapper').css('height', rightColumnHeight + 'px');
    }
}

var rotator_selectedIndex;

function rotator_swapNthChild(n) {
    var visibleItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:visible');
    var nextItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:nth-child(' + n + ')');
    $('.ImageAutoRotator .RotateWrapper').fadeOut("slow", function() {
        $('.RotatePager ul li a').removeClass('selected');
        $('.RotatePager ul li:nth-child(' + (n) + ') a').addClass('selected');
        $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem').hide();
        $(nextItem).show();
        $('.ImageAutoRotator .RotateWrapper').fadeIn("slow");

        rotator_selectedIndex = n;
    });

}



function imageAutoRotator_Rotate(timeout) {
    if (rotator_selectedIndex == null) {
        rotator_selectedIndex = 1;
    }

    var visibleItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:visible');
    var nextItem;

    if ($(visibleItem).next().size() > 0) {
        nextItem = $(visibleItem).next();
        rotator_selectedIndex = rotator_selectedIndex + 1;
    } else {
        nextItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:first');
        rotator_selectedIndex = 1;
    }
    $('.ImageAutoRotator .RotateWrapper').fadeOut("slow", function() {

        // set pager (only if visible)
        $('.RotatePager ul li a').removeClass('selected');
        $('.RotatePager ul li:nth-child(' + (rotator_selectedIndex) + ') a').addClass('selected');
        //

        $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem').hide();
        $(nextItem).show();
        $('.ImageAutoRotator .RotateWrapper').fadeIn("slow");
        setTimeout('imageAutoRotator_Rotate(' + timeout + ');', timeout);
    });

}

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()) + ';path=/';
}

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 "";
}


var _font9 = 'h4';
var _font10 = '.caption';
var _font11 = '.moreLink, .MoreLink, a.moreLink';
var _font12 = '.smallText';
var _font14 = 'h1, h2, h3, p, .ContactUs .Form label, .MediaRequest .Form label, ul li';
var _font21 = '.largeText, .LargeText';
var _zones = '.HomeTemplate .LeftColumn, .HomeTemplate .RightColumn, .TwoColumnTemplate .RightColumn';

var _lh18 = 'p';
var _lh25 = '.largeText, .LargeText';

function setFontSize(fontModifier) {
    var nine = 9 + fontModifier;
    var ten = 10 + fontModifier;
    var eleven = 11 + fontModifier;
    var twelve = 12 + fontModifier;
    var fourteen = 14 + fontModifier;
    var eighteen = 18 + fontModifier;
    var twentyone = 21 + fontModifier;
    var twentyfive = 25 + fontModifier;
    $(_zones).find(_font14).css('font-size', fourteen + 'px');
    $(_zones).find(_font9).css('font-size', nine + 'px');
    $(_zones).find(_font10).css('font-size', ten + 'px');
    $(_zones).find(_font11).css('font-size', eleven + 'px');
    $(_zones).find(_font12).css('font-size', twelve + 'px');
    $(_zones).find(_font21).css('font-size', twentyone + 'px');
    $(_zones).find(_lh18).css('line-height', eighteen + 'px');
    $(_zones).find(_lh25).css('line-height', twentyfive + 'px');
    setCookie('FontModifier', fontModifier, 1);
}

var fontModifier = 0;

function init() {
    fontModifier = getCookie('FontModifier');
    if (fontModifier == undefined || fontModifier == null || fontModifier == '') {
        fontModifier = 0;
    }
    setFontSize(fontModifier * 1);

}

function showWatermark(ctrl) {
    if (ctrl.value == '') {
        ctrl.value = 'Search';
    }
}

function hideWatermark(ctrl) {
    
    if (ctrl.value == 'Search') {
        ctrl.value = '';
    }
}
