/*-------------------------------------------------------
* 说明：基于jQuery编写
* 作者：Gavin
* 创建时间：2008-10-27
* 最后一次修改时间：2009-03-04 
-------------------------------------------------------*/
function initMenu(treeDiv) {
	$(treeDiv + ' ul ul').hide();
	$(treeDiv + ' li a').click(function() {
		var clickElement=$(this);
		var checkElement = $(this).next();
		if(checkElement.is('ul') && (checkElement.is(':has("li")'))){
			if(checkElement.is(':visible')) {
				checkElement.slideUp('normal');
				return false;
			}
			if(!checkElement.is(':visible')) {
				checkElement.parent().parent().find("ul:visible").slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
    });
}

$(document).ready(function(){
						   
	//消除链接虚线框
	$("a").bind("focus",function(){
    	if(this.blur){ //如果支持 this.blur
        	this.blur();
        }
    });
	
	// 初始化侧栏菜单
	initMenu("#subNav");
	
	//高亮当前二级栏目
	$("#subNav .current, #menubar .current").parents("ul").show();
	$("#menubar .current").parents("ul").show();

    //弹出客服离线
	$("#btnClose").bind("click",function(){
	    $(this).parent().remove();
    });
	
	var menuYloc = $("#popup").offset().top;
	$(window).scroll(function (){
	var offsetTop = menuYloc + $(window).scrollTop() +"px";
	$("#popup").animate(
		{top : offsetTop },
		{ duration:600 , queue:false }
		);
	});
	
	//表单label自适应宽度
	var max = 0;  
	$("label").each(function(){  
		if ($(this).width() > max) max = $(this).width();  
	});  
	$("label").width(max);
	
	//文本框高亮
	$('input[type="text"], input[type="password"], textarea').each(function(){
		$(this).addClass("idleField");
		$(this).focus(function() {
			$(this).removeClass("idleField").addClass("focusField");
			if (this.value == this.defaultValue){ 
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		$(this).blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});	  
	});
	
	//斑马线表格
	//$(".thinLineTable tr:even").addClass("even");
	$("#toolbarHandler, .toolbar").bind("mouseover",function(){
			$("#toolsList").show();
		}).bind("mouseout",function(){
			$("#toolsList").hide();
		});
	
	//tabs
	var index=0;
	$("#news .tabContent:first, #faq .tabContent:first").show();
	$("#news .tabContent li:last").addClass("lastItem");
	$(".tabs li").mouseenter(function(){
		$tabsLi=$(this).parent().find("li");
		index=$tabsLi.index($(this));
		//alert(index);
		$tabsLi.removeClass("active");
		$tabsLi.filter(":eq("+index+")").addClass("active");
		$(this).parent().siblings().hide();
		$(this).parent().siblings().filter(":eq("+index+")").show();
	});
	
	$("#btnMenu").toggle(
		function(){
			$("#menubar").css("left","-177px");	
		},
		function(){
			$("#menubar").css("left","0");
		}
	);
	
});