
/*
Kwicks for jQuery (version 1.5.1)
Copyright (c) 2008 Jeremy Martin
http://www.jeremymartin.name/projects.php?project=kwicks
	
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php

Any and all use of this script must be accompanied by this copyright/license notice in its present form.
*/
(function ($) { $.fn.kwicks = function (n) { var p = { isVertical: false, sticky: false, defaultKwick: 0, event: 'mouseover', spacing: 0, duration: 500 }; var o = $.extend(p, n); var q = (o.isVertical ? 'height' : 'width'); var r = (o.isVertical ? 'top' : 'left'); return this.each(function () { container = $(this); var k = container.children('li'); var l = k.eq(0).css(q).replace(/px/, ''); if (!o.max) { o.max = (l * k.size()) - (o.min * (k.size() - 1)) } else { o.min = ((l * k.size()) - o.max) / (k.size() - 1) } if (o.isVertical) { container.css({ width: k.eq(0).css('width'), height: (l * k.size()) + (o.spacing * (k.size() - 1)) + 'px' }) } else { container.css({ width: (l * k.size()) + (o.spacing * (k.size() - 1)) + 'px', height: k.eq(0).css('height') }) } var m = []; for (i = 0; i < k.size(); i++) { m[i] = []; for (j = 1; j < k.size() - 1; j++) { if (i == j) { m[i][j] = o.isVertical ? j * o.min + (j * o.spacing) : j * o.min + (j * o.spacing) } else { m[i][j] = (j <= i ? (j * o.min) : (j - 1) * o.min + o.max) + (j * o.spacing) } } } k.each(function (i) { var h = $(this); if (i === 0) { h.css(r, '0px') } else if (i == k.size() - 1) { h.css(o.isVertical ? 'bottom' : 'right', '0px') } else { if (o.sticky) { h.css(r, m[o.defaultKwick][i]) } else { h.css(r, (i * l) + (i * o.spacing)) } } if (o.sticky) { if (o.defaultKwick == i) { h.css(q, o.max + 'px'); h.addClass('active') } else { h.css(q, o.min + 'px') } } h.css({ margin: 0, position: 'absolute' }); h.bind(o.event, function () { var c = []; var d = []; k.stop().removeClass('active'); for (j = 0; j < k.size(); j++) { c[j] = k.eq(j).css(q).replace(/px/, ''); d[j] = k.eq(j).css(r).replace(/px/, '') } var e = {}; e[q] = o.max; var f = o.max - c[i]; var g = c[i] / f; h.addClass('active').animate(e, { step: function (a) { var b = f != 0 ? a / f - g : 1; k.each(function (j) { if (j != i) { k.eq(j).css(q, c[j] - ((c[j] - o.min) * b) + 'px') } if (j > 0 && j < k.size() - 1) { k.eq(j).css(r, d[j] - ((d[j] - m[i][j]) * b) + 'px') } }) }, duration: o.duration, easing: o.easing }) }) }); if (!o.sticky) { container.bind("mouseleave", function () { var c = []; var d = []; k.removeClass('active').stop(); for (i = 0; i < k.size(); i++) { c[i] = k.eq(i).css(q).replace(/px/, ''); d[i] = k.eq(i).css(r).replace(/px/, '') } var e = {}; e[q] = l; var f = l - c[0]; k.eq(0).animate(e, { step: function (a) { var b = f != 0 ? (a - c[0]) / f : 1; for (i = 1; i < k.size(); i++) { k.eq(i).css(q, c[i] - ((c[i] - l) * b) + 'px'); if (i < k.size() - 1) { k.eq(i).css(r, d[i] - ((d[i] - ((i * l) + (i * o.spacing))) * b) + 'px') } } }, duration: o.duration, easing: o.easing }) }) } }) } })(jQuery);



var Global = {

    init: function () {
        Global.fontResizer();

        Global.inputPlaceholder();
        Global.selectCategories();

        if ($('.contentHome').length > 0) {
            Global.homeTeaser();
        }
        if (!$('.contentHome').length > 0 && $('.downloadBrochure ').length > 0) {
            $(window).scroll(Global.scrollEvent);
            Global.scrollEvent();
        }
        if ($('.accordion ').length > 0) {
            Global.accordionSetup();
        }
        if ($('.addthisBar').length > 0) {
            Global.initAddThis();
        }

    },

    initAddThis: function () {
        if ($.browser.msie && parseInt($.browser.version) == 7) {
            $('.addthisBar').addClass('addthisBarIe');
        } else if ($.browser.opera) {
            $('.addthisBar').addClass('addthisBarOpera');
        }
        $.getScript("http://s7.addthis.com/js/250/addthis_widget.js?username=milieucentraal");
    },


    scrollEvent: function () {
        var iTop = $(document).scrollTop(),
		bBrochureFixed = $('.downloadBrochure a').hasClass('fixed');

        if ($.browser.msie && $.browser.version.substring(0) == 8) {
            iTop = document.documentElement.scrollTop;
        }

        if ((bBrochureFixed && iTop < 170)) {
            $('.downloadBrochure a').removeClass('fixed');

        } else if (!bBrochureFixed && iTop > 170) {
            $('.downloadBrochure a').addClass('fixed');

        }

    },


    selectCategories: function () {
        $('#categoryswitch').each(function () {
            var $categoryswitch = $(this);

            $('.selectHandle', $categoryswitch).click(function () {
                var close = function () {
                    $categoryswitch.removeClass('open');
                    $categoryswitch.css('height', '16px');
                    $('ul', $categoryswitch).css('height', '16px');

                    //$('body').unbind('mousedown.categoryswitch');
                };

                var open = function () {
                    $categoryswitch.addClass('open');
                    $categoryswitch.css('height', 'auto');
                    $('ul', $categoryswitch).css('height', 'auto');

                    $('body').bind('mousedown.categoryswitch', function (e) {
                        if ($categoryswitch.find(e.target).length > 0) return;
                        close();
                    });
                };

                if ($categoryswitch.hasClass('open')) {
                    close();
                } else {
                    open();
                }
            });
        })

    },

    accordionSetup: function () {
        $('.accordion h2').bind('click', function () {
            var liItem = $(this).parent();

            if ($(liItem).hasClass('open')) {
                $('.innerContent', liItem).slideUp(function () {
                    $(liItem).removeClass('open');
                });

            } else {
                $('.innerContent', liItem).slideDown(function () {
                    $(liItem).addClass('open');
                });

            }
        });
    },

    fontResizer: function () {
        if (Cookie.getCookie('verbouwwijzerFontSize')) {
            var iSetFontSize = parseFloat(Cookie.getCookie('verbouwwijzerFontSize'));
            $('.mainContent .wysiwyg').css('fontSize', iSetFontSize);
            $('.mainContent .accordion').css('fontSize', iSetFontSize);
            Cufon.refresh();
        }

        $('.textToolbar .txtResize').click(function () {
            var mainContent = $('.mainContent');
            var sCurrFontSize = $('.wysiwyg', mainContent).css('fontSize');

            if (Cookie.getCookie('verbouwwijzerFontSize')) {
                var iCurrFontSize = parseFloat(Cookie.getCookie('verbouwwijzerFontSize'));
            } else {
                var iCurrFontSize = parseFloat(sCurrFontSize, 10);
            }

            var iNewFontSize = iCurrFontSize;
            if ($(this).hasClass('txtLarger')) {
                iNewFontSize = iCurrFontSize + 1;
            } else if ($(this).hasClass('txtSmaller')) {
                iNewFontSize = iCurrFontSize - 1;
            }

            $('.wysiwyg', mainContent).css('fontSize', iNewFontSize);
            $('.accordion', mainContent).css('fontSize', iNewFontSize);
            Cufon.refresh();

            Cookie.setCookie('verbouwwijzerFontSize', iNewFontSize, 1);

        });
    },

    homeTeaser: function () {
        $('.homeTeaser').kwicks({
            max: 194,
            spacing: 1
        });
    },


    inputPlaceholder: function () {
        $('input[data-placeholder]').each(function () {
            if ($(this).val() == '') {
                var value = $(this).attr('data-placeholder');
                $(this).val(value);
                $(this).addClass('iPlaceholder');
            }

            $(this).focus(function () {
                var value = $(this).attr('data-placeholder');
                if ($(this).val() == '' || $(this).val() == value) {
                    $(this).val('');
                    $(this).removeClass('iPlaceholder');
                }

            }).blur(function () {
                if ($(this).val() == '') {
                    var value = $(this).attr('data-placeholder');
                    $(this).val(value);
                    $(this).addClass('iPlaceholder');
                }
            });
        });
    }

}


var Cookie = {
    setCookie: function (name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },

    getCookie: function (name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },

    deleteCookie: function (name) {
        Cookie.setCookie(name, "", -1);
    }
}

$(Global.init);


