﻿var slideshowInterval;
var gradeSlideshowInterval;
$(document).ready(function () {
    //if ($("#topContainer").outerHeight() < $(window).height())
    // $("#topContainer").height($(window).height() - 10);
    setTimeout(function () { positionPageElements(); }, 100);
    switchTestimonials();
    setInterval(function () { switchTestimonials(); }, 12000);
    goToSlide(0);
    slideshowInterval = setInterval(function () { goToSlide(-1); }, 6000);
    goToGradeSlide(0);
    goToITGradeSlide(1);
    $(window).resize(function () { positionPageElements(); });
    reportResolution();
});


function positionPageElements(){
    var slideContainerPosition = $("#slideContainer").position();
    $("div.slide").css("top", (slideContainerPosition.top + 3) + "px");
    $("div.slide").css("left", (slideContainerPosition.left + 3) + "px");


    var gradeSlideContainerPosition = $("#gradeSlideContainer").position();
    $("table.gradeSlide").css("top", (gradeSlideContainerPosition.top) + "px");
    $("table.gradeSlide").css("left", (gradeSlideContainerPosition.left) + "px");

    var itGradeSlideContainerPosition = $("#itGradeSlideContainer").position();
    if (itGradeSlideContainerPosition != null) {
        //$("div.itGradeSlideScrollContainer").css("top", (itGradeSlideContainerPosition.top) + "px");
        //$("div.itGradeSlideScrollContainer").css("left", (itGradeSlideContainerPosition.left) + "px");
    }
}

var currentSlideIndex = 0;
var numSlides = 8;
function goToSlide(slideIndex) {
    $("#slide" + currentSlideIndex).fadeOut(1000);
    $("#slide" + currentSlideIndex + "ButtonContainer").removeClass("selectedPageLink");
    if (slideIndex >= 0) {
        currentSlideIndex = slideIndex;
        clearInterval(slideshowInterval);
    } else {
        currentSlideIndex = (currentSlideIndex + 1) % numSlides;
    }
    $("#slide" + currentSlideIndex).fadeIn(1000);
    $("#slide" + currentSlideIndex + "ButtonContainer").addClass("selectedPageLink");
}

var currentGradeSlideIndex = 0;
var numGradeSlides = 6;
function goToGradeSlide(gradeSlideIndex) {
    $("#gradeSlide" + currentGradeSlideIndex).fadeOut(1000);
    $("#gradeSlide" + currentGradeSlideIndex + "Button").removeClass("selectedGradeSlideButton");
    if (gradeSlideIndex >= 0) {
        currentGradeSlideIndex = gradeSlideIndex;
        clearInterval(gradeSlideshowInterval);
    } else {
        currentGradeSlideIndex = (currentGradeSlideIndex + 1) % numGradeSlides;
    }
    $("#gradeSlide" + currentGradeSlideIndex).fadeIn(1000);
    $("#gradeSlide" + currentGradeSlideIndex + "Button").addClass("selectedGradeSlideButton");
}

var currentITGradeSlideIndex = 0;
var numITGradeSlides = 5;
function goToITGradeSlide(itGradeSlideIndex) {
    $("#itGradeSlide" + currentITGradeSlideIndex).fadeOut(1000);
    $("#itGradeSlide" + currentITGradeSlideIndex + "Button").removeClass("selectedITGradeSlideButton");
    if (itGradeSlideIndex >= 0) {
        currentITGradeSlideIndex = itGradeSlideIndex;
        clearInterval(gradeSlideshowInterval);
    } else {
        currentITGradeSlideIndex = (currentITGradeSlideIndex + 1) % numITGradeSlides;
    }
    $("#itGradeSlide" + currentITGradeSlideIndex).fadeIn(1000);
    $("#itGradeSlide" + currentITGradeSlideIndex + "Button").addClass("selectedITGradeSlideButton");
}


var currentTestimonialIndex = 0;
var numTestimonials = 6;
function switchTestimonials() {
    $("#testimonialContainer" + currentTestimonialIndex).fadeOut(1000, function () {
        currentTestimonialIndex = (currentTestimonialIndex + 1) % numTestimonials;
        $("#testimonialContainer" + currentTestimonialIndex).fadeIn(1000);
    });
}

function reportResolution() {
    try {
        $.ajax({
            type: "POST",
            url: "/SplashPage/SplashPage.aspx/ReportScreenResolution",
            data: JSON.stringify({ 'logID': logID, 'width': screen.width, 'height': screen.height }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                // Do something interesting here.
            }
        });
    } catch (ex) { }
}
