(function($){
	$(function(){
		$.fn.extend({
			slider: function(showTime, number_nav, contect_nav){
				var _autoPlay = 0;
				var itemI = 1;
				var $autoItems = $('li', this);
				var itemLength = $autoItems.length;				
				if( itemLength > 1 ){
					if(number_nav){
						var nav = '<a href="#" class="on">1</a>';
						for(var i=1; i<itemLength; i++){
							nav += '<a href="#">'+ ( i+1 ) +'</a>';
						}
						$(this).after('<p class="image_nav">' + nav + '</p>');
						var nav_item =  $(this).next('p');
						var nav_items =  nav_item.children();
					}
					if(contect_nav){
						if( number_nav ){
							nav_item.prepend('<i class="prev">&lt;</i>').append('<i class="next">&gt;</i>');
							nav_items =  $(this).next('p').children();
						} else {
							$(this).after('<p class="image_nav"><i class="prev">&lt;</i><i class="next">&gt;</i></p>');
							var nav_items =  $(this).next('p').children();
						}
					}
					
					_autoPlay = setInterval(function(){
							autoPlay(itemI);
							itemI++;
							itemI = itemI === itemLength ? 0 : itemI;
						}, showTime);
						
					function autoPlay(itemI){
						$autoItems.eq(itemI).css('z-index', 3).fadeIn(800, function(){
							$(this).addClass('on').siblings().css('z-index', 1).removeClass('on').hide();
							$(this).css('z-index', 2);		
						});
						if( number_nav ){
							nav_item.children('a').eq(itemI).addClass('on').siblings('a').removeClass();
						}	
					}
					
					
					if( number_nav || contect_nav ){						
						nav_items.click(function(){
							if( $(this).attr('class') == 'next' || $(this).attr('class') == 'prev' ){
								var i = ( $autoItems.filter(':visible').index() );
								itemI = $(this).attr('class') == 'next' ? i+1 : i-1;							
								itemI = itemI === itemLength ? 0 : itemI;	
							} else {
								itemI = parseInt($(this).text()) - 1;
							}						
							autoPlay(itemI);
							return false;
						})
																
						$(this).parent().hover(function(){
							clearInterval(_autoPlay);
						}, function(){
							_autoPlay = setInterval(function(){
								autoPlay(itemI);
								itemI++;
								itemI = itemI === itemLength ? 0 : itemI;
							}, showTime);
						});
					}
				}
			},
			panel: function(fullWidth, stepWidth){
				var items = $(this).children();
				items.each(function(){
					var i = $(this).index();
					var the_width = fullWidth - i * stepWidth;
					$(this).animate({width: the_width});
				});
				
				var homeShow_L = items.length;
				items.mouseover(function(){
					var i = $(this).index();
					$(this).stop(0, 1).animate({width: fullWidth - i * stepWidth}, 300, 'swing');
					$(this).prevAll().each(function(){
						var the_i = $(this).index();
						var the_width = fullWidth - the_i * stepWidth;
						$(this).stop(0, 1).animate({width: the_width}, 300, 'swing');
					});
					$(this).nextAll().each(function(){
						var the_i = $(this).index();
						var the_width = ( homeShow_L - the_i ) * stepWidth;
						$(this).stop(0, 1).animate({width: the_width}, 300, 'swing');
					})
				})
			}
		})
		
		$('#homeShow').slider(3000, 1, 0);
		// $('#homeShow').panel(960, 100);
		
	})
})(jQuery)
