﻿var EventWidgets = EventWidgets ? EventWidgets : function () {

    var private = {

        host: "memberservices.membee.com/feeds",
        

        jsonpcall: function (fn, parms, callbackFn) {

            $.getJSON('http://' + private.host + '/' + fn + '?' + parms + '&method=?',
                callbackFn);
        },

        loadhtml: function (container, urlraw, callback, parms) {

            

            var urlselector = (urlraw).split(" ", 1);
            var url = urlselector[0];
            var selector = urlraw.substring(urlraw.indexOf(' ') + 1, urlraw.length);
            container = container;
            callback = callback;

            private.jsonpcall('Service.ashx', 'downloadurl=' + escape(url) + "&" + parms,
                function (msg) {
                    // gets the contents of the Html in the 'msg'
                    // todo: apply selector
                    //private.container.html(msg);
                    
                    container.html(msg);
                    if ($.isFunction(callback)) {
                        callback();
                    }
                });
        },

        // wire widget after it's loaded
        Events_Init: function () {

        }
    };

    var public = {

        // load widget into 'container' from 'host'
        Events: function (container, parms) {
        
            private.loadhtml(container, 'http://' + private.host + '/Events',
                private.Events_Init, parms);
        }
    }

    return public;
} ();


