// Plugin loading in jquery
// Jose I. Paris
(function($){
  $.extend({
    require: function(plugin, o){
      o = $.extend({
        css: false,
        jsbase: '',
        cssbase: '',
        onload: null
      }, o || {});
      var src = o.jsbase + '/' + plugin + '.js';
      // Provide a callback function to the getScript function
      $.getScript(src, o.onload);
      if(o.css){
        var c = document.createElement('link');
        c.type = 'text/css';
        c.rel = 'stylesheet';
        c.href = o.cssbase + '/' + plugin + '.css';
        $('head')[0].appendChild(c);
      }
    },
	
	requireCss: function(cssPath,id){
        var c = document.createElement('link');
		if(id){
			$(c).attr("id",id);
		}
        c.setAttribute("type","text/css");
        c.setAttribute('rel','stylesheet');
        c.setAttribute("href",cssPath);
		c.setAttribute("media", "all");
        $('head')[0].appendChild(c);
    },
	
	changeCss: function(id,cssPath){
		var elem=document.getElementById(id);
		if(elem){
			$('#'+id).attr("href",cssPath);
		}else{
			$.requireCss(cssPath,id);
		}
    }
	
  });
})(jQuery);
