﻿jQuery(function($){
	$("#IndexTitleTop").find("#linktitle").each(function(){
		$(this).hover(function(){
			var obj=$(this);
			var tt = $(this).attr("rel");
			$("#IndexTitleTop").find("#linktitle").each(function(){
				$(this).removeClass("Current");												 
			});
			if(tt==1)
			{
				$("#linktitleshow1").show();
				$("#linktitleshow2").hide();
			}
			else{
				$("#linktitleshow2").show();
				$("#linktitleshow1").hide();
			}
			$("#MoreNews").attr("href",obj.attr("href"))
			obj.addClass("Current");
		});
	});
	
	if($("#shopxingyongcomentform").length>0)
	{
		$.formValidator.initConfig({formid:"shopxingyongcomentform",errorfocus:false,onerror:function(msg){},onsuccess:function(){
				var CommentName = $.trim($("#txtCommentName").val());							   
				var CommentTel = $.trim($("#txtCommentTel").val());
				var CommentAddress = $.trim($("#txtCommentAddress").val());
				var CommentContent = $.trim($("#AntUserContent").val());	
				var CommentOther = $.trim($("#txtCommentOther").val());	
				var CompanyID = $.trim($("#CompanyHidden").val());	
				$("#txtbutton").attr("disabled", true);
				var curl="/public/ajax.aspx?action=addcompanycomment";
				curl +="&CommentName="+escape(CommentName);
				curl +="&CommentTel="+escape(CommentTel);
				curl +="&CommentAddress="+escape(CommentAddress);
				curl +="&CommentContent="+escape(CommentContent);
				curl +="&CommentOther="+escape(CommentOther);
				curl +="&CompanyID="+escape(CompanyID);
				$.ajax({
					  url: curl,
					  cache: false,
					  success:function(data)
					  {
						  curl = window.location.href;
						  if( curl.indexOf("#")!= -1 )
							curl = curl.substring(0,curl.indexOf("#"));
						  if(data=="0")
						  {	
							 alert("留言成功，我们会尽快与您取得联系！");
							 window.location.href=curl;
						  }
						  else if(data=="1")
						  {	
							 alert("留言成功，我们会尽快与您取得联系！");//SUCCESS
							 window.location.href=curl;
						  }
						  else{
							  alert(data);
							  $("#txtbutton").attr("disabled", false);
						  }
					  }
				});	
				return false;																										   
		}});
		$.formValidator.getInitConfig("1").wideword = true;
		$("#txtCommentName").formValidator({onshow:"请填写您的姓名，方便我们与您快速联系。",onfocus:"请填写您的姓名，方便我们与您快速联系。",oncorrect:"&nbsp;"}).inputValidator({min:2,max:60,onerror: "您的姓名填写不正确，长度在2-60个字符之间。"})
		$("#txtCommentTel").formValidator({onshow:"请输入您的联系电话，您填写的电话是保密的。",onfocus:"请输入您的联系电话，您填写的电话是保密的。",oncorrect:"&nbsp;"}).inputValidator({min:7,max:30,onerror: "请输入您的联系电话，您填写的电话是保密的。"})
		$("#txtCommentAddress").formValidator({onshow:"请输入您的联系地址。",onfocus:"请输入您的联系地址。",oncorrect:"&nbsp;"}).inputValidator({min:0,max:60,onerror: "您的联系地址，长度在60个字符之间。"})
		$("#txtCommentOther").formValidator({onshow:"请输入您的电子邮件。",onfocus:"请输入您的电子邮件，没有可不填写。",oncorrect:"&nbsp;"}).inputValidator({min:0,max:60,onerror: "请输入您的电子邮件，没有可不填写。"})
		$("#AntUserContent").formValidator({onshow:"请输入您的留言内容。",onfocus:"请输入您的留言内容。",oncorrect:"&nbsp;"}).inputValidator({min:0,max:500,onerror: "请输入您的留言内容，五百字以内。"})
	}
	if($("#mapContainer").length>0)
	{
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("mapContainer"));
			if(addrs.length>0)
			{
				map.setCenter(new GLatLng(addrs[0].latitude, addrs[0].longitude), 11);
			}
			else{
				map.setCenter(new GLatLng(mapx,mapy), 11);
			}
			map.addControl(new GSmallMapControl());
			map.enableScrollWheelZoom();
			var bounds = new GLatLngBounds(); 
			var markers = [], point;
			for (var i = 0, len = addrs.length; i < len; i++) {
				point = new GLatLng(addrs[i].latitude, addrs[i].longitude);
				var markerOptions = { icon:createMarker(i) };// 设置 GMarkerOptions 对象
				markers[i] = new GMarker(point,markerOptions);
				map.addOverlay(markers[i]);
				var str='<div style="padding:0 10px; width:300px;line-height:25px;text-align:left;">' + addrs[i].address + '<br />电话：' + addrs[i].phone;
				if(addrs[i].fax.replace("  ","").length>0)
					str+='<br />传真：' + addrs[i].fax ;
				if(addrs[i].traffic.replace("  ","").length>0)
					str+='<br />交通指南：' + addrs[i].traffic ;
				str +=  '</div>';
				markers[i].bindInfoWindowHtml(str);
				(function(i){
					GEvent.addListener(markers[i],'click',function(p){
						map.setZoom(14);
						map.panTo(p);
					})
				})(i)
				bounds.extend(point);
			}
		}	
	}
});
function createMarker(index){
	var letter = String.fromCharCode("A".charCodeAt(0)+index);
	var letteredIcon = new GIcon(G_DEFAULT_ICON);
	letteredIcon.image="http://www.google.com/mapfiles/marker"+letter+".png";
	return letteredIcon
}
function dk_slideplayerCompany(object,config){
	this.obj = object;
	this.config = config ? config : {width:"300px",height:"240px",fontsize:"12px",right:"10px",bottom:"10px",time:"5000"};
	this.pause = false;
	var _this = this;
	if(!this.config.right){
		this.config.right = "0px"
	}
	if(!this.config.bottom){
		this.config.bottom = "3px"
	}
	if(this.config.fontsize == "12px" || !this.config.fontsize){
		this.size = "12px";
		this.height = "21px";
		this.right = "6px";
		this.bottom = "10px";
	}else if(this.config.fontsize == "14px"){
		this.size = "14px";
		this.height = "23px";
		this.right = "6px";
		this.bottom = "15px";
	}
	this.count = jQuery(this.obj + " li").size();
	this.n =0;
	this.j =0;
	var t;
	this.factory = function(){
		jQuery(this.obj).css({position:"relative",zIndex:"0",margin:"0",padding:"0",width:this.config.width,height:this.config.height,overflow:"hidden"})
		jQuery(this.obj).prepend("<div style='position:absolute;z-index:20;right:"+this.config.right+";bottom:"+this.config.bottom+"'></div>");
		jQuery(this.obj + " li").css({width:"100%",height:"100%",overflow:"hidden"}).each(function(i){jQuery(_this.obj + " div").append("<a>"+(i+1)+"</a>")});

		jQuery(this.obj + " img").css({border:"none",width:"100%",height:"100%"})

		this.resetclass(this.obj + " div a",0);

		jQuery(this.obj + " p").each(function(i){			
			jQuery(this).parent().append(jQuery(this).clone(true));
			jQuery(this).html("");
			jQuery(this).css({position:"absolute",margin:"0",padding:"0",zIndex:"1",bottom:"0",left:"0",height:_this.height,width:"100%",background:"#000",opacity:"0.4",overflow:"hidden"})
			jQuery(this).next().css({position:"absolute",margin:"0",padding:"0",zIndex:"2",bottom:"0",left:"0",height:_this.height,lineHeight:_this.height,textIndent:"5px",width:"100%",textDecoration:"none",fontSize:_this.size,color:"#FFFFFF",background:"none",zIndex:"1",opacity:"1",overflow:"hidden"})
			if(i!= 0){jQuery(this).hide().next().hide()}
		});

		this.slide();
		this.addhover();
		t = setInterval(this.autoplay,this.config.time);
	}
	
	this.slide = function(){
		jQuery(this.obj + " div a").mouseover(function(){
			_this.j = jQuery(this).text() - 1;
			_this.n = _this.j;
			if (_this.j >= _this.count){return;}
			jQuery(_this.obj + " li").hide();
			jQuery(_this.obj + " p").hide();
			jQuery(_this.obj + " li").eq(_this.j).fadeIn("slow");
			jQuery(_this.obj + " li").eq(_this.j).find("p").show();
			_this.resetclass(_this.obj + " div a",_this.j);
		});
	}

	this.addhover = function(){
		jQuery(this.obj).hover(function(){clearInterval(t);}, function(){t = setInterval(_this.autoplay,_this.config.time)});
	}
	
	this.autoplay = function(){
		_this.n = _this.n >= (_this.count - 1) ? 0 : ++_this.n;
		jQuery(_this.obj + " div a").eq(_this.n).triggerHandler('mouseover');
	}
	
	this.resetclass =function(obj,i){
		jQuery(obj).css({float:"left",marginRight:"3px",width:"15px",height:"14px",lineHeight:"15px",textAlign:"center",fontSize:"12px",color:"#FFFFFF",background:"#323232",cursor:"pointer"});
		jQuery(obj).eq(i).css({color:"#FFFFFF",background:"#ff9815",textDecoration:"none"});
	}

	this.factory();
}
function LoadCompanyVideo(id){
	var curl="ShowComVideo.aspx?id="+id;
	$.ajax({
		  url: curl,
		  cache: false,
		  success:function(data)
		  {
			  $("#AntNewVideo").html(data);
		  }
	});		
}
function LoadCompanyQuan(id){
	var curl="ShowComQuan.aspx?id="+id;
	$.ajax({
		  url: curl,
		  cache: false,
		  success:function(data)
		  {
			  $("#ContentList360").html(data);
		  }
	});		
}


(function(){
	  var CommonTab = function(seting){
		  return new CommonTab.fn.init(seting);
	  };
	  CommonTab.prototype =CommonTab.fn =  {
		  indexId:0,
		  Totallpage:1,
		  pageWidth:0,
		  Timer:0,
		  currIndex:0,
		  $:function(v){
			  return document.getElementById(v);
		  },
		  $$:function(o,e){
			  return this.$(o).getElementsByTagName(e);
		  },
		  getStyle:function(el,style) {
			  if (!+"\v1") {
				  style = style.replace(/\-(\w)/g,
				  function(all, letter) {
					  return letter.toUpperCase()
				  });
				  var value = el.currentStyle[style]; (value == "auto") && (value = "0px");
				  return value
			  } else {
				  return document.defaultView.getComputedStyle(el, null).getPropertyValue(style)
			  }
		  },
		  preWidth:function(seting){
			  var id=seting.id,eg=seting.eg;
			  var MarginLeft = parseInt(this.getStyle(this.$$(id,eg)[0],"margin-left"),10),MarginRight = parseInt(this.getStyle(this.$$(id,eg)[0],"margin-right"),10);				
			  this.Totallpage = Math.ceil(this.$$(id,eg).length/seting.pageNb);//总页数
			  if(this.Totallpage>1){//分页数大于1页开始操作
			  this.$(id).style.width = (this.$$(id,eg)[0].offsetWidth+MarginLeft+MarginRight) * this.$$(id,eg).length + "px";	
			  this.$(id).parentNode.style.position = "relative";
			  this.$(id).style.position = "absolute";
			  this.$(id).style.left = 0 +"px";
			  }	
			  this.pageWidth = (parseInt(this.$$(id,eg)[0].offsetWidth) + 2) * seting.pageNb;//1屏宽度
		  },
		  move:function(seting,n,sta){
			  var _this = this,id=seting.id,eg=seting.eg;
			  var MarginLeft = parseInt(this.getStyle(this.$$(id,eg)[0],"margin-left"),10),MarginRight = parseInt(this.getStyle(this.$$(id,eg)[0],"margin-right"),10),MovePix;
			  if(this.pageWidth % seting.MovePix !== 0) {
				  var deflagNums = this.pageWidth % (Math.floor(seting.MovePix / 2));
				  MovePix = Math.floor(seting.MovePix / 2);
			  }else{
				  MovePix = seting.MovePix;
			  }
			  _this.Timer =setInterval(function(){
				  if(sta=="right"){
					  _this.currIndex+=MovePix;
					  if(Math.abs(parseInt(_this.$(seting.id).style.left))<Math.abs(-(_this.pageWidth*n))){
						  _this.$(seting.id).style.left = -_this.currIndex+"px";
						  _this.$(seting.right).onclick = function(){return false};
					  }else{
						  clearInterval(_this.Timer);
						  _this.Timer = 0;
						  CommonTab.fn.handRight(seting);
						  if(_this.indexId==_this.Totallpage-1){
						  _this.$(seting.right).className=seting.classNameOFF;
						  _this.$(seting.left).className=seting.classNameON;
						  }
						  if(_this.indexId<_this.Totallpage-1){
						  _this.$(seting.right).className=seting.classNameON;
						  _this.$(seting.left).className=seting.classNameON;
						  }
					  }
				  }else{
					  _this.currIndex-=MovePix;
					  if(Math.abs(parseInt(_this.$(seting.id).style.left))>Math.abs(-(_this.pageWidth*n))){
						  _this.$(seting.id).style.left = -_this.currIndex+"px";
						  _this.$(seting.left).onclick = function(){return false};
					  }else{
						  clearInterval(_this.Timer);
						  _this.Timer = 0;
						  CommonTab.fn.handLeft(seting);
						  if(_this.indexId==0){
						  _this.$(seting.left).className=seting.classNameOFF;
						  _this.$(seting.right).className=seting.classNameON;
						  }
						  if(_this.indexId>0){
						  _this.$(seting.left).className=seting.classNameON;
						  _this.$(seting.right).className=seting.classNameON;
						  }
					  }
				  }
				 
			  },1)
		  },
		  handLeft:function(seting){
			  var id = seting.left,_this = this;
			  this.$(id).onclick = function(){
				  if(_this.indexId>0){
				  _this.indexId--;
				  _this.move(seting,_this.indexId,"left");
				  }
			  }
		  },
		  handRight:function(seting){

			  var id = seting.right,_this = this;
			  this.$(id).onclick = function(){
				  if(_this.indexId<_this.Totallpage-1){
				  _this.indexId++;
				  _this.move(seting,_this.indexId,"right");
				  }
			  }
		  },
		  init:function(seting){
			  CommonTab.fn.preWidth(seting);
			  CommonTab.fn.handLeft(seting);
			  CommonTab.fn.handRight(seting);
		  }
	  }

	  window.CommonTab = CommonTab;
  })()
