
var spotlightElement = null;
var spotlightColors = new Array ("#FFFFFF", "#FCFCFC", "#F5F5F5", "#ECECEC", "#E5E5E5", "#DCDCDC");
var overLessonLink = false;
var overLessonMenu = false;
var rating = 5;
var highlightsVisible = false;
var newsVisible = false;


function getX (element) {
    var x = 0;
    while (element) {
        x += element.offsetLeft;
        element = element.offsetParent;
    }
    return x;
}


function getY (element) {
    var y = 0;
    while (element) {
        y += element.offsetTop;
        element = element.offsetParent;
    }
    return y;
}


function OnLessonLinkOver () {
    overLessonLink = true;
    setTimeout (ShowHideLessonMenu, 50);
}


function OnLessonLinkOut () {
    overLessonLink = false;
    setTimeout (ShowHideLessonMenu, 50);
}


function OnLessonMenuOver () {
    overLessonMenu = true;
    setTimeout (ShowHideLessonMenu, 50);
}


function OnLessonMenuOut () {
    overLessonMenu = false;
    setTimeout (ShowHideLessonMenu, 50);
}


function ToggleHighlights () {
    var highlightsDiv = document.getElementById ("highlights");
    if (highlightsVisible) {
        highlightsVisible = false;
        highlightsDiv.setAttribute ("style", "display: none;");
    }
    else {
        highlightsVisible = true;
        highlightsDiv.setAttribute ("style", "display: block;");
    }
}


function ToggleNews () {
    var newsDiv = document.getElementById ("news");
    if (newsVisible) {
        newsVisible = false;
        newsDiv.setAttribute ("style", "display: none;");
    }
    else {
        newsVisible = true;
        newsDiv.setAttribute ("style", "display: block;");
    }
}

 
function ShowHideLessonMenu () {
    if (overLessonLink || overLessonMenu) {
        var lessonLink = document.getElementById ("lessonLink");
        var lessonMenu = document.getElementById ("lessonMenu");
        var menuLeft = getX (lessonLink);
        var menuTop = getY (lessonLink) + lessonLink.offsetHeight - 2;
        lessonMenu.setAttribute ("style", "display: inline; position: absolute; left: " + menuLeft + "; top: " + menuTop + ";");
        // We have to hide the applet because it gets z-order precedence over the menu
        var introApplet = document.getElementById ("introApplet");
        var introAppletReplacement = document.getElementById ("introAppletReplacement");
        if (introApplet != null && introAppletReplacement != null) {
            introApplet.setAttribute ("style", "display: none;");
            introAppletReplacement.setAttribute ("style", "display: block;");
        }
    }
    else {
        var lessonMenu = document.getElementById ("lessonMenu");
        lessonMenu.setAttribute ("style", "display: none;");
        var introApplet = document.getElementById ("introApplet");
        var introAppletReplacement = document.getElementById ("introAppletReplacement");
        if (introApplet != null && introAppletReplacement != null) {
            introApplet.setAttribute ("style", "display: inline;");
            introAppletReplacement.setAttribute ("style", "display: none;");
        }
    }
}


function SpotlightTurnOn (colorIndex) {
    if (colorIndex > 0) {
        colorIndex--;
        spotlightElement.setAttribute ("style", "background-color: " + spotlightColors [colorIndex] + ";");
        setTimeout ('SpotlightTurnOn (' + colorIndex + ')', 100);
    }
}


function SpotlightOn (element) {
/*
    spotlightElement = element;
    SpotlightTurnOn (spotlightColors.length);
*/
}


function SpotlightTurnOff (colorIndex) {
    if (colorIndex < spotlightColors.length) {
        colorIndex++;
        spotlightElement.setAttribute ("style", "background-color: " + spotlightColors [colorIndex] + ";");
        setTimeout ('SpotlightTurnOff (' + colorIndex + ')', 100);
    }
}


function SpotlightOff (element) {
/*
    spotlightElement = element;
    SpotlightTurnOff (0);
*/
}


function ChangeRating (control, eventInfo) {
    // The first star will always be filled so no need to change it
    var star2 = document.getElementById ("rating2");
    var star3 = document.getElementById ("rating3");
    var star4 = document.getElementById ("rating4");
    var star5 = document.getElementById ("rating5");
    if (control.id == "rating1") {
        rating = 1;
        star2.src = "../image/starEmpty.png";
        star3.src = "../image/starEmpty.png";
        star4.src = "../image/starEmpty.png";
        star5.src = "../image/starEmpty.png";
    }
    else if (control.id == "rating2") {
        rating = 2;
        star2.src = "../image/starFilled.png";
        star3.src = "../image/starEmpty.png";
        star4.src = "../image/starEmpty.png";
        star5.src = "../image/starEmpty.png";
    }
    else if (control.id == "rating3") {
        rating = 3;
        star2.src = "../image/starFilled.png";
        star3.src = "../image/starFilled.png";
        star4.src = "../image/starEmpty.png";
        star5.src = "../image/starEmpty.png";
    }
    else if (control.id == "rating4") {
        rating = 4;
        star2.src = "../image/starFilled.png";
        star3.src = "../image/starFilled.png";
        star4.src = "../image/starFilled.png";
        star5.src = "../image/starEmpty.png";
    }
    else if (control.id == "rating5") {
        rating = 5;
        star2.src = "../image/starFilled.png";
        star3.src = "../image/starFilled.png";
        star4.src = "../image/starFilled.png";
        star5.src = "../image/starFilled.png";
    }
}
