/* Cookie plugin */
jQuery.cookie = function(key, value, options) {
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);
        if (value === null) { options.expires = -1; }
        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }
    options = value || {};
    var result, decode = options.raw ? function(s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
function createBanner() {
    var cvsHeader = document.getElementById("boxHeader_banner");
    alert(cvsHeader);
}
function LeonesSkinInitialization() {
    /* Current Team */
    var elmMyTeamLink = jQuery("#leonesMyTeamLink");
    if (elmMyTeamLink) {
        var myTeamName = jQuery('meta[name=myteam]').attr("content");
        var myTeamUrl = location.href;
        if (myTeamName) {
            jQuery.cookie('leones_myTeamName', myTeamName, { expires: 365, path: '/' });
            jQuery.cookie('leones_myTeamUrl', escape(location.href), { expires: 365, path: '/' });
        } else {
            myTeamName = jQuery.cookie('leones_myTeamName');
            myTeamUrl = unescape(jQuery.cookie('leones_myTeamUrl'));
        }

        if (myTeamName && myTeamUrl) {
            jQuery(elmMyTeamLink).text("Programma " + myTeamName).attr("href", myTeamUrl); //.show();
        } else {
            elmMyTeamLink.hide();
        }
    }
    jQuery("html").attr("xmlns:fb", "http://www.facebook.com/2008/fbml");
    
    /* Fancybox links */
    jQuery("a.fancybox").fancybox({
        'changeSpeed': 300,
        'cyclic': false,
        'enableEscapeButton': true,
        'margin': 10,
        'modal': false,
        'opacity': true,
        'overlayColor': '#666',
        'overlayOpacity': 0.3,
        'overlayShow': true,
        'padding': 5,
        'showCloseButton': true,
        'showNavArrows': true,
        'speedIn': 300,
        'speedOut': 300,
        'titlePosition': 'over',
        'titleShow': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });
    /* Apply fancybox to multiple items */
    $("a.fancybox.group").fancybox({
        'changeSpeed': 300,
        'cyclic': false,
        'enableEscapeButton': true,
        'margin': 10,
        'modal': false,
        'opacity': true,
        'overlayColor': '#666',
        'overlayOpacity': 0.3,
        'overlayShow': true,
        'padding': 5,
        'showCloseButton': true,
        'showNavArrows': true,
        'speedIn': 300,
        'speedOut': 300,
        'titlePosition': 'over',
        'titleShow': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });

    /* YouTube video in fancybox */
    $('a.youtube').click(function() {
        url = this.href;
        if (url.indexOf("youtu.be") > -1) url = url.replace(new RegExp('youtu.be', 'i'), 'www.youtube.com/embed') + '?rel=0&autoplay=1';
        else url = url.replace(new RegExp('watch\\?v=', 'i'), 'embed/') + '?rel=0&autoplay=1';
        $.fancybox({ 'type': 'iframe', 'href': url, 'overlayShow': true, 'centerOnScroll': true, 'speedIn': 100, 'speedOut': 50, 'width': 640, 'height': 480 });
        // "this.preventDefault()" doesn't work here
        return false;
    });
    //Social Initialization
    if (window.addthis) { addthis.init(); }
    // Smoelenboek
    var arrContactCard = new Array();
    var arrContactId = new Array();
    $(".contactCard").each(function(i, obj) {
        var elm = $(obj);
        var id = elm.data("id") || "";
        if (id != "") {
            arrContactCard.push({ elm: elm, id: id, fn: (elm.data("functie") || ""), bio: (elm.data("biography") || "") });
            arrContactId.push(id);
        }
    });
    if (arrContactId.length > 0) {
        $.getJSON(urlServices + "?jsoncallback=?", { ws: "getcontacts", contactid: arrContactId.join(","), format: "json" }, function(response) {
            if (response.Exceptions.length == 0 && response.Data.length > 0) {
                $.each(arrContactCard, function(i, obj) {
                    var smoel = "<h3>" + arrContactCard[i].fn + "</h3>";
                    smoel += "<img src=\"" + response.Data[i].Photo.replace("no_avatar.gif", "nopicture.png") + "\" alt=\"" + response.Data[i].Name + "\" style=\"border: solid 1px black; width: 90px; height: 116px; float: left; margin-right: 5px;\" />";
                    smoel += "<div class=\"contactInfo\">";
                    smoel += response.Data[i].Name + "<br/>";
                    if (response.Data[i].Phone != "") smoel += "<span style=\"font-size:120%;\">&#9742;</span> " + response.Data[i].Phone + "<br/>";
                    if (response.Data[i].Mobile != "") smoel += "<span style=\"font-size:120%;\">&#9990;</span> " + response.Data[i].Mobile + "<br/>";
                    if (response.Data[i].Email != "") smoel += "<span style=\"font-size:120%;\">&#9993;</span> <a href=\"mailto:" + response.Data[i].Email + "\">" + response.Data[i].Name + "</a><br/>";
                    if (arrContactCard[i].bio != "" && response.Data[i].Biography != "") smoel += "<br/>" + response.Data[i].Biography.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
                    smoel += "</div>";
                    $(arrContactCard[i].elm).html(smoel).css("display", "block").css("clear", "both");
                });
            }
        });
    }
}

(function($, Sys) {
    $(document).ready(function() {
        LeonesSkinInitialization();
    });
} (jQuery, window.Sys));

$.fn.positionOn = function(element, height) {
    return this.each(function() {
        var target = $(this);
        var position = element.position();

        var x = position.left;
        var y = position.top;

        target.css({ position: 'absolute', top: y, left: x }).height(height);
    });
};
function showLoader(clientID) {
    $("#" + clientID + "_Prog").positionOn($("#" + clientID + "_UP"), 50).show();
}
function hideLoader(clientID) {
    $("#" + clientID + "_Prog").css({ position: 'relative', top: 0, left: 0 }).height(0).hide();
}
(function(a, b) {
    dnnModalInfo = {
        load: function() {
            var e = parent;
            var d = e.parent;
            if (typeof (d.$find) != "undefined") {
                if (location.href.indexOf("popUp") == -1 || e.location.href.indexOf("popUp") > -1) {
                    e.location.href = location.href;
                    var c = e.$("#iPopUp");
                    if (c.dialog("isOpen") === true) {
                        c.dialog("option", {
                            close: function(f, g) { }
                        }).dialog("close").remove()
                    }
                } else {
                    e.$("#iPopUp").dialog({
                        title: document.title
                    })
                }
            }
        },
        show: function(g, d, c, h) {
            var f = b("#iPopUp");
            if (f.length == 0) {
                f = b('<iframe id="iPopUp" src="about:blank" scrolling="auto" frameborder="0" ></iframe>');
                b(document).find("html").css("overflow", "hidden");
                b(document).append(f)
            }
            f[0].src = g;
            var i = parent;
            f.dialog({
                modal: true,
                autoOpen: true,
                dialogClass: "dnnFormPopup",
                position: "center",
                minWidth: h,
                minHeight: c,
                maxWidth: 1920,
                maxHeight: 1080,
                resizable: true,
                closeOnEscape: true,
                close: function(j, k) {
                    b(this).remove()
                }
            }).width(h - 11).height(c - 11);
            var e = b('<a href="#" class="dnnToggleMax"><span>Max</span></a>');
            b(".ui-dialog-title").after(e);
            e.click(function(n) {
                n.preventDefault();
                var o = b(a),
                    m = b(this),
                    j, l, k;
                if (f.data("isMaximized")) {
                    j = f.data("height");
                    l = f.data("width");
                    k = f.data("position");
                    f.data("isMaximized", false)
                } else {
                    f.data("height", f.dialog("option", "minHeight")).data("width", f.dialog("option", "minWidth")).data("position", f.dialog("option", "position"));
                    j = o.height() - 11;
                    l = o.width() - 11;
                    k = [0, 0];
                    f.data("isMaximized", true)
                }
                m.toggleClass("ui-dialog-titlebar-max");
                f.dialog({
                    height: j,
                    width: l
                });
                f.dialog({
                    position: "center"
                })
            });
            if (d.toString() == "true") {
                return false
            }
        }
    };
    dnnModalInfo.load()
} (this, jQuery));

Date.prototype.addDays = function(days) {
    this.setDate(this.getDate() + days);
}
