$(function(){
	$.extend({
		slider:function(options){
			var defaults = {contentCls:"mfpSlide-con",navCls:"mfpSlide-nav",linkCls:"mScm-link",timer:5000,activeTriggerCls:"selected",intval:null};
			var opts = $.extend(defaults,options);
			var activeIndex = 0;
			var allIndex = $("."+opts.contentCls).find("li").length;
			function init(){
				navtrigger();
				opts.intval = setInterval(function(){slide();},opts.timer);
			}
			function navtrigger(){
				$("."+opts.contentCls+" li a."+opts.linkCls).mouseover(function(){
					clearInterval(opts.intval);opts.intval=null;
				}).mouseout(function(){
					opts.intval = setInterval(function(){slide();},opts.timer);
				});
				$("."+opts.navCls).find("li").each(function(index){
					$(this).click(function(){
						clearInterval(opts.intval);opts.intval=null;
						targetIndexTmp=index;
						activeIndex=$("li."+opts.activeTriggerCls).index();
						$("."+opts.navCls).find("li").eq(activeIndex).removeClass(opts.activeTriggerCls);
						$("."+opts.navCls).find("li").eq(targetIndexTmp).addClass(opts.activeTriggerCls);
						var acp = $("."+opts.contentCls).find("li").eq(activeIndex);
						var ncp = $("."+opts.contentCls).find("li").eq(targetIndexTmp);
						if(acp.find("b").length==1){acp.find("b").animate({top:-40,opacity:0});}
						opts.intval = setInterval(function(){slide();},opts.timer);
						acp.fadeOut('slow',function(){
							ncp.fadeIn('slow');
							if(ncp.find("b").length==1){ncp.find("b").animate({top:-10,opacity:1});}
							activeIndex=targetIndexTmp;
						});
					});
				});
			}
			function slide(targetIndex){
				targetIndex = activeIndex+1;
				if(targetIndex>=allIndex){targetIndex=0;}
				$("."+opts.navCls).find("li").eq(activeIndex).removeClass(opts.activeTriggerCls);
				$("."+opts.navCls).find("li").eq(targetIndex).addClass(opts.activeTriggerCls);
				var acp = $("."+opts.contentCls).find("li").eq(activeIndex);
				var ncp = $("."+opts.contentCls).find("li").eq(targetIndex);
				if(acp.find("b").length==1){acp.find("b").animate({top:-40,opacity:0});}
				acp.fadeOut('slow',function(){
					ncp.fadeIn('fast');
					if(ncp.find("b").length==1){ncp.find("b").animate({top:-10,opacity:1});}
					activeIndex=targetIndex;
				});
			}
			init();
		}
	});
});