﻿
var EM = {
    root: '/',
    msie: false,
    msieVersion: -1,
    /* siteVersion: used to disable the cache */
    siteVersion: 3,
    cufonSelectors: ['.topnav li.item a', 'h1', 'h2', '.emfont', '.sf_label', '.mylightbox .tablabel'],
    //    Lightbox: {
    //        models: []
    //    },
    /* startup the site */
    boot: function (siteRoot) {
        this.root = siteRoot;

        this.init();

        this.cufon();
        Cufon.now();
    },
    init: function () {
        if ($.browser.msie) {
            this.msie = true;
            this.msieVersion = parseInt($.browser.version, 10);
            if (this.msieVersion < 7) {
                this.initIE6();
            } else if (this.msieVersion == 7) {
                this.initIE7();

            }
        }
        if (EM.ModelSearch) {
            EM.ModelSearch.init();
        }
        this.Lightbox.init();
    },
    cufon: function () {
        var selector = this.cufonSelectors.join(',');
        Cufon.replace(selector);
    },
    cufonModelSearch: function () {
        var selector = '.sf_label';
        //selector += ',h1,h2';
        Cufon.replace(selector);

    },
    refreshCufon: function () {
        Cufon.refresh();
    },


    /* IE 6 modifications */
    initIE6: function () {
        $('<link />', {
            rel: 'stylesheet', 'type': 'text/css',
            href: this.root + 'css/ie6.css'
        }).appendTo('head');
    },
    /* IE 7 modifications */
    initIE7: function () {
        /*
        console.log('V1=' + $('html').width());
        console.log('V2=' + $('body').width());
        console.log('V3=' + $(document).width());
        console.log('V4=' + $('#container').width());
        */
        //hide odd horizontal scrollbar in IE7
        $('html').css('overflow-x', 'hidden');

        //the negative text-indent doesn't work as expected in IE7, so just remove the tekst from the links
        $('#socialmedia a').text('');
    },

    loadJson: function (url, data, handler) {
        if (arguments.length < 3) {
            handler = arguments[1];
            data = {};
        }
        this.ajax(url, data, 'json', handler);
    },
    loadText: function (url, data, handler) {
        if (arguments.length < 3) {
            handler = arguments[1];
            data = {};
        }
        this.ajax(url, data, 'text', handler);
    },
    ajaxPost: function (url, data) {
        $.ajax({
            url: EM.root + url,
            data: data || {},
            type: 'POST',
            dataType: 'text',
            success: EM.noop
        });
    },

    ajax: function (url, data, dataType, handler) {
        $.ajax({
            url: EM.root + url,
            data: data || {},
            type: 'GET',
            cache: true,
            dataType: dataType,
            success: handler
        });
    },


    positionNewsForm: function () {
        function repositionForm() {
            var pageLocationJQObj = $("#nieuwsbrief1");
            var pageLocationObj = pageLocationJQObj.get(0);
            //var formJQobj = $("#nieuwsbriefInner"); 
            var formJQobj = $('form[action*=mailplus]');
            var formobj = formJQobj.get(0);
            var h = formJQobj.height();
            pageLocationObj.style.height = h + 'px';
            var loc = pageLocationJQObj.offset();
            formobj.style.position = 'absolute';
            formobj.style.top = loc.top + 'px';
            formobj.style.left = loc.left + 'px';
            formobj.style.zIndex = 10000;
        }
        $(repositionForm);
        $(window).bind('resize', repositionForm);
        setTimeout(repositionForm, 800);
    },

    /** ignore this function */
    noop: function () { }
};
