//By 二级联动 选择框美化版
jQuery.fn.extend({
  zhubajie_select: function() {
	  var d=this;
	  var ced=false;
	  var f=d.find("select");
	  f.hide();
	  d.append('<div class="dropselectbox" style="display: block;"><h4 class="" style="width: '+f.width()+'px;">'+f.val()+'</h4><span class="FixSelectBrowserSpan"/><ul style="display: none; width: '+d.find("h4").width()+'px;z-index:10;"/></div>');
	  d.find("h4").hover(function(){$(this).addClass("over");},function(){$(this).removeClass("over");});
	  d.blur(function(){d.find("li").remove();d.find("ul").hide();ced=false;});
	  //开始写入列表
	  d.find("div").click(function(){
		  if(ced){
			d.find("li").remove();
			d.find("ul").hide();
			ced=false;
		  }else{
			  d.find("li").remove();
			  d.find("ul").show();
			  
			  d.find("h4").toggleClass("current");
			  //d.find("span").toggleClass("over");
			  
			  f.find("option").each(function(){
					d.find("ul").append("<li>"+$(this).text()+"</li>");
				}); 
			  //定义ul宽度
			  d.find('ul').css('width',d.find('h4').width());
			  d.find("ul li").each(function(){
				if($(this).text()==d.find("h4").text())$(this).addClass("over");
			  });
				//定义滑动
				d.find('ul li').hover(function(){d.find('ul li').removeClass("over");$(this).addClass("over");},function(){$(this).removeClass("over");});
				d.find('ul li').click(function(){
					var val=$(this).text();
					d.find('h4').html(val);f.val(val);
					
					if(d.attr('id')=='zhubajie_type'){
						$("#zhubajie_cat select option").each(function(){
							try{
								$("#zhubajie_cat select")[0].options.remove(0);
							}catch(e){
								$(this).remove();
							}
						});
						if(val=='人才'){
							try{
								$("#zhubajie_cat select")[0].add(new Option('技能'));
								$("#zhubajie_cat select")[0].add(new Option('会员名'));
							}catch(e){
								$("#zhubajie_cat select").append('<option>技能</option><option>会员名</option>');
							}
						}else if(val=='任务'){
							try{
								$("#zhubajie_cat select")[0].add(new Option('标题'));
								$("#zhubajie_cat select")[0].add(new Option('任务号'));
								$("#zhubajie_cat select")[0].add(new Option('发布者'));
							}catch(e){
								$("#zhubajie_cat select").append('<option>标题</option><option>任务号</option><option>发布者</option>');
							}
						}
						$("#zhubajie_cat h4").html($("#zhubajie_cat select").val());
					}
				}); //改变选值
				//处理联动
				ced=true;
			}
	  });
	  },
	 zhubajie_topmenu: function() {
		 var d=this;
		 var d_=$(".tabcon");
		 var did=this.attr("id");
		 var thisli=d.find(".currently");//找到当前状态li
		 var thislid=thisli.attr('id');//找到当前状态li
		 d.find(".topmenu_over").hover(function(){
				 //当前状态
				 var thisid=$(this).attr("id");
				 var thisid_=$("#"+thisid+"_");
				 if(thislid!=thisid)$(this).addClass("currently");
				 d_.find("ul").hide();
				 //d_.find("ul").hide('show');
				 //thisid_.show('show');
				 thisid_.fadeIn('show');
				 },function(){
				 //失去状态
				 var thisid=$(this).attr("id");
				 var thisid_=$("#"+thisid+"_");
				 if(thislid!=thisid)$(this).removeClass("currently");
				 //d_.find("ul").hide();
				 //thisid_.show();
				 });
	   }

});
