﻿function initialisatie() {
    $("div#centreer").delay(600).fadeIn(1200);
    $("div#koptekst img").mouseup(function (data) {
        document.location = data.shiftKey ? "/beheer" : "/"; 
    });
    $("div#calameoviewer").dialog({ autoOpen: false, modal: true,
        /* Scrollbar fix */
        open: function (event, ui) {
            $('body').css('overflow', 'hidden'); 
            $('.ui-widget-overlay').css('width', '100%'); },
        close: function (event, ui) {
            $('body').css('overflow', 'auto');
        },
        position: 'top',
        width: '935px',
        resizable: false,
        closeOnEscape: true,
        show: "fold",
        hide: "clip"
    });
}

function homeInitialisatie() {
    $("div.matrixcel div.illustratie img").fadeTo("fast", 1).delay(1200).fadeTo("fast", 0.1);
    $("div.matrixcel").hover(matrixcelIn, matrixcelUit).click(matrixcelnavigatie);
    $("div#menu a").click(function () {
        document.location = "/home/index/" + $(this).attr("id").substring(2);
    });
}

function categorieInitialisatie() {
    $("div#paginering div.pagina").click(function () {
        var slash = document.location.href.lastIndexOf("/");
        if (slash == -1) { return; }
        document.location = document.location.href.substring(0, slash + 1) + $(this).html();
    });

    $("div#paginering img.paginanavigatie").click(function () {
        var slash = document.location.href.lastIndexOf("/");
        if (slash == -1) { return; }
        document.location = document.location.href.substring(0, slash + 1) + $(this).attr("id").substring(1);
    });
}

function matrixcelIn() {
    $(this).find("div.illustratie img").fadeTo("fast", 1);
    $("div#paginatoelichting div.matrixtoelichting").hide();
    $("div#paginatoelichting div#" + $(this).attr("id") + ".matrixtoelichting").fadeTo("slow", 1);
}

function matrixcelUit() {
    $(this).find("div.illustratie img").fadeTo("fast", 0.1);
    $("div#paginatoelichting div#" + $(this).attr("id") + ".matrixtoelichting").clearQueue().hide();
}

function matrixcelnavigatie() {
    var prefix = $(this).attr("id").substring(0, 1);
    var id = $(this).attr("id").substring(2);
    
    if (prefix == 'c') {
        document.location = "/categorie/index/" + id + "/1";
    }
    else if (prefix == 'p') {
        // formaat is p_id_pagina
        var underscore = id.lastIndexOf("_");
        document.location = "/publicatie/index/" + id.substring(0, underscore) +
            "/" + id.substring(underscore + 1);
    }
}

function publicatieInitialisatie() {
    setTimeout(function () {
        $("div#vorigepublicatie").unbind();
        $("div#volgendepublicatie").unbind();
        $("div.bladerbalk").unbind();
        $("div#vorigepublicatie").css("top", $('div#[id^="p_"]').offset().top - 24);
        $("div#volgendepublicatie").css("top", $('div#[id^="p_"]').offset().top - 24);
        $("div.navigatiebalk").slideDown();
        $("div.bladerbalk").slideDown();

        $("div#volgendepublicatie").click(function () {
            var id = $('div#[id^="p_"]').attr("id").substring(2);
            var underscore = id.lastIndexOf("_");
            document.location = "/publicatie/volgende/" + id.substring(0, underscore) +
                "/" + id.substring(underscore + 1);
        });
        $("div#vorigepublicatie").click(function () {
            var id = $('div#[id^="p_"]').attr("id").substring(2);
            var underscore = id.lastIndexOf("_");
            document.location = "/publicatie/vorige/" + id.substring(0, underscore) +
                "/" + id.substring(underscore + 1);
        });
        $("div.bladerbalk").click(function () {
            $("div#calameoviewer").dialog({ title: $("input#publicatietitel").attr("value") }); 
            $("div#calameoviewer").dialog("open");
        });
        $("div#calameoviewer").dialog({ autoOpen: false, modal: true,
            /* Scrollbar fix */
            open: function (event, ui) { $('body').css('overflow', 'hidden'); $('.ui-widget-overlay').css('width', '100%'); },
            close: function (event, ui) {
                $('body').css('overflow', 'auto');
            },
            position: 'top',
            width: '935px',
            resizable: false,
            closeOnEscape: true,
            show: "fold",
            hide: "clip"
        });
    }, 2000);
}
