/**
* @author    Kyle Hengst <kyle@cyberdesignworks.com.au>
*/
(function($) 
	{
	
		$.fn.slidingPanels = function(settings) 
			{
			
				settings = jQuery.extend({
					panel_height: 300,
					panel_offset: 110,
					height: 300,
					offset: 0,
					class_name: 'slidingPanels'
				}, settings);
				
				function move(id,n)
					{	
						var moveto = n * settings.panel_offset;
						
						// stop all animations
						$('#'+id+' li').stop();
						
						
						// move panel
						$('#'+id+' li:eq('+n+')').addClass(settings.class_name+"_active");
						$('#'+id+' li:eq('+n+')').removeClass(settings.class_name+"_inactive");
						//alert(settings.class+"_active");
						$('#'+id+' li:eq('+n+')').animate({top:moveto});
						
						// move panels above
						$('#'+id+' li:gt('+n+')').each(function(){
							index = $('#'+id+' li').index(this);
							moveto = index * settings.panel_offset; // - (settings.panel_height+settings.panel_offset);
							$(this).addClass(settings.class_name+"_inactive");
							$(this).removeClass(settings.class_name+"_active");
							$(this).animate({top:moveto});
						});	
						
						// move panel below
						$('#'+id+' li:lt('+n+')').each(function(){
							index = $('#'+id+' li').index(this);
							moveto = index * settings.panel_offset - (settings.panel_height-settings.panel_offset);
							$(this).addClass(settings.class_name+"_inactive");
							$(this).removeClass(settings.class_name+"_active");
							$(this).animate({top:moveto});
						});
						
					}		
				
				this.each(function()
					{
						var panels = 0;
						var scope = $(this);
						$("li",scope).each(function(){
							var n = panels++;
							$(this).hover(
							function () {
								// scope.stop();
								move(scope.attr("id"),n);
								//alert(n);
							}, 
							function () {
								//$(this).find("span:last").remove();
							})
						});
						settings.height = (panels-1)*settings.panel_offset + settings.panel_height;
						settings.offset = settings.height - settings.panel_offset * panels;
						scope.height(settings.height);
						//move(scope.attr("id"),0);
					}) // close slidingPanels object
				
			} // close slidingPanels
	
	})(jQuery);