
Cufon.replace('H1, H2, H3:not(".projectsContent H3")');
var postBackElement = { id: 0 }; // object used by update panels javascript
var gaFancyboxFormSubmitEvent = [];
// Analytics tracking coupling when a form is submitted
function gaTrackFormSubmission() {
    _gaq.push(gaFancyboxFormSubmitEvent);
    gaFancyboxFormSubmitEvent = [];
};

$(document).ready(function () {
    // Settings of the jQuery Cycle on the homepage
    $('.slides').cycle({
        fx: 'fade',
        next: '#next',
        prev: '#prev',
        timeout: 10000
    });

    //Sets all background graphics to their right position, dependent of the length of the subnavigation items in the sidebar
    var Pos = ($('.subnav').height()) + 60;
    var mainPos = (Pos) - 1000;
    var sidePos = (Pos) - 30;
    $('.main').css('background-position', '0px ' + mainPos + 'px');
    $('.sidebar .body').css('background-position', '0px ' + sidePos + 'px');
    $('.content .body').css('background-position', '0px ' + sidePos + 'px');

    $('.projects').mouseenter(function () {
        $('.projects').animate(
        { top: '0px' }, 500);
        callInit();
        $('IMG', this).attr('src', '/images/projectbar/projectsTabOpen.gif')
    });
    $('.projects').mouseleave(function () {
        $('.projects').animate(
        { top: '-200px' }, 500);
        callInit();
        $('IMG', this).attr('src', '/images/projectbar/projectsTabClosed.gif')
    });

    //Give all images with class 'Styled' a fancy border and outer glow/drop shadow
    $('IMG.styled').each(function () {
        var klas = $(this).attr('align'); //puts the alignment value of the image on the placeHolder DIV
        var imgHeight = $(this).height(); //puts the alignment value of the image on the placeHolder DIV
        var imgWidth = $(this).width(); //puts the alignment value of the image on the placeHolder DIV
        $(this).removeAttr('align'); //the align parameter of the image is removed
        $(this).wrap('<div class="placeHolder ' + klas + '">').before('<div class="cornersTop topleft"></div>' +
      '<div class="imgTop" style="width:' + (imgWidth) + 'px"></div>' +
      '<div class="cornersTop topright"></div>' +
      '<div class="imgRight" style="height:' + (imgHeight) + 'px"></div>' +
      '<div class="cornersBottom bottomleft"></div>' +
      '<div class="imgBottom" style="width:' + (imgWidth) + 'px"></div>' +
      '<div class="cornersBottom bottomright"></div>' +
      '<div class="imgLeft" style="height:' + (imgHeight) + 'px"></div>'); //Adding a bunch of DIV's to style the image
    });


    $('.footerContent .recommended A').each(function () {
        var href = $(this).attr('href');
        var html = $(this).html();
        $(this).replaceWith('<a href="' + $(this).attr('href') + '" target="_blank"><span class="arrow"><img src="/images/default/spacer.gif" width="7" height="7" border="0" />&nbsp;</span>' + $(this).html() + '</a>');
    });

    //sets the height of the news sidebar on the right
    var newsHeight = $('.news').height();
    $('.news .sidebar').height(newsHeight - 50);

    $('.button').click(function (e) {
        e.stopPropagation();
    });

    /* ---------------------------------------------------------------------------------------- */
    /*  Fancybox elements                                                                       */
    /* ---------------------------------------------------------------------------------------- */

    // Fancybox for downloading a brochure for a building
    $(".fancyboxDownloadBrochure").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Download Brochure', 'Submit'];
            _gaq.push(['_trackEvent', 'Download Brochure', 'Open']);
        }
    });
	
	// Fancybox for downloading a brochure for a building
    $(".fancyboxKeepMeInformed").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            gaFancyboxFormSubmitEvent = ['_trackEvent', 'Houd me op de hoogte', 'Submit'];
            _gaq.push(['_trackEvent', 'Houd me op de hoogte', 'Open']);
        }
    });

    // Default Fancybox config for vanwanrooij
    $(".fancyboxURL").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false
    });

    // Default Fancybox gallery config for vanwanrooij
    $(".fancyboxAdGallery").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        onComplete: function () {
            var galleries = $('.ad-gallery').adGallery();
        }
    });

    // Fancybox Photogallery
    $("a[rel=gallery]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayOpacity': '0.7',
        'showCloseButton': false,
        'titlePosistion': 'inside'
    });

    callInit();

    // Analytics tracking coupling when a form is submitted
    $("#register INPUT:last").click(function () {
        _gaq.push(gaFancyboxFormSubmitEvent);
        gaFancyboxFormSubmitEvent = [];
    });
});

function callInit() {
    // execute the function queue 
    if (initQ != null) {
        for (var i = 0; i < initQ.length; i++) {
            initQ[i].call();
        }
    }
}


