;(function($){
    
    dsg.fn.initToolTabLoader = function(ajaxurl, params){
        /*
        * tabs is an array containing objects of this type :
        *   bundles: {
        *       name: 'BundleList',
        *       id: '#tab-promopack'
        *   }
        *    
        * -> name: name of the block to load
        * -> id: id of the div receiving content
        */
        var options = $j.extend({
            tabs: {}
        }, params)
				
				var loaded = new Array();
        var ajaxurltab = new Array();
				var loaderDIV = '<div class="tab-content-loader" style="position:relative; height:150px; background-color:#eee;">\
														<img src="http://panther.dev/fo-pixmania/css/i/icons/ajax-loader.gif" style="position:absolute; top:50%; left:50%; margin-left:-10px; margin-top:-10px;" />\
													</div>';
				
        $.each(options.tabs, function(i, tab){
            ajaxurltab[i] = tab.session_start==false ? ajaxurl + "&tab=" + tab.name +"&bStartSession="+tab.session_start : ajaxurl + "&tab=" + tab.name;
						loaded[i] = false;
						// Get tab content
						if(tab.onclick===true) { $("a[href='"+tab.id+"']").click(function(){loadTabContent(i,tab.id);}); }
						else loadTabContent(i,tab.id);
        });
				
        function loadTabContent(i,tabId) {
					if (!loaded[i]) {
						$(tabId+" .content").html(loaderDIV);
						// Show loader
						$(tabId + " img").show();
						$.ajax({
							url: ajaxurltab[i],
							success: function(htmlcontent){
								if ( '' == jQuery.trim(htmlcontent) ) {
									removeBundleTab(tabId);
								} else {
									loaded[i] = true;
									$(tabId+" .content").html($(htmlcontent).find(".content").html());
									if ( $j("a.weee-link").length > 0 ) {
										$j("a.weee-link").simpletooltip({
											click: true, 
											hideOnLeave:false
										});
									}
									if (tabId == "#tab-comparometer") prdPageCompare();
								}
							},
							error: function(){
								removeBundleTab(tabId);
							}
						});	
					}
				}
				
        function removeBundleTab(tabId) {
					// Remove bundle tab
					$("#menu-tabs").find("a[href='"+tabId+"']").parent('li').remove();
					$(tabId).remove();
					// Reload tabs
					$("#fa-bottom-tabs").simpletabs({noresize: true});
        }
    };
})(jQuery);