$(document).ready(function(){
	//中间部分 tab切换,点击事件
	var $selected = "c_left";//设定初始化选定
	var $timer;//初始化定时器
	var $li_click_func = function(){
		//把表头换过来，再把内容换过来
		$selected = changeTab($(this));
	}
	//切换tab函数，返回当前选中的tab名称
	function changeTab(obj){
		$obj = obj;
		var div_id = $obj.children("input").val();
		if(!$obj.hasClass("tab_hover")){
			$tab_hover = $("#tab_container").find(".tab_hover");
			$tab_hover.removeClass("tab_hover");
			$tab_hover.addClass("tab");
			$obj.removeClass("tab");
			$obj.addClass("tab_hover");  
		
			$("#" + div_id).show();
			$("#" + div_id).siblings().hide();
		}
		return div_id;
	}
	//鼠标移上的函数
	$li_mouseover_func = function(){
		//首先判定当前悬停的不是已经选中的
		if(!$(this).hasClass("tab_hover")){
			//鼠标移上时添加一个定时器
			$this_obj = $(this);
			$timer = setTimeout(function(){changeTab($this_obj);},500);
		}
	}
	$li_mouseout_func = function(){
		//首先消除定时器
		clearTimeout($timer);
		//如果selected 不是tab_hover，则让他变过来
		$selected_li = $("#tab_container").find("input[value='"+$selected+"']").parent();
		if(!$selected_li.hasClass("tab_hover")){
			changeTab($selected_li);
		}
	}
	//为所有的tab标签绑定上事件
	$lis = $("#tab_container").find("input");
	$lis.each(function(){
		$input = $(this);
		$li = $input.parent();//因为无法从外部取得这个集合，只能从子元素得到父元素的方法来得到
		//给li委托上事件，
		$li.bind("click",$li_click_func);
		$li.bind("mouseover",$li_mouseover_func);
		$li.bind("mouseout",$li_mouseout_func);	
	});
	/***************************************************/
	
	//头图的定时切换
	$("#moving_container").jCarouselLite({
		btnNext: ".moving_btn1",
		btnPrev: ".moving_btn2",
		visible: 1,
		speed: 4000,
		auto: true,
		mouseWheel: true
	});

	//sidebar 选中的反色
	$cat_name = $.trim($("#cat_name").html());
	$("#nav_ul > li > a").each(function(){
		if($.trim($(this).html()) == $cat_name){
			$(this).addClass("select_list");
		}
	});
	
	
	
})
