$(document).ready(function(){
	//业务查询切换
	ywcxChange();
	//网上咨询
	wszxChange();
	rollUp("jfgg-con",137,1,100);
	topChange();
	xxgkChange1();
	xxgkChange2();
	bottomChange();

	consultSet();
	
	if($("#isHasVideo").val() == "1"){
		videoSet($("#videoContent").val(),$("#videoHPImg").val(),"video-container","false","258","182");
	}
});

function videoSet(content,hpImg,container,autoStart,width,height){
	var temp = document.createElement("div");
	$(temp).html(content);
	var embed = $(temp).find("EMBED").eq(0);
	var file = embed.attr("flashvars");
	var videoFile = file.substring(5,file.length);
	
	var s5 = new SWFObject("js/video-player/flvplayer.swf","single",width,height,"7");
	s5.addParam("allowfullscreen","true");
	s5.addVariable("autostart",autoStart);
	s5.addVariable("image",hpImg);
	s5.addVariable("file",videoFile);
	s5.addVariable("width",width);
	s5.addVariable("height",height);
	s5.write(container);
}

/**
 * @author 关辉鹏 2010-05-21
 * @see 填充网上咨询
 * @return
 */
function consultSet(){
	setXmlCsUrl("web/consultList.jsp");
	var consultArray = getConsultArray(5);
	var container = $("#wszx #wszx-con");
	if(consultArray[0] != 0){
		var temp = "<ul>";
		$(consultArray).each(function(i){
			temp += "<li><img src='images/005.jpg' /><span class='text'>";
			temp += "<a title='"+htmlToJs(consultArray[i].title)+"' href='"+consultArray[i].getUrl()+"' target='_blank'>";
			temp += subTitle(getConsultType(consultArray[i].type)+htmlToJs(consultArray[i].title),15)+"</a>";
			temp += "</span><span class='date'>";
			temp += consultArray[i].date.substring(0,10)+"</span></li>";
		});
		temp += "</ul>";
		container.html(temp);
	}else{
		container.html("<div class='tip'>暂无相关文章</div>");
	}
}

function getConsultType(id){
	var temp = "";
	if(id == 0){
		temp = "治安";
	}else if(id == 1){
		temp = "交通";
	}else if(id == 2){
		temp = "消防";
	}else if(id == 3){
		temp = "出入境";
	}else if(id == 4){
		temp = "法制";
	}else if(id == 5){
		temp = "户政管理";
	}else if(id == 6){
		temp = "网络信息安全";
	}else{
		temp = "其它";
	}
	return "【"+temp+"】";
}

/**
 * @author 关辉鹏 2010-05-11
 * @see 截取标题
 * @param str
 * @param subLength
 * @return
 */
function subTitle(str,subLength){
	if(str != null && str != ""){
		if(str.length > subLength){
			str = str.substring(0,subLength)+"...";
		}
	}
	return str;
}

function htmlToJs(str){
	str = str.replace(/\&nbsp\;/g, "\t"); 
    return str; 
}

function topChange(){
	$("#gayw #title li").mouseover(function(){
		resetLi($(this),"images-new/gonganyaowen2.jpg");
		var id = $(this).attr("id");
		$("#head-part #center .top").hide();
		$("#head-part #center .col-con").hide();
		$("#head-part #center #"+id+"1").show();
		$("#head-part #center #"+id+"2").show();
	});
}

function xxgkChange1(){
	$("#jgzn #title li").mouseover(function(){
		$(this).parent().children().css({background:"none"});
		$(this).css({background:"url(images/images-new/xinxi_25.jpg)"});
		
		var id = $(this).attr("class");
		$("#jgzn .col-con").hide();
		$("#jgzn #"+id+"3").show();
	});
}

function xxgkChange2(){
	$("#rsxx #title li[class!=change8]").mouseover(function(){
		$(this).parent().children().css({background:"none"});
		$(this).css({background:"url(images/images-new/xinxi_25.jpg)"});
		
		var id = $(this).attr("class");
		$("#rsxx .col-con").hide();
		$("#rsxx #"+id+"4").show();
	});
}

function wszxChange(){
	$("#wszx #change li").mouseover(function(){
		resetLi($(this),"images-new/hudong_17.jpg");
	});
	$("#wszx #change li").mouseout(function(){
		$(this).css({background:"none","font-weight":"normal"});
	});
}

function bottomChange(){
	$("#center-bottom #title li").mouseover(function(){
		resetLi($(this),"images-new/hudong_17.jpg");
		var id = $(this).attr("id");
		
		$("#center-bottom .cb-con").hide();
		$("#center-bottom #"+id+"1").show();
	});
}

function setSlide(obj,width,height,txtHeight,txtLength){
	var focus_width = width;
	 var focus_height = height;
	 var text_height = txtHeight;
	 var swf_height = focus_height + text_height;
	 
	 var texts = "";
	 var objArray = obj.split(",");
	 var temp = objArray[2].split("|");
	 for(var i = 0;i < temp.length;i++){
		 if(temp[i].length > txtLength){
			 texts += temp[i].substring(0,txtLength)+"...|";
		 }else{
			 texts += temp[i]+"|";
		 }
	 }
	 
	 texts = texts.substring(0, texts.length-1);
	 var pics = objArray[0];
	 var links = objArray[1];

	 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
	 document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="images/pic/focus.swf"> <param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">');
	 document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	 document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
	 document.write('<embed src="images/pic/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" ?bgcolor="#ffffff" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	 document.write('</object>');
}

function crjjdcxCheck(){
	var no = $("#crjjdcx input[type='text']").val();
	if($.trim(no) == ""){
		alert("请输入受理编号或身份证号码！");
		return false;
	}
	return true;
}

function jtwfcxCheck(){
	var errors = "";
	var no = $("#jtwacx input[type='text']").val();
	if($.trim(no) == ""){
		errors += "请输入车牌号！\n";
	}
	if($("#jtwacx select").val() == ""){
		errors += "请选择车牌类型！\n";
	}
	if(errors != ""){
		alert(errors);
		return false;
	}
	return true;
}

function toConsult(){
	var v =document.getElementById("cj").value;
	v = v.replace(/\s/g, "");
	if(v==""){
		alert("请输入查询ID");
	}else if(v.length!=20){
		alert("查询ID格式不正确，请检查！");
	}else{
		document.getElementById("cj").value = "";
		window.open("consult.jsp?url=web/InfoConsult.do?id="+v,"consult", "", "");
	}
}

/**
 * @author 关辉鹏 2010-05-21
 * @see 搜索验证
 * @return
 */
function searchCheck(){
	if($.trim($("#searchValue").val()) == ""){
		alert("请输入查询关键字！");
		return false;
	}
	return true;
}

/**
 * @author 关辉鹏 2010-05-20
 * @see 交警业务查询切换
 * @param type
 * @return
 */
function jjywcxChange(type){
	$("#jjywcx-right #top table").hide();
	if(type == 1){
		$("#jjywcx-right #top #jtwacx").show();
	}else if(type == 2){
		$("#jjywcx-right #top #hzcx").show();
	}else{
		$("#jjywcx-right #top #cjcx").show();
	}
}

/**
 * @author 关辉鹏 2010-05-17
 * @see 业务查询切换
 * @return
 */
function ywcxChange(){
	$("#ywcx #change li").mouseover(function(){
		resetLi($(this),"images-new/wangfu019.jpg");
		var id = $(this).attr('id');
		if("change1" == id){
			$("#ywcx #crjjdcx,#sfzbljdcx").hide();
			$("#ywcx #jjywcx").show();
		}else if("change2" == id){
			$("#ywcx #jjywcx,#sfzbljdcx").hide();
			$("#ywcx #crjjdcx").show();
		}else{
			$("#ywcx #jjywcx,#crjjdcx").hide();
			$("#ywcx #sfzbljdcx").show();
		}
	});
}

function resetLi(obj,bg){
	obj.parent().children().css({background:"none","font-weight":"normal"});
	obj.css({background:"url(images/"+bg+")","font-weight":"bold"});
}
