﻿$(document).ready(function(){
	maqueeMsg();
	seachsub();
	showWindows();
	jumpFace();
	guestsubmit();
	getNews();
});

function seachsub(){
	$("#seachtxt").click(function(){
		if($("#seachtxt").val().length==0||$("#seachtxt").val()=="站内搜索")
		{
		 $(this).val("");
		 $("#seachtxt").css({ color: "#000"});
		}
	});
	$("#seachtxt").keydown(function(){
			if(event.keyCode==13){$("#seachbtn").focus();}
	});
	$("#seachbtn").click(function(){
		if($("#seachtxt").val().length==0||$("#seachtxt").val()=="站内搜索")
		{
			alertMsg("","请输入搜索关键字!");
			return;
		}else{
			window.location.href= "/ProjectSearch/1-1-" + $.trim($("#seachtxt").val()) + ".html";
		}
	});
}

function showWindows(){
	//var lock = false;
	$(".open").hover(function(){},function(){});
	var btn={
		closeit : function(){
			$("div").remove("#newwindow");
			$("div").remove("#newbg");
		},
	    photolist : function(){
		        $("#ar").click(function(){
					$("#imgcontent>div").animate({marginLeft:'-177px'},300,'',function(){
								$("#imgcontent>div").find("img:first").appendTo($("#imgcontent>div"));
								$("#imgcontent>div").css("marginLeft",0);
					});
				});
				 $("#al").click(function(){
					$("#imgcontent>div").animate({marginLeft:'177px'},300,'',function(){
								$("#imgcontent>div").find("img:last").prependTo($("#imgcontent>div"));
								$("#imgcontent>div").css("marginLeft",0);
					});
				});
		},
		onclickImg : function(e){
			$("#imgcontent>div>img").click(function(){
					var src = $(this).attr("src").substring(0,$(this).attr("src").lastIndexOf("/")+1);
					var img = $(this).attr("src").substr($(this).attr("src").lastIndexOf("/")+1).replace("s","");
					if(e==0){
						$("#newwindow>.datas>.imgs").attr("src",src+img);
					}else if(e==1){
						$(".datas>.imgs").attr("src",src + img);
					}
					
				});
		},
		getID : function(a){
			var aStr = a.substr(a.lastIndexOf("/")+1).split(".");
			var _ID = aStr[0];
			return _ID
		},
		openit : function(id){
		   //if(lock==true)return;
		   if(locked==true)return;
		  $("body").prepend('<div id="newbg"></div>');
		  var h =Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
          $("#newbg").css({height:h});
		 $("body").prepend('<div id="newwindow"><input id="closeit" type="button" /><div class="datas"><img class="imgs" /><div id="imglist"><span id="al"></span><div id="imgcontent"><div></div></div><span id="ar"></span></div><h2><a  target="_blank"  href=""></a></h2><span class="time"></span><div class="info"></div></div></div>');
		  var _top =parseFloat(-25+document.documentElement.scrollTop+document.documentElement.clientHeight/2) + "px";
		  $("#newwindow").css({top:_top});
		  $.ajax({
			  type:"get", 
			  dataType:"json",
			  url:"/opear/system.aspx",
			  data:"guid=" + btn.getID(id),
			  success:function(msg){
				  var data =msg.JsonData;
				  $("#newwindow").find(".imgs").attr("src",data[0].PictureUrl+data[0].Picture);
				  $("#newwindow").find(".imgs").attr("alt",msg.Title);
				  $("#newwindow").find("h2>a").text(msg.Title);
				  $("#newwindow").find("h2>a").attr("href",msg.LinkUrl);
				  $("#newwindow").find(".time").text(msg.DevDate);
				  $("#newwindow").find(".info").html(msg.Content);
				  for(i=0;i<msg.total;i++){
							$("<img />").attr("src",data[i].PictureUrl+data[i].Picture.replace(".","s.")).appendTo("#imgcontent>div");
							
				  }
				  btn.onclickImg(0);
			  }
			});
		  //lock = true;
		  locked = true;
		  $("#newwindow").fadeIn(500);
		  //$("#newwindow").draggable();
		  btn.photolist();
		  $("#closeit").click(function(){btn.closeit();locked=false;});//lock=false;}); 
		}
	}
	$(".open").click(function(){ btn.openit($(this).attr("rel"))});
	$("#default").find(".imgs").click(function(){btn.openit($(this).next("h2").find("a").attr("href"))});
	$("#product").find(".imgs").click(function(){btn.openit($(this).next("h2").find("a").attr("href"))});
	if($("#product")){
		btn.onclickImg(1);
		btn.photolist();
	};
}
var faceapp ="whynot1.gif";
function jumpFace(){
	var lock = false;
	var gbtns={
		     closeface : function(){
			      $("div").remove("#facetig");
				  lock = false;
				  $("#faceinfo").removeClass("index");
		      },
			  facebind : function(){
				  $("#facetig>img").click(function(){
						$("#faceimg").attr("src",$(this).attr("src"));
						faceapp = $(this).attr("src");
						gbtns.closeface();
				  });
			  }
	};

	$("#faceinfo").click(function(){
		var tag_html="";	
		if(lock == true)return;
		$(this).toggleClass("index");
		$(this).find("option").each(function(){ 
				tag_html+='<img  src="../Images/face/'+$(this).text()+ '.gif" />';
		});
		$("#retxt>.l").append('<div id="facetig" ><input id="closeit" type="button" />'+ tag_html+'</div>');	
		$("#facetig>#closeit").click(function(){gbtns.closeface()});
		lock = true ;
		gbtns.facebind();
		$("#facetig").fadeIn(500);
		
	});
}

var locked = false;
function alertMsg(){
	var btn={
		closeit : function(){
			$("div").remove("#altmsg");
			locked = false;
		}
	};
	if(locked==true)return;
		locked = true;
		$("body").prepend('<div id="altmsg"><h1>提示</h1><input id="closeit" type="button" /><span class="'+ arguments[0] +'">'+ arguments[1] +'</span><input id="opear" value="确 定" type="button" /></div>');
		var _top = document.documentElement.scrollTop+document.documentElement.clientHeight/2+ "px";
		$("#altmsg").css({marginTop:_top});
		$("#opear").focus();
		$("#altmsg").draggable();
		$("#closeit").click(function(){btn.closeit()});
		if(arguments.length<3)
		{
			$("#opear").click(function(){btn.closeit()});
		}else{
			var url = arguments[2];
			$("#opear").click(function(){btn.closeit();window.location.href= url});
		};
}

//消息滚动
function maqueeMsg(){
	var turnData=function(){
		$("#news").animate({marginTop:'-30px'},500,'',function(){
				$("#news").find("li:lt(1)").appendTo($("#news"));
				$("#news").css("marginTop",0);
				});
		};
	window.setInterval(turnData,3000);
	$("#banner").append('<div id="h_nav"></div>');
	var so = new SWFObject("/Flash/flashmenu.swf", "sotester", "960px", "235px", "0", "");
	    so.addParam("wmode", "transparent");
		so.write("h_nav");
	    
}

function guestsubmit(){
	var check_submit = function () {
		if($("#NickName").val()=="")
		{
			alertMsg("","请填写用户名!");
			return false;
		}else if($("#Message").val()=="")
		{
			alertMsg("","请填写留言内容!");
			 return false;
		}else{
			return true;
		};
	};
	$("#gbook_post").click(function(){	
		if(check_submit()==true){
			var _face = faceapp.substr(faceapp.lastIndexOf("/")+1);
			var _name = $("#NickName").val();
			var _qq = $("#QQ").val();
			var _message = $("#Message").val();
               $.get("../opear/FeedBack.aspx",{face:_face,name:_name,qq:_qq,message:_message},function(){alertMsg("","提交成功,请等待管理员审核!","../FeedBack");});
		}
	});
}

function getNews(){
	$("#sildown").click(function(){
		  $("#onliservice").slideDown(50);		  
	  });
	  $("#closeit").click(function(){$("#onliservice").hide(20)});
}
