var topNewsId = 1;
var plattegrondvlag_clicked = false;

$(function(){

    // activate FancyBox
    $(".fancyimage").fancybox({
        'overlayShow': true 
    });

    // scrolls the news items on newsindex
    $("#newsUp").click(function(){
        if (topNewsId > 1) {
            $("#" + (topNewsId - 1)).css('display', 'block');
            $("#" + (topNewsId + 4)).css('display', 'none');
            topNewsId--;
        }
    });
    $("#newsDown").click(function(){
        if (amountOfNieuwsItems && topNewsId + 5 <= amountOfNieuwsItems) {
            $("#" + topNewsId).css('display', 'none');
            $("#" + (topNewsId + 5)).css('display', 'block');
            topNewsId++;
        }
    });
   
    // scrolls the nieuwswijzer items on newsindex
    $("#left").click(function(){
        if (topNewsId > 1) {
            $("#" + (topNewsId - 1)).css('display', 'block');
            $("#" + (topNewsId)).css('display', 'none');
            topNewsId--;
        }
    });
    $("#right").click(function(){
        if (amountOfNieuwsItems && topNewsId + 1 <= amountOfNieuwsItems) {
            $("#" + topNewsId).css('display', 'none');
            $("#" + (topNewsId + 1)).css('display', 'block');
            topNewsId++;
        }
    });

    // menu rollovers (changes txt color)
    $("#menu a").hover(
        function(){
            split = $(this).attr("class").split("selected");
            if (split == "") {
                $(this).addClass("hover");
            }
        }, 
        function(){
            if (split == "") {
                $(this).removeClass("hover");
            }
        }
    );

    
    // plattegrond rollovers (changes txt color)
    $("#plattegrond a").click(function(){
        plattegrondvlag_clicked = true;
        switcher($(this));
    });

    $("#plattegrond a").mouseover(function(){
        if (plattegrondvlag_clicked == true) {
            return;
        }
        switcher($(this));
    });
});
function switcher(elem){
    // hide all the other flags and empty the text box
    $("#content div.description").css("display", "none");
    $("#plattegrond a").css("background-image",  "none");

    // display all flags from the current school together with its text box
    $("[rel=" + selectedSchool + "]").css("background-image", "none");
    $("#" + selectedSchool).css("display", "none");
    elem.css("background-image", "url(/img/scholen/plattegronden/" + elem.attr("id") + ".png)");
    var id = elem.attr("id");
    $("#" + id + "2").css("background-image", "url(/img/scholen/plattegronden/" + id + "2.png)");
    $("#" + id.substr(0, id.length - 1)).css("background-image", "url(/img/scholen/plattegronden/" + id.substr(0, id.length - 1) + ".png)");
    $("#" + elem.attr("rel")).css("display", "block");
    
}

function popup(url, width, height)
{
    width  = width  != undefined ? width  : 1020;
    height = height != undefined ? height : 510;
    mywindow = window.open(url, 'Schoolwijzer', 'width=' + width + ',height=' + height + ',scrollbars=no,toolbar=no,location=no');
    mywindow.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
    return false;
}

function popupVideo()
{
    mywindow = window.open('/algemeen/filmpje', 'Stichtingwijzer', 'width=340,height=260,scrollbars=no,toolbar=no,location=no');
    mywindow.moveTo((screen.width - 340) / 2, (screen.height - 260) / 2);
    return false;    
}