(function($) {
	$.cmsMapPath = function(relativeUrl, applicationName, pluginName, pluginVersion) {
		var url = "/";
		
		if (applicationName == null){
			applicationName = $.cmsGetSite();
		}

		if (applicationName != null && applicationName.length > 0 && window.location.href.indexOf(applicationName) > 0) {
			url = "/" + applicationName + "/";
		}

		if (pluginName != null) {
			url += "plugins/" + pluginName;
			if (pluginVersion != null) {
				url += "-" + pluginVersion + "/";
			}
			else {
				url += "-0.1/";
			}
		}

		return url + relativeUrl;
	};
	
	$.cmsGetSite = function(){
		var site = $("meta[name='site']").attr('content');
		if (site == null){
			return null;
		}
		if (site.charAt(site.length-1) == "/"){
			site = site.substring(0, site.length-1);
		}
		if (site.charAt(0) == "/"){
			site = site.substring(1);
		}
		return site;
	};
})(jQuery);
