

(function($){
		
		//下拉菜单  （三种效果show、fade、slide，speed设置速度）
		$.fn.showMenu=function(settings){
			settings=$.extend({
				effect: "show",		
				speed: 300
			},settings);
			if(settings.effect=="show"){
				this.hover(function(){ $(this).find("ul").show();     	},
								function(){ $(this).find("ul").hide();				});
			}else if(settings.effect=="fade"){
				this.hover(function(){ $(this).find("ul").fadeIn(settings.speed);     	},
								function(){ $(this).find("ul").fadeOut(settings.speed);				});	
			}else if(settings.effect=="slide"){
				this.hover(function(){ $(this).find("ul").slideDown(settings.speed);     	},
								function(){ $(this).find("ul").slideUp(settings.speed);				});		
			}
			return this;
		}
		
		
		//Tab切换
		$.fn.tabSwitch=function(settings){
			settings=$.extend({
				tabContent: "tab_cont",
				currentClass: "curr",
				firstShow: 1
			},settings);
			$(this).children().eq(settings.firstShow-1).addClass(settings.currentClass);
			$("."+settings.tabContent).hide().eq(settings.firstShow-1).show();
			$(this).children().each(function(n){ $(this).attr("index",n);	});			
			$(this).children().click(function(){
					var currIndex=parseInt($(this).attr("index"));
					$(this).addClass(settings.currentClass).siblings().removeClass(settings.currentClass);
					$("."+settings.tabContent).eq(currIndex).show().siblings("."+settings.tabContent).hide();
			});
			return this;
		}
		
		
		//展开&收缩
		$.fn.stretch=function(settings){
			st=$.extend({
				nextTag: "ul",
				currentClass: "curr",
				animate: true,
				defaultOpen: 0,
				autoBack: false
			},settings);
			$(this).eq(st.defaultOpen).addClass(st.currentClass).next(st.nextTag).show().siblings(st.nextTag).hide();
			if(st.autoBack){
				$(this).click(function(){
					$(this).addClass(st.currentClass).siblings().removeClass(st.currentClass);
					if(st.animate){
						$(this).next(st.nextTag).slideDown().siblings(st.nextTag).slideUp();
					}else{
						$(this).next(st.nextTag).show().siblings(st.nextTag).hide();
					}				
				});
			}else{				
				$(this).click(function(){
					$(this).toggleClass(st.currentClass);
					if(st.animate){
						$(this).next(st.nextTag).slideToggle();
					}else{						
						$(this).next(st.nextTag).toggle();	
					}
				});
			}			
		}
		
		
		//Banner切换
		$.fn.bannerSlide=function(settings){
			st=$.extend({
				width: 800,
				height: 200,
				numStyle: "numStyle",
				numCurr: "numCurr",
				effect: "slide",
				interval: 4000,
				speed: 800
			},settings);
			st.currIndex=0;		
			st.thisObj=$(this);
			st.actionTime=null;
			$(this).css({	position:"relative", width:st.width+"px", height:st.height+"px", overflow:"hidden", zoom:1 });
			$(this).find("ol,ul,li").css({listStyle:"none", padding:"0px", margin:"0px"});
			$(this).find("li").css({width:st.width+"px", height:st.height+"px", overflow:"hidden"});
			$(this).find("img").css({border:"none"});
			$("."+st.numStyle).children().each( function(n){$(this).attr("index",n)} );
			if(st.effect=="slide"){
				$(this).children("ul").css({ position:"absolute", top:"0px", left:"0px"});
				$("."+st.numStyle).children().click(function(){
					clearTimeout(st.actionTime);
					thisIndex=parseInt($(this).attr("index"));
					slideImage(thisIndex);
				});
				slideImage(0);
			}
			if(st.effect=="fade"){
				$(this).children("ul").css({position:"relative", height:st.height+"px"})
				.children("li").css({position:"absolute", width:st.width+"px", left:"0px", top:"0px" })
				.eq(0).css({zIndex:1});	
				$("."+st.numStyle).children().click(function(){
					clearTimeout(st.actionTime);
					thisIndex=parseInt($(this).attr("index"));
					fadeImage(thisIndex);
				});
				fadeImage(0);
				$(this).find("li").hover(function(){
					//alert("asdfasdf");
					clearTimeout(st.actionTime);
				},function(){
					st.actionTime=setTimeout(function(){ fadeImage(st.currIndex) },st.interval);
					//alert("asdfasdf");
				});
			}
			function slideImage(index){
				if(index==st.thisObj.find("ul > li").length) st.currIndex=0;
				else st.currIndex=index;
				ulPos=-st.currIndex*st.height+"px";
				st.thisObj.children("ul").stop().animate({top:ulPos},st.speed);
				$("."+st.numStyle).children().eq(st.currIndex).addClass(st.numCurr).siblings().removeClass(st.numCurr);
				st.currIndex++;
				st.actionTime=setTimeout(function(){slideImage(st.currIndex)},st.interval);
			}
			function fadeImage(index){
				if(index==st.thisObj.find("ul > li").length) st.currIndex=0;
				else st.currIndex=index;
				st.thisObj.find("ul > li").eq(st.currIndex).fadeIn(st.speed).siblings().fadeOut(st.speed);
				$("."+st.numStyle).children().eq(st.currIndex).addClass(st.numCurr).siblings().removeClass(st.numCurr);
				st.currIndex++;
				st.actionTime=setTimeout(function(){ fadeImage(st.currIndex) },st.interval);
			}
		}
		
		
		//弹出内容
		$.fn.showContent=function(settings){
			st=$.extend({
				closeStyle:"#close"			
			},settings);	
			st.oTarget=null;
			$($(this).attr("href")).css({display:"none"});
			$(this).click(function(){
				showBg();
				st.oTarget=$(this).attr("href");
				sTop=document.documentElement.clientHeight-$(st.oTarget).height();				
				sTop=sTop/2+document.documentElement.scrollTop;				
				sLeft=($("body").width()-$(st.oTarget).width())/2;				
				$(st.oTarget).css({
					position:"absolute",
					left:sLeft+"px",
					top:sTop+"px",
					zIndex:200
				}).fadeIn();
				return false;
			});
			function showBg(){
				$("body").append("<div id='showBg'></div>");
				$("#showBg").css({
					display:"none",
					position:"absolute",
					top:"0px",
					left:"0px",
					zIndex:1,
					width:$(document).width()+"px",
					height:$(document).height()+"px",
					background:"#000",
					opacity:0.5
				}).fadeIn();
				$("#showBg").click(function(){
					$(this).fadeOut();
					$(st.oTarget).fadeOut();
				});				
			}
			$(st.closeStyle).css({cursor:"pointer"}).click(function(){
					$("#showBg").fadeOut();
					$(st.oTarget).fadeOut();
				});			
		}
		
		
		//弹出图片
		$.fn.showImage=function(settings){
			$(this).click(function(){
				showBg();
				$("body").append('<div id="imgBox"></div>');
				$("#imgBox").css({
					position: "absolute",
					zIndex: 200,
					width: "300px",
					height: "20px",
					left: ($(document).width()-320)/2+"px",
					top: (document.documentElement.clientHeight-40)/2+document.documentElement.scrollTop+"px",
					background: "#000",
					textAlign: "center",
					padding: "10px",
					color: "#ccc",
					display: "none"
				}).append("<span>Loading......</span>").fadeIn();
				var tmpImg=new Image();
				tmpImg.src=$(this).attr("href");
				tmpImg.onload=function(){
					$("#imgBox > span").replaceWith('<img src="'+tmpImg.src+'" id="targetImg" />');
					$("#targetImg").css({ display: "none"	});
					t_width=$("#targetImg").width();
					t_height=$("#targetImg").height();
					t_left=($(document).width()-t_width)/2;
					t_top=(document.documentElement.clientHeight-t_height)/2+document.documentElement.scrollTop;
					$("#imgBox").animate({
						top: t_top+"px",
						left: t_left+"px",
						width: t_width+"px",
						height: t_height+"px"
					},600);
					setTimeout(function(){ $("#imgBox > img").fadeIn(); },800);					
				}
				return false;
			});
			function showBg(){
				$("body").append("<div id='showBg'></div>");
				$("#showBg").css({
					display:"none",
					position:"absolute",
					top:"0px",
					left:"0px",
					zIndex:1,
					width:$(document).width()+"px",
					height:$(document).height()+"px",
					background:"#000",
					opacity:0.4
				}).fadeIn();
				$("body").click(function(){
					$("#showBg,#imgBox").animate({opacity:"hide"},600);
					setTimeout(function(){ $("#showBg,#imgBox").remove() },600);
				});				
			}
		}
		
		
		//导航当前项
		$.fn.currentMenu=function(settings){
			st=$.extend({
				text: "home",
				style: "curr"
			},settings);		
			st.text=st.text.toLowerCase();
			$(this).each(function(n){
				tmpText=$(this).text().toLowerCase();
				if(tmpText==st.text){
					$(this).addClass(st.style);
				}
			});
		}
		
		
		  
})(jQuery);