if (initQ === undefined) var initQ = [];



var gaFancyboxFormSubmitEvent = [];
// Analytics tracking coupling when a form is submitted
function gaTrackFormSubmission() {
    _gaq.push(gaFancyboxFormSubmitEvent);
    gaFancyboxFormSubmitEvent = [];
};
$(document).ready(function () {
    $('#slider').bxSlider({
        auto: true,
        speed: 1500,
        pause: 6000,
        randomStart: true,
        autoControls: false,
        autoHover: true,
        pager: true,
        controls: true
    });
    $('#slider-projecten').bxSlider({
        auto: false,
        autoControls: false,
        autoHover: true,
        controls: true,
        displaySlideQty: 5
    });
    $('#slider-woningtypes').bxSlider({
        auto: false,
        autoControls: false,
        autoHover: true,
        controls: true,
        infiniteLoop: false,
        displaySlideQty: 4
    });
    $(function () {
        var tabContainers = $('div.woning-zoeken > div');
        tabContainers.hide().filter(':first').show();

        $('div.woning-zoeken ul.tab a').click(function () {
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $('div.woning-zoeken ul a').removeClass('active');
            $(this).addClass('active');
            return false;
        }).filter(':first').click();

    });
    //$(function () {
    $("span.checkboxList input").ezMark();
    $("span.selectList select, #zoeken select").selectbox();
    // });

    /* ---------------------------------------------------------------------------------------- */
    /*  Fancybox elements                                                                       */
    /* ---------------------------------------------------------------------------------------- */
    // Fancybox for the footer signupURL
    $(".fancyboxFooterSignupURL").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Inschrijven Algemeen', 'Footer', 'Submit'];
            _gaq.push(['_trackEvent', 'Inschrijven Algemeen', 'Footer', 'Open']);
        }
    });

    // Fancybox for the widget Signup
    $(".fancyboxWidgetSignupURL").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Inschrijven Algemeen', 'Widget', 'Submit'];
            _gaq.push(['_trackEvent', 'Inschrijven Algemeen', 'Widget', 'Open']);
        }
    });

    // Fancybox for downloading a brochure for a building
    $(".fancyboxBuildingDownloadBrochure").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Woningen', 'Download Brochure', 'Submit'];
            _gaq.push(['_trackEvent', 'Woningen', 'Download Brochure', 'Open']);
        }
    });

    // Fancybox for downloading a brochure for a building
    $(".fancyboxBuildingMoreInformation").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Woningen', 'Meer informatie', 'Submit'];
            _gaq.push(['_trackEvent', 'Woningen', 'Meer informatie', 'Open']);
        }
    });

    // Fancybox for downloading a brochure for a building
    $(".fancyboxBuildingKeepMeInformed").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Woningen', 'Houd me op de hoogte', 'Submit'];
            _gaq.push(['_trackEvent', 'Woningen', 'Houd me op de hoogte', 'Open']);
        }
    });

    // fancybox for downloading a brochure for a project
    $(".fancyboxProjectDownloadBrochure").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Projecten', 'Download Brochure', 'Submit'];
            _gaq.push(['_trackEvent', 'Projecten', 'Download Brochure', 'Open']);
        }
    });

    // Fancybox for downloading a brochure for a building
    $(".fancyboxProjectMoreInformation").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Projecten', 'Meer informatie', 'Submit'];
            _gaq.push(['_trackEvent', 'Projecten', 'Meer informatie', 'Open']);
        }
    });

    // Fancybox for downloading a brochure for a building
    $(".fancyboxProjectKeepMeInformed").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Projecten', 'Houd me op de hoogte', 'Submit'];
            _gaq.push(['_trackEvent', 'Projecten', 'Houd me op de hoogte', 'Open']);
        }
    });

    $('#pagecontent a').each(function () {
        var title = $(this).attr('title');
        var klas = $(this).attr('class');
        if (title == "fancyboxURL")
        {
            $(this).attr('class', title + ' ' + klas);
            $(this).attr('title', '');
        }
    });

    // Default Fancybox config for vanwanrooij
    $(".fancyboxURL").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false
    });

    // Default Fancybox config for vanwanrooij
    if (typeof initializeMap == 'function') {
        $(".fancyboxGM").fancybox({
            'transitionIn': 'none',
            'transitionOut': 'none',
            'overlayOpacity': '0.7',
            'showCloseButton': false,
            'onComplete': initializeMap,
            'onClosed': function () { /*if (typeof showAllMarkers == 'function') { showAllMarkers(mapSmall); }*/ }
        });
    }    

    $('FORM').keypress(function(e){ disableEnterKey(e) }); 
    $.expr[':'].focus = function(a){ return (a == document.activeElement); }

    callInit();

    
});

function callInit() {
    // execute the function queue 
    if (initQ != undefined) {
        for (var i = 0; i < initQ.length; i++) {
            initQ[i].call();
        }
    }
}

function disableEnterKey(e) {	
    var key; 
    // relay the keycode to the right variable 
    if (window.event) { 
        key = window.event.keyCode; //IE 
    } else { 
        key = e.which; //firefox 
    } 

    if (key == 13) { 
        // pressed the enter key 
        if ($(".:focus").is("input")) { 
            // selected a form item 
            // simulate/bubble the keypress to the item 
            $(".:focus").keypress(e); 
            return false; 
        } else { 
            e.preventDefault(); 
            // not selected any form item 
            return false; 
        } 
    } else { 
        // just pressed a key, do nothing 
        return true; 
    } 
}
