$(document).ready(function(){

    var sBaseurl = $('base').attr('href');

    // jsEnabled class for body
    $('body').addClass('jsEnabled');

    // Form check fields
    $('.swisCheckField').val('swis_check_ok');

    // Alle links met rel="external" in een nieuw venster openen
    $("a[rel=external]").each(function(i){
        this.target="_blank";
    });

    // Prefill text for inputs
    $("input[type='text']").example(function() {
        return $(this).attr('title');
    }, {className: 'searchinputtxt'});

    // Tabs homepage
    $(".eyeworksscripted .bullets").tabs(".panes > div.box-gray", {
        // here is a callback function that is called before the tab is clicked
        onClick: function(event, tabIndex) {
            $('.productiontype').hide();
            $('#productiontype'+tabIndex).show();
        },

        rotate: true
    }).slideshow({
        autoplay: true,
        clickable: false,
        interval: 4000
    });



    // News ticker op de homepage (zie http://flowplayer.org/tools/scrollable/index.html)
    $("#ticker .scrollable").scrollable({circular: true, keyboard: false, vertical: true }).autoscroll();

    // Catalogue filter
    $('#cataloguefilterform #cb_filter_checkall').click(function(){
        // als je "check all" aan of uit vinkt ook alle category checkboxen aan of uit vinken
        $('#catalogue-filter input:checkbox').attr('checked', $(this).attr('checked'));
    });

    // local productions filter: bij het kiezen van een optie in de select wordt het formulier ge-submit
    $('#localproductionsfilterform input').click(function(){
        $('#localproductionsfilterform').submit();
    });

    $('#localproductionsfilterform select').change(function(){
        $('#localproductionsfilterform').submit();
    });

    // menu background preloaden
    jQuery.preLoadImages('images/bg-cataloguemenu.png', 'images/bg-cataloguemenu-bottom.png','images/bg-companymenu.png','images/bg-companymenu-bottom.png');


    // voor spam check
    Website.initFormCheckFields();

});

// preLoad Images
(function($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)

// Cufon!
Cufon.replace('.ScalaSans, .content h2, .content h3', {
    hover: true
});




/**
* Form Check Fields
**/
var aCheckFields;
var iCheckFields;

Website.initFormCheckFields = function() {

    // Form check fields
    aCheckFields = $('.swisFormCheck');
    iCheckFields = aCheckFields.length;

    if(iCheckFields > 0) {
        $.get(Website.Config.sBaseUrl +'default/index/get-default-form-check-value', null,
        this.fillFormCheckFields);
    }

};

Website.fillFormCheckFields = function(sFormCheckValue) {

    while (iCheckFields--) {
        if (aCheckFields[iCheckFields].value == '') {
            aCheckFields[iCheckFields].value = sFormCheckValue;
        }
    }

};
