﻿
var VIGET = VIGET || {};
VIGET.fileInputs = function() {
    var $this = $(this),
        $val = $this.val(),
        valArray = $val.split('\\'),
        newVal = valArray[valArray.length - 1],
        $fakeFile = $this.siblings('.achtergrond');
    if (newVal !== '') { $fakeFile.text(newVal); }
};

$(document).ready(function() {
    $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_rounded', overlay_gallery: false, show_title: false });
    Cufon.replace('h1, h2, h3, .bladen'); // Works without a selector engine
    Cufon.replace('#sub1'); // Requires a selector engine for IE 6-7, see above
    Cufon.now();

    $(".clickable").click(function() {
        var url = $(this).find("a:last").attr("href");
        var urlLen = url.length;
        var ext = url.substring(urlLen - 4, urlLen);
        if (ext == ".pdf" || ext == ".doc" || ext == "docx") {
            docWin = window.open(url, 'docWin');
            try {
                docWin.focus();
            } catch (e) { }
        } else {
            location = url;
        }
    });

    $(".clickable2").click(function() {
        var url = $(this).find("a:first").attr("href");
        var urlLen = url.length;
        var ext = url.substring(urlLen - 4, urlLen);
        if (ext == ".pdf" || ext == ".doc" || ext == "docx") {
            docWin = window.open(url, 'docWin');
            try {
                docWin.focus();
            } catch (e) { }
        } else {
            location = url;
        }
    });
    var currFaq = "0";
    $('gehele-vraag').next(".antwoord").hide();
    $(".vraag").click(function() {
        $(".vraag").each(function() {
            $(this).removeClass("vraag_on");
            $(this).next(".antwoord").removeClass("show");
        });
        if ($(this).attr("rel") != currFaq) {
            $(this).addClass("vraag_on");
            $(this).next(".antwoord").addClass("show");
            currFaq = $(this).attr("rel");
        } else {
            $(this).removeClass("vraag_on");
            $(this).next(".antwoord").removeClass("show");
            currFaq = "0";
        }
    });

    AutoFill($("input[rel='searchField']"), "Zoeken");

    $('.vraag input[type=file]').bind('change', VIGET.fileInputs);

});

function setText(a, b) {
    x = document.getElementById(a);
    if (x) { x.innerHTML = b.options[b.selectedIndex].innerHTML };
}

function findFaq(ID) {
    var obj = $(".vraag[rel='" + ID + "']");
    $(obj).addClass("vraag_on");
    $(obj).next(".antwoord").addClass("show");
}

function AutoFill(selector, text) {
    $(selector).attr({ value: text }).focus(function() {
        if ($(this).val() == text) { $(this).val(""); } 
    }).blur(function() {
        if ($(this).val() == "") { $(this).val(text); }
    });
}

function fnSwitchContactText(id) {
    $(".route").hide();
    $("#route" + id).show();
}

