﻿var sli, lli, mt, st, rt;
$(document).ready(function() {
    var adjustheight = 268;
    $("#adjust").toggle(function() {
        $('#truncate').css('height', 'auto').css('overflow', 'visible');
        $(this).text("[Read Less]");
    }, function() {
        $('#truncate').css('height', adjustheight).css('overflow', 'hidden');
        $(this).text("[Read More]");
    });


    $("#nav > li").hover(
        function() {
            clearTimeout(st);
            sli = this;
            mt = setTimeout("showMenu()", 250);
        },
        function() {
            clearTimeout(mt);
            if (this.id !== lli) {
                st = setTimeout("showSectionMenu()", 250);
            }
        }
    );
    lli = $("#nav > li.active").attr("id");

    if ($("#rotator").length) {
        var i = 0;
        $("#rotator img").each(function() {
            $(this).attr("id", "rot" + i).css("position", "absolute");
            if (i > 0) {
                $(this).css("display", "none");
            }
            i += 1;
        });
        if (i > 1) {
            rt = setTimeout("rotateSlides(0, " + i + ")", 5000);
        }
    }

});

function rotateSlides(currentslide, slidecount) {
    var newslide = currentslide + 1;
    if (newslide === slidecount) {
        newslide = 0;
    }
    $("#rot" + currentslide).fadeOut("slow");
    $("#rot" + newslide).fadeIn("slow");
    rt = setTimeout("rotateSlides(" + newslide + " ," + slidecount + ")", 5000);
}

function showMenu() {
    $("#nav > li ul").hide();
    $(sli).children("ul").show();
}

function showSectionMenu() {
    $("#nav > li ul").hide();
    $("#nav > li#" + lli + " ul").show(); 
}

