﻿(function($) {

    $.extend({

        namespace: function(spaces) {
            var parent_space = window;
            var namespaces = spaces.split(".");

            for (var i = 0; i < namespaces.length; i++) {
                if (typeof parent_space[namespaces[i]] == "undefined") {
                    parent_space[namespaces[i]] = new Object();
                }

                parent_space = parent_space[namespaces[i]];
            }

            return parent_space;
        }

    });

})(jQuery);

(function($) {

    $.myPlugin = function() {
        var test = {
            
        }
};

$.webService = function(method, params, success, failure) {

    if (!params) params = {};
    if (!failure) failure = function(xhr, status, error) {
        alert(xhr.statusText);
    }

    $.ajax({
        type: "POST",
        url: method,
        data: JSON.stringify(params),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: success,
        error: failure,
        dataFilter: function(data) {
            var response;

            if (typeof (JSON) !== "undefined" && typeof (JSON.parse) === "function")
                response = JSON.parse(data);
            else
                response = val("(" + data + ")");

            if (response.hasOwnProperty("d"))
                return response.d;
            else
                return response;
        }
    });

};
})(jQuery);


$.extend($.namespace("$.Umbraco.Ajax"),
    {
        ContactUs: function(strName, strEmail, strSubject, strMessage, success_func, error_func) {
        $.webService(
                "/ContactUs.asmx/Contact",
                { 
                strName: strName,
                strEmail: strEmail,
                strSubject:strSubject,
                strMessage:strMessage  
                },
                success_func,
                error_func);
        } 
    });


