/* 
* Ykone.com - JS
* @author Mohamed BENARROUDJ <mohamed.benarroudj@laposte.net>
*/
(function($){
	
	$.fn.yTabs = function(y_callback){
	
		$(this).each(function(){
    
			// Save Current Tab
			var tabs = $(this);
			
			// Retrieve Div container
			var container = tabs.next('div:first');
			
			// Callback on links
			$('li > a', this).click(function(){

				var node = $(this);
        
        // Add loading animation
        container.prepend("<div class='ajax-loading'></div>");
					
				// Retrieve target
				var target = node.attr('href').split('#')[0];
				if( target.length )
				{		
					// Select tab
					$('li.active', tabs).removeClass('active');
					node.parent('li').addClass('active');
				
					// Display loading
					$(".ajax-loading", container).fadeIn();
											
					// Load content
					$.get(target, {'ajax':1}, function(data)
					{
						// Hide loading
						$(".ajax-loading", container).fadeOut();
						
						// Show content
						// Note: Use InnerHTML function instead of "html()" function.
						//       "html()" function load js from content and infinity loop
						container.fadeOut(function(){container[0].innerHTML = data; if( typeof(y_callback) != 'undefined' ) y_callback(); container.fadeIn()});
					});
				}
				
				return false;
			});
		});
	}

})(jQuery)