﻿var timeout;
var currentPhoto = 0;
var currentItem = 0;
var photos;
var menuItems;
var menuQuotes;

function onBlur() {
    clearTimeout(timeout);
    timeout = null;
};

function onFocusIn() {
    timeout = setTimeout(nextSlide, 6000);
}

function CheckFocus() {
    var info = document.getElementById("info");
    if (document.hasFocus() && timeout == null) {
        onFocusIn()
    }
    else {
        if (timeout == null) {
            onBlur();
        }
    }
}

$(function () {
    var i = 0;

    photos = $("#jQ-Divs").children();
    menuItems = $("#menu-Slider").children();
    menuQuotes = $(".menuSlider_quote");

    //setInterval(CheckFocus, 500);

    $(window).focus(function () {
        CheckFocus();
    });

    i = 0;
    $("#menu-Slider").children().each(function () {
        $(this).attr("style", "");

        if (i == 0) {
            $(this).attr("class", "menuSlider_text current");
        } else {
            $(this).attr("class", "menuSlider_text");
        }
        i++;
    });

    $("jQ-Divs").children().each(function () {
        $(this).attr("style", "display:none;");
    });

    timeout = setTimeout(slide, 1000);
});

function slide() {
    clearTimeout(timeout);
    ("#" + menuItems[currentItem].id)
    $(".menuSlider_text.current").fadeIn(1500);
    $("#" + menuQuotes[0].id).fadeIn(1500);
    currentPhoto = 0;
    $("#" + photos[0].id).fadeIn(1500);

    currentItem = 0;

    $("#" + menuItems[currentItem].id + " div.menuPijl").attr("class", "menuPijl");
    $("#" + menuItems[currentItem].id + " div.menuPijl").show();

    timeout = setTimeout(nextSlide, 6000);
}

function nextSlide() {
    $("#" + photos[currentPhoto].id).hide();

    currentPhoto++;
    if (currentPhoto >= photos.length) {
        currentPhoto = 0;
    }
    $("#" + photos[currentPhoto].id).fadeIn(1500, function () {
        setTimeout(nextSlide, 6000);
    });

    //niet selecteren
    $("#" + menuItems[currentItem].id).attr("class", "menuSlider_text");
    $("#" + menuItems[currentItem].id).animate({ backgroundColor: "#FFFFFF" }, 1500);
    $("#" + menuItems[currentItem].id + " div.menuPijl").attr("class", "menuPijl onzichtbaar");
    $("#" + menuItems[currentItem].id + " div.menuPijl").hide();

    $("#" + menuQuotes[currentItem].id).fadeOut(1500);
    hideQuotes();

    currentItem++;
    if (currentItem >= menuItems.length) {
        currentItem = 0;
    }

    //selecteren
    $("#" + menuItems[currentItem].id).attr("class", "menuSlider_text current");
    $("#" + menuItems[currentItem].id).animate({ backgroundColor: "#008D7F" }, 1500);
    $("#" + menuItems[currentItem].id + " div.menuPijl").attr("class", "menuPijl");
    $("#" + menuItems[currentItem].id + " div.menuPijl").show();

    
    if ($("#" + menuQuotes[currentItem].id).html().trim() != "") {
        $("#" + menuQuotes[currentItem].id).fadeIn(1500);
        showQuotes();
    }

}

function showQuotes() {
    $("div#quoteLinks").fadeIn('1500');
    $("div#quoteRechts").fadeIn('1500');
}

function hideQuotes() {
    $("div#quoteLinks").fadeOut('slow');
    $("div#quoteRechts").fadeOut('slow');
}
