/**
 * 首页导航栏切换
 * p_div:父ID层
 * s_div：子id层
 * operate:操作,默认点击
 * is_clear:是否删除父层所有东西
 * state_htm开标签
 * end_htm结束标签
 * 后续补充，添加的位置等
 */
$(function(){
	$("#change_request").click(function(){
		i_type = $(this).attr("data");
		var classhtml=null;
		var urlname=SITEURL.replace(/shop\./, "www.");
		switch (i_type){
			case "1":
				$(this).attr("data","2");
				$(this).attr("title","切换到服务分类");
				$(this).prev("a").attr("href",urlname+"/task/");
				classhtml="所有任务分类";
				tasks_url = urlname+"/index.php?do=ajax&view=home_type&type=task";
				changing_over("changing_over","show_task",'click',0,tasks_url);
				break;
			case "2":
				$(this).attr("data","3");
				$(this).attr("title","切换到人才分类");
				$(this).prev("a").attr("href",urlname+"/fuwu/");
				classhtml="所有服务分类";
				tasks_url = urlname+"/index.php?do=ajax&view=home_type&type=service";
				changing_over("changing_over","show_service",'click',0,tasks_url);
				break;
			case "3":
				$(this).attr("data","1");
				$(this).attr("title","切换到任务分类");
				$(this).prev("a").attr("href",urlname+"/talent/");
				classhtml="所有人才分类";
				tasks_url = urlname+"/index.php?do=ajax&view=home_type&type=talent";
				changing_over("changing_over","show_talent",'click',0,tasks_url);
				break;
		}
		$('.s_tl strong').html(classhtml);
	});
	function changing_over(p_div,s_div,operate,is_clear,url,state_htm,end_htm){
		operate ? operate : operate = 'click';
		is_clear ? is_clear : is_clear = 1;
		if(url == '' || typeof(url) == 'undefined'){
			alert("请填写请求路径");
		}
		if($("#"+s_div).length){
			$("#"+s_div).removeClass('hidden');
			$("#"+s_div).siblings().addClass('hidden');
		}else{
			$.ajax({
				type: "get",
				url: url,
				data: "html",
				success: function(html){
					if(state_htm&&end_htm){
						$(state_htm+html+end_htm).appendTo($('#'+p_div));
					}else{
						$('<ul class="clearfix" id="'+s_div+'">'+html+'</ul>').appendTo($('#'+p_div));
					}
					$("#"+s_div).siblings().addClass('hidden');
				}
			}); 
		}
	}
});