$(document).ready(function() {
    $("#contactForm").validate({
        rules: {
            Email: {
                required: true,
                email: true
            },
            Naam: "required",
            Onderwerp: "required",
            Opmerking: "required"
        },
        errorClass: "invalid"
    });


    $("#contactForm").find("#submitButton").click(function() {
        if ($("#contactForm").valid()) {
            var randomnumber = Math.floor(Math.random() * 100001);
            var send = $.post("/Ajax/saveContactForm.aspx?randomnumber=" + randomnumber,
                    {
                        naam: $("#fldVoornaam").val(),
                        email: $("#fldEmail").val(),
                        onderwerp: $("#fldOnderwerp").val(),
                        bericht: $("#fldBericht").val()
                    },
                    function(data) {
                        document.location = document.location + "/bedankt";
                    }
                );
            return false;
        }
        else {
            $("em.verplichtMelding").text("Niet alle verplichte velden zijn ingevuld");
            $("em.verplichtMelding").css("color", "#CD0069");
        }
        return false;
    });

    $('#topvacaturesRechts').cycle({
        fx: 'scrollDown',
        easing: 'easeInQuint',
        timeout: 3000,
        next: '#middelScrollUp',
        prev: '#middelScrollDown',
        nowrap: 0,
        after: onAfter
    });

    $("#btnZoeken").click(function() {
        var vakgebied = "";
        var opleiding = "";
        var regio = "";
        var divisie = "";

        if ($("#inpVakgebied").val() != null) { vakgebied = $("#inpVakgebied").val(); }
        if ($("#inpOpleiding").val() != null) { opleiding = $("#inpOpleiding").val(); }
        if ($("#inpRegio").val() != null) { regio = $("#inpRegio").val(); }
        if ($("#inpDivisie").val() != null) { divisie = $("#inpDivisie").val(); }
        divisie = divisie.replace(' & ', ' en ');

        $("#frmVacatureZoeken").attr("action", "/" + $("#doelgroepHome").val() + "/vacatures?Vakgebied=" + vakgebied + "&Opleiding=" + opleiding + "&Regio=" + regio + "&Divisie=" + divisie + "&Trefwoord=" + $("#inpTrefwoord").val());
    });


    $("#btnZoekenFooter").click(function() {
        sendFooterForm();
    });

//    $("#vacatureFormFooter").submit(function() {
//        sendFooterForm();
//    });

    function sendFooterForm() {
        var vakgebied = "";
        var opleiding = "";
        var regio = "";
        var trefwoord = "";
        var doelgroep = "";

        if ($("#doelgroepHomeFooter").val() != null) { doelgroep = $("#doelgroepHomeFooter").val(); }

        if (doelgroep != "vmbo_techniek" && doelgroep != "hbo_techniek" && doelgroep != "hbo_it" && doelgroep != "overige_vakgebieden") {
            doelgroep = "overige_vakgebieden";
        }

        if ($("#inpVakgebiedFooter").val() != null) { vakgebied = $("#inpVakgebiedFooter").val(); }
        if ($("#inpRegioFooter").val() != null) { regio = $("#inpRegioFooter").val(); }
        if ($("#inpTrefwoordFooter").val() != null && $("#inpTrefwoordFooter").val() != "Trefwoord of vacaturenummer") { trefwoord = $("#inpTrefwoordFooter").val(); }

        $("#vacatureFormFooter").attr("action", "/" + doelgroep + "/vacatures?Vakgebied=" + vakgebied + "&Opleiding=" + opleiding + "&Regio=" + regio + "&Divisie=&Trefwoord=" + trefwoord).submit();
    }

    //uitklappen vacatureformulier
    $("a#btnShowForm").click(function() {
        if ($(this).hasClass("open")) {
            $(this).removeClass("open").addClass("closed");
            $("div#cntVacatureForm").find("form").fadeOut(500);
            $(this).oneTime(500, function() {
                $("div#cntVacatureForm").animate({ height: 0 }, 500);
            });
            $(this).removeClass("btnVorige").addClass("btnVolgende").text("Toon zoekopties")
        }
        else if ($(this).hasClass("closed")) {
            $(this).removeClass("closed").addClass("open");
            $("div#cntVacatureForm").animate({ height: 310 }, 500);
            $(this).oneTime(500, function() {
                $("div#cntVacatureForm").find("form").fadeIn(500);
            });
            $(this).removeClass("btnVolgende").addClass("btnVorige").text("Verberg zoekopties")
        }
        return false;
    });

    //load paginator
    var curPage = "page_1";
    var curPageNr = 1;
    $("table#tblVacatures").find("tr").hide();
    $("table#tblVacatures").find("tr.header").show();
    $("table#tblVacatures").find("tr.page_1").show();
    $("#" + curPage).show();
    updatePaginator(curPageNr);

    //check of gebruiker via 'uitgebreid zoeken' is gekomen
    var url = document.location;
    var strippedUrl = url.toString().split("#");
    if (strippedUrl.length > 1) {
        if (strippedUrl[1] == "uitgebreid") {
            $("a#btnShowForm").click();
        }

    }

    $("#btnZoekenUitgebreidFooter").click(function() {
        $("a#btnShowForm").click();
    });

    $("#flashBanner").flash({
        src: "/incl/swf/werkenbij.swf",
        width: 427,
        height: 49,
        flashvars: { xmlurl: "/ajax/createBannerXML.aspx" },
	wmode: "transparent"
    });

    $("#movie").flash({
        src: "/incl/swf/homepage_animatie.swf",
        width: 350,
        height: 320,
        wmode: 'transparent',
        flashvars: { videoUrl: "/incl/swf/slim_werken_small.flv" },
	wmode: "transparent"
    });
    
    /*

    $("#bnrVMBOTechniek").flash({
        src: "/incl/swf/banner_vmbo_techniek.swf",
        width: 489,
        height: 290,
        flashvars: { link1: "/vmbo_techniek/de_mensen_van_enexis", link2: "/slimme_feiten" },
	wmode: "transparent"
    });

    $("#bnrHBOTechniek").flash({
        src: "/incl/swf/banner_hbo_techniek.swf",
        width: 489,
        height: 290,
        flashvars: { link1: "/hbo_techniek/de_mensen_van_enexis", link2: "/slimme_feiten" },
	wmode: "transparent"
    });

    $("#bnrHBOIT").flash({
        src: "/incl/swf/banner_hbo_it.swf",
        width: 489,
        height: 290,
        flashvars: { link1: "/hbo_it/de_mensen_van_enexis", link2: "/slimme_feiten" },
	wmode: "transparent"
    });
    
    */

    $("#bnrOverigeVakgebieden").flash({
        src: "/incl/swf/banner_overige_vakgebieden.swf",
        width: 489,
        height: 290,
        flashvars: { link1: "/overige_vakgebieden/de_mensen_van_enexis", link2: "/slimme_feiten" },
	wmode: "transparent"
    });

    $("#ingangFlashVMBOTechniek").flash({
        src: "/incl/swf/home_vmbo_techniek.swf",
        width: 113,
        height: 96,
        flashvars: { urlVar: "/vmbo_techniek" },
	wmode: "transparent"
    });

    $("#ingangFlashHBOTechniek").flash({
        src: "/incl/swf/home_hbo_techniek.swf",
        width: 113,
        height: 96,
        flashvars: { urlVar: "/hbo_techniek" },
	wmode: "transparent"
    });

    $("#ingangFlashHBOIT").flash({
        src: "/incl/swf/home_hbo_it.swf",
        width: 113,
        height: 96,
        flashvars: { urlVar: "/hbo_it" },
	wmode: "transparent"
    });

    $("#ingangFlashOverigeVakgebieden").flash({
        src: "/incl/swf/home_overige_vakgebieden.swf",
        width: 113,
        height: 96,
        flashvars: { urlVar: "/overige_vakgebieden" },
	wmode: "transparent"
    });

});

function onAfter(curr, next, opts) {
	var index = $(this).parent().children().index(this);
	$('#middelScrollDown')[index == 0 ? 'hide' : 'show']();
	$('#middelScrollUp')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}

function openWindow(url, name) {
    var width = 950;
    var height = 625;

    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;

    var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=yes";
    sOptions += ",width=" + width;
    sOptions += ",height=" + height;
    sOptions += ",left=" + left;
    sOptions += ",top=" + top;

    window.open(url, name, sOptions);
}

