﻿(function($) {


    window.VD = {

        ie: false,
        msieVersion: -1,
        //pre-init, call cufon etc..
        boot: function(siteRoot) {
            this.siteRoot = siteRoot;
            this.msieVersion = -1;
            if ($.browser.msie) {
                this.ie = true;
                this.msieVersion = parseInt($.browser.version, 10);
                $('html').addClass('ie ie' + this.msieVersion);
                //setup IE6 options
                window.IE6UPDATE_OPTIONS = {
                    icons_path: "http://static.ie6update.com/hosted/ie6update/images/"
                }
            }
            this.doCufon();


            //Custom radio buttons, niet op het nieuwsbrief-formulier
            if ($('.mpFormTable').html() == null) {
                $('input').customInput();
            }

            //$('img[usemap]').maphilight({
            //    groupBy: 'href',
            //    stroke: false,
            //    fillColor: '000000',
            //    fillOpacity: '0.3'
            //});
        },
        contentFlowTitleSelector: '#contentFlow .globalCaption .title',
        doCufon: function() {

            //if(!this.ie) {
            //TODO: determine if we want to use cufon for this or not


        Cufon.replace('.menu1 .item, .menu2 .item a', {
            //fontFamily: 'Arial'
            //fontFamily: 'Waukegan'
            fontFamily: 'EurostyleLT',
            fontWeight: 100
        });
        //}
        Cufon.replace('h1,h2,h3,h4,h5, .divContentLinkBlockText, .leafletLink, .videoLink', {
            fontFamily: 'WideEurostile'
            //fontFamily: 'EurostyleLT',
            //fontWeight: 700
            //fontFamily: 'MicrogrammaD'
        });

        Cufon.replace('.sfeerbeeld h1', {
            fontFamily: 'EurostyleLT'
            //fontFamily: 'Waukegan'
        });
        Cufon.replace('.homeMotivatorText > h2, .pageNotFound > h1, .pageNotFound > h2, .pageNotFoundLinks > h2', {
            fontFamily: 'DemiEurostile'
        });
        Cufon.replace('.homeMotivatorText > .subtext', {
            fontFamily: 'EurostyleLT'
        });

        Cufon.replace('.divProductenHomeContent > h1, .divKwaliteitHomeContent > h1, .divServiceHomeContent > h1, .divDuurzaamHomeContent > h1, .divHomeContentContent > h1, .divSmaakHomeContent > h1, .newsPageTitle, .faqPageTitle', {
            //fontFamily: 'Waukegan'
            //fontFamily: 'EurostyleLT'
            fontFamily: 'DemiEurostile'
        });
        Cufon.replace('.divLinkBlockText h2', {
            fontFamily: 'EurostyleLT'
        });
        Cufon.replace('div.jubileumContent h2, div.jubileumContent h3', {
            fontFamily: 'EurostileJubileum',
            fontWeight: 700
        });


        Cufon.replace(VD.contentFlowTitleSelector, {
        //fontFamily: 'EurostyleLT'
    });

    Cufon.now();
    //#contentFlow .globalCaption .title

},

/** 
* DOM is ready, init menus etc..
*/
documentReady: function() {
    if (this.ie && this.msieVersion < 9) {
        //roundedCorners for IE
        // use CSS3 for the rest
        //this must be applied before we initialize the menu
        this.fixSubmenuCorners();
    }
    this.initMenu();

    this.pngFix();

    //            if (window.VD.msieVersion == 7) {
    //                $('#site').addClass('ie7');
    //            }
},
pngFix: function() {
    if (this.ie && this.msieVersion == 6) {
        var pngFixSelector = '#header,#content,#footer .footerLogoCt';
        pngFixSelector += ',.region-bottom';
        pngFixSelector += ',.automaatselector div.caption';
        pngFixSelector += ',.palletkortingOverlay';

        $(pngFixSelector).pngFix({
            blankgif: this.siteRoot + 'Img/blank.gif'
        });
    }
},

/* setup jquery corner plugin */
fixSubmenuCorners: function() {
    //check for plugin
    if (!$.fn.corner) { return; }
    //create rounded corners

    //we must set the display property for the ul.submenu here, because otherwise both the roundedcorner div & the submenu are hidden            
    $('#nav ul.submenu')
                .wrap('<div class="roundedcorners" />')
                .show();
    $('#nav .roundedcorners')
                .corner('bottom 8px');
    if (this.ie) {
        //modify some properties for IE7 & IE8
        if (this.msieVersion < 8) {
            $('#nav .roundedcorners').children('div:first').remove();
            $('#nav .roundedcorners').children('div:last').css('margin-top', '-16px');
        } else {
            $('#nav .roundedcorners').children('div:last').css('margin-top', '-3px');
        }
    }
    //$('#nav ul.submenu').corner('bottom');
},

initMenu: function() {
    var siteWidth = parseInt($('#nav .section').width(), 10);
    var mainMenu = $('#nav ul.menu1');
    var mainMenuItems = mainMenu.children('li');

    var itemWidth;
    if (mainMenuItems.length > 5) {
        // if we have more than 5 top level menu items we must resize them to fit the available space
        itemWidth = Math.floor(siteWidth / mainMenuItems.length);
        mainMenuItems.css('width', itemWidth);
    }

    var level2 = $('#nav ul.menu2');
    var level2Children = level2.children('li');

    if (level2Children.length > mainMenuItems.length) {
        //new width
        itemWidth = Math.floor(siteWidth / level2Children.length);
        level2Children.css('width', itemWidth);
        //also size the subsubmenus
        level2.find('.submenu').css('width', itemWidth);
    }

    //attach event listeners:
    level2.delegate('li.item', 'mouseover', function() {
        var me = this;
        //cancel any close operation if it's scheduled
        if (me._hideTimer) {
            clearTimeout(me._hideTimer);
            me._hideTimer = null;
            //delete me._hideTimer;
        }
        $(this).addClass('active')
                    .children('.submenu,.roundedcorners')
                    .show();
    });
    level2.delegate('li.item', 'mouseout', function() {
        var me = this;
        //close the menu after a short delay
        me._hideTimer = setTimeout(function() {
            $(me).removeClass('active')
                        .children('.submenu,.roundedcorners')
                        .hide();
            me._hideTimer = null;
            //delete me._hideTimer;
        }, 100);
    });

    /*level2Children.css('display', 'inline');
    mainMenuItems.css('display', 'inline');*/
}
};

function initSizes() {

    if (window.VD.msieVersion != 6) {
        //Fix content height, note this causes some troubles in IE 6, therefore it's disabled
        var browserHeight = $('#site').outerHeight();
        var bottomHeight = $('.region-bottom').outerHeight();
        var horizonHeight = $('.region-horizon').outerHeight();
        var headerHeight = $('#header').outerHeight();
        var navHeight = $('#nav').outerHeight();
        var breadcrumbsHeight = $('#breadcrums').outerHeight();

        var contentHeight = $('#content').outerHeight();
        var desiredHeight = browserHeight - bottomHeight - horizonHeight - headerHeight - navHeight - breadcrumbsHeight; // - 125
        //var magicNumber = 85;
        if (contentHeight < desiredHeight) {
            $('#content').height(desiredHeight); //- magicNumber);
        }
    }
    //Fix footer item alignment
    var footerLis = $('ul.footerMenu li');
    if (footerLis.length > 2) {
        //Disclaimer moet minder margin-right krijgen om Sitemap naar links te verplaatsen               
        $(footerLis.get(2)).css("margin-right", "17px");
    }
    if (footerLis.length > 6) {
        //Van Duijnen Horeca moet minder margin-right krijgen om Contact naar links te verplaatsen
        $(footerLis.get(6)).css("margin-right", "0px");
    }

}

$(document).ready(function() {
    VD.documentReady();
    fixfortestpages()

    $('div.sollicitatieFormulier input[type="file"].fileInputSoli').filestyle({ imageheight: 22, imagewidth: 65, width: 274 });
});

$(window).load(function() {
    fixfortestpages();

    //initSizes();

    if (window.VD.msieVersion == 6 && $.fn.activebar) {
        $('<div></div>').html(IE6UPDATE_OPTIONS.message || 'Internet Explorer is missing updates required to view this site. Click here to update... ')
                .activebar(window.IE6UPDATE_OPTIONS);
    }
});



})(jQuery);


function postCallMeBack(naam, telefoonNummer) {
    var url = VD.siteRoot + "ashx/CallMeBackHandler.ashx"; 
        
    $.ajax({
        url: url,
        data: {
            name: naam,
            phone: telefoonNummer
        },
        dataType: 'json',
        type: 'GET',
        success: function(data, textStatus, jqXHR) {
            showCallMeBackPanel(".divHomepageCallMeNowThanks");
        },
        error: function(jqXHR, textStatus, errorThrown) {
            showCallMeBackPanel(".divHomepageCallMeNowError");
    }

    });
}

function showCallMeBackPanel(divId) {
    $(".divHomepageCallMeNowForm").hide();
    $(".divHomepageCallMeNowThanks").hide();
    $(".divHomepageCallMeNowError").hide();

    $(divId).show();
}


function fixfortestpages() {
    // telefoonnummer
    if ($(location).attr('href').indexOf("new_homepage_test.aspx") != -1)
        $("#header .imgPhoneNumber").css('display', 'block');

    //test a
    if ($(location).attr('href').indexOf("new_productaanbod_test_a.aspx") != -1) {
        $(".divProductenHome").addClass("divProductenHomeNew");
        $("#header .imgPhoneNumber").css('display', 'block');
    }

    //test b
    if ($(location).attr('href').indexOf("new_productaanbod_test_b.aspx") != -1) {
        $("#header .imgPhoneNumber").css('display', 'block');
    } 

}

