function closeLayer(id) {
	$('#'+id).slideUp(250, function() {
		$('#'+id).remove();
	});
	$('#customers > li a').removeClass('active');
}

(function($){ 
    $.fn.extend({  
        dynamiclist: function() {
			var count = 0;
			var container = "customerInfo";
			var extList = $('<li id="'+container+'" class="customerInfoList" style="display:none;"></li>');
			
			function showInfo(elm, id){
				var link = $(elm).attr("href");
				var pos = $(elm.parentNode).attr("class");
				$('#'+id+'> li a').removeClass('active');
				$(elm).addClass('active');
				$('ul#'+id+' li.'+pos+':last').after(extList);
				$.ajax({
					url: link, 
					cache: false, 
					success: function(content){
						$('#'+container).html(content);
						$('#'+container).slideDown(500);
					}
				});
			}		
			function toggleInfo(elm, id){
				if($(elm).attr("href")) {
					if($(elm).hasClass("active")){
						$(elm).removeClass("active");
						closeLayer(container);
					} else {
						if($('#'+container).attr("id")) {
							extList.slideUp(500, function(){showInfo(elm, id);});
						} else {
							showInfo(elm, id);
						}
					}
				}
			}
			
			return this.each(function() {
				var list = $(this).attr("id");	
				$('#' + list + '> li a').click(function(event){
					toggleInfo(this, list);
					return false;
				});
            }); 
        },
		filter: function() {
		
			function showFilter(e) {
				$("ul.customerList li a").css({ 'opacity': '1' });
				$("ul.customerList li a[rel!='"+e+"']").each(function(){
					if($(this).attr("rel")) {
						$(this).css({ 'opacity': '0.125' });
					}
				});
			}
			function removeFilter(e) {
				$("ul.customerList li a[rel!='"+e+"']").each(function(){
					if($(this).attr("rel")) {
						$(this).css({ 'opacity': '1' });
					}
				});
			}
		
			return this.each(function() {
				var id = $(this).attr("id");
				$('#'+id+' li a').click(function(event){
					if($(this).hasClass("active")) {
						$(this).removeClass("active");
						removeFilter($(this).html().toLowerCase());
					} else {
						$('#'+id+' li a').removeClass("active");
						$(this).addClass("active");
						showFilter($(this).html().toLowerCase());
					}
				});
			});
		}
    }); 
})(jQuery);
