$(document).ready(function () {
    var headul = $('.nav > ul');
    var navli = headul.children('li');
    navli.each(function (index) {
        $(this).hover(
			function () {
			    var li = $(this);
			    li.css({ 'background-color': '#1a4884' });
			    li.children('a').css({ 'color': 'white' });

			    var w = li.width() + 8;
			    if (index + 1 == navli.length) {
			        //li.css({'border-right':'dotted 1px #898989'});
			        w = li.width() + 6;
			    }

			    if ($.browser.mozilla) {
			        if (index == 4) {
			            //li.css({'border-right':'dotted 1px #898989'});
			            w = li.width() + 6;
			        }
			        if (index == 2) {
			            //li.css({'border-right':'dotted 1px #898989'});
			            w = li.width() + 8;
			        }

			    }

			    li.find('ul').css({ display: 'block', width: w, opacity: 0 })
				.stop(true)
				.animate({ opacity: .95 }, 300);

			}, function () {
			    var li = $(this);
			    li.css({ 'background-color': 'white' });
			    li.children('a').css({ 'color': 'black' });

			    li.find('ul').stop(true).animate({ opacity: 0 }, 300, function () {
			        $(this).css({ display: 'none' })
			    });

			    if (index + 1 == navli.length) {
			        li.css({ 'border-right': 'none' });
			    }
			}
		);
    });

    var sidenav = $('.sidenav');
    if (sidenav.length > 0) {
        sidenav.find('a').each(function (index) {
            var l = $(this);
            l.hover(function (e) {
                l.parent().css({ 'background': '#c60c31' });
            }, function (e) {
                l.parent().css({ 'background': '#E3E3E3' });
            });

        });
    }

    var advance = $('.advance');
    var advlink = $('.advlink');
    var advwrapper = $('.advwrapper');
    advwrapper.css({ 'display': 'none' });
    var searchBtn = $('.search').children('a');

    searchBtn.mouseover(function () {
        advwrapper.css({ 'display': 'block' });
    });

    advwrapper.mouseleave(function () {
        advwrapper.css({ 'display': 'none' });
    });

    $("#searchbox").focus(function () {
        if (this.value == 'Enter search term') { this.value = ''; }
    }); 
});