function bodyId(){
return document.getElementsByTagName("body")[0].getAttribute("id");	
}

function introInfo(divId,ulId){
	var Id = bodyId();
	if(Id == "home"){
		var wra = document.getElementById(divId);
		var ul = document.getElementById(ulId);
		var li = new Array();
		
		try{
		for(i=0; i<ul.childNodes.length; i++){
		if(ul.childNodes[i].tagName == "LI"){
				li.push(ul.childNodes[i]);
			}
		}
		
		li[0].getElementsByTagName("a")[0].className = "on";
		var div = new Array();
		for(i=0; i<wra.childNodes.length; i++){
			if(wra.childNodes[i].className == "infoCon"){
				wra.childNodes[i].style.display = "none";
				div.push(wra.childNodes[i]);
			}
		}
		div[0].style.display = "block";
		
		for(i=0; i<li.length; i++){
			li[i]._i = i;
			li[i].onmouseover = function(){
				for(j=0; j<li.length; j++){
					li[j].getElementsByTagName("a")[0].className = "";
					div[j].style.display = "none";
				}
				this.getElementsByTagName("a")[0].className = "on";
				div[this._i].style.display = "block";
			}
		}
		}catch(e){}
	
	}
}
function getElementsByClassName(tagname,classname){
var _arr = new Array;
var _a = document.getElementsByTagName(tagname);
for(i=0; i<_a.length; i++){
	if(_a[i].className == classname){
		_arr.push(_a[i]);
	}
}
return _arr;
}




function conTabs(){
	if(document.getElementById("tabs")){
		var tabs = document.getElementById("tabs").getElementsByTagName("li");
		var cons = getElementsByClassName("div","tabCon");
		
		for(i=0; i<tabs.length; i++){
			tabs[i]._i = i;
			cons[i].style.display = "none";
			tabs[i].onclick = function(){
				for(j=0; j<cons.length; j++){
					tabs[j].className = "";
					cons[j].style.display = "none";
					if(document.getElementById("aboutUsImg")){
					    var aboutUsImg = document.getElementById("aboutUsImg").getElementsByTagName("img");
					    aboutUsImg[j].style.display = "none";
					}
				}
				cons[this._i].style.display = "block";
				cons[this._i].style.height = "auto";
				this.className = "on";
				if(document.getElementById("aboutUsImg")){
				    var aboutUsImg = document.getElementById("aboutUsImg").getElementsByTagName("img");
				    aboutUsImg[this._i].style.display = "block";
				}
			}
		}
		tabs[0].className = "on";
		cons[0].style.display = "block";
		cons[0].style.height = "auto";
	}
}

function funcTabs(){
	if(document.getElementById("funcTabs")){
		var tabs = document.getElementById("funcTabs").getElementsByTagName("li");
		for(i=0; i<tabs.length; i++){
			tabs[i]._i = this.innerHTML;
			tabs[i].onclick = function(){
				for(j=0; j<tabs.length; j++){
					tabs[j].className = "";
				}
				this.className = "on";
			}
		}
	}
}

function wallPaper(maskId,leftBtnId,rightBtnId){
if(document.getElementsByTagName("body")[0].getAttribute("id") == "gallery"){
	var largeImg = document.getElementById("largeImg").getElementsByTagName("img")[0];
	var leftBtn = document.getElementById(leftBtnId);
	var rightBtn = document.getElementById(rightBtnId);
	var mask = document.getElementById(maskId);
	mask.scrollLeft=0;
	var scrollCon = mask.getElementsByTagName("ul")[0];
	var allChildren = scrollCon.getElementsByTagName("li");
	for(j=0; j<allChildren.length; j++){
		allChildren[j].onclick = function(){
			for(k=0; k<allChildren.length; k++){
				allChildren[k].className = "";
			}
			this.className = "on";
				document.getElementById("largeImg").getElementsByTagName("img")[0].src = "";
			try{
		          
			   document.getElementById("largeImg").getElementsByTagName("img")[0].setAttribute("src",this.getAttribute("value"));
			   
			    document.getElementById("imgDes").innerHTML=this.getElementsByTagName("img")[0].getAttribute("alt");
			  
			}catch(e)
			{
			   document.getElementById("largeImg").getElementsByTagName("img")[0].setAttribute("src",this.getAttribute("value"));
			
			}
		}
	}
	var scrollItemNumber = scrollCon.getElementsByTagName("li").length;
	var liWidth = 89;
	var step = 4;
	var clickTimes = Math.ceil(scrollItemNumber/step) - 1;
	var leftCount = 0;
	var rightCount = clickTimes;
	var scrollAmount = liWidth*step;
	var scrollInterval;
	var doing = false;
	var scroller = function(target){
		if(target > mask.scrollLeft){
			mask.scrollLeft += Math.ceil((target - mask.scrollLeft)/5);
		}else if(target < mask.scrollLeft){
			mask.scrollLeft += Math.floor((target - mask.scrollLeft)/5);
		}else if(target == mask.scrollLeft){
			clearInterval(scrollInterval);
			doing = false;
		}
		//innerHTML = target + "|" + mask.scrollLeft;

	}
	leftBtn.onclick = function(){
		if(leftCount>0 && doing == false){
			var target = mask.scrollLeft - scrollAmount;
			scrollInterval = setInterval(function(){scroller(target)},50);
			doing = true;
			leftCount -= 1;
			rightCount += 1;
			return false;
		}else return false;
	}
	rightBtn.onclick = function(){
		if(rightCount>0 && doing == false){
			var target = mask.scrollLeft + scrollAmount;
			scrollInterval = setInterval(function(){scroller(target)},50);
			doing = true;
			leftCount += 1;
			rightCount -= 1;
			return false;
		}else return false;
	}
}

}

if(window.attachEvent){
	window.attachEvent("onload",function(){introInfo("infoZh","infoZhUl")});
	window.attachEvent("onload",function(){introInfo("infoEn","infoEnUl")});
	window.attachEvent("onload",conTabs);
	window.attachEvent("onload",funcTabs);
	window.attachEvent("onload",function(){wallPaper("imgScroll","scrollLeft","scrollRight")});
}else if(window.addEventListener){
	window.addEventListener("load",function(){introInfo("infoZh","infoZhUl")},false);
	window.addEventListener("load",function(){introInfo("infoEn","infoEnUl")},false);
	window.addEventListener("load",conTabs,false);
	window.addEventListener("load",function(){wallPaper("imgScroll","scrollLeft","scrollRight")},false);
}



function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}




function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;


	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}







$(document).ready(function(){
	if($("body#locations").length > 0){
		var strA = "<div id=\"overLay\"></div>";
		var strB = "<div id=\"alertWra\"><div id=\"alertTitle\">长期租用</div><div id=\"alertCon\"></div><div id=\"alertCloseBtn\">关闭</div></div>";
		var conA = "<p>AAAA为您提供舒适安全的生活环境是我们的服务目标,相信也是您的愿望。创造安全、舒适、和谐的生活环境需要每一为住户的共同努力和相互理?请您和您的家人注意以下事?</p><p>请勿将危险品,剧毒物品和放射性物品带进公寓。当您离开公寓?请关好门?并检查水、电、燃气的截门是否关好?/p><p>为了保证您和家人及公寓内所有其他住户的安全,请您注意并叮嘱您的家?尤其是未成年子女,不要在公寓内燃放烟花爆竹或使用明火。请勿随意移动或使用消防器材。为保持疏散?疏散门和消防通道的通畅,请勿在楼道等公共地域堆放杂务。否?视为废弃物被及时清理?/p>";
		var conB = "<p>BBBB为您提供舒适安全的生活环境是我们的服务目标,相信也是您的愿望。创造安全、舒适、和谐的生活环境需要每一为住户的共同努力和相互理?请您和您的家人注意以下事?</p><p>请勿将危险品,剧毒物品和放射性物品带进公寓。当您离开公寓?请关好门?并检查水、电、燃气的截门是否关好?/p><p>为了保证您和家人及公寓内所有其他住户的安全,请您注意并叮嘱您的家?尤其是未成年子女,不要在公寓内燃放烟花爆竹或使用明火。请勿随意移动或使用消防器材。为保持疏散?疏散门和消防通道的通畅,请勿在楼道等公共地域堆放杂务。否?视为废弃物被及时清理?/p>";
		if($("#overLay").length < 1){
			$("body").append(strA);
		}
		$("body").append(strB);
		$("#alertCon").html(conA);
		$("#overLay").css({display:"none"});
		$("#alertWra").css({display:"none"});
		var eWidth = $("#alertWra").width();
		var eHeight = $("#alertWra").height();
		
		var pageArr=getPageSize();
		var wWidth = pageArr[2];
		var wHeight = pageArr[3];
		var dWidth = pageArr[0];
		var dHeight = pageArr[1];
		var scrollArr = getPageScroll();
		var scrollTop = scrollArr[0];
		var scrollLeft = scrollArr[1];
		
		var posLeft = (wWidth - eWidth)/2 + document.body.scrollLeft||document.documentElement.scrollLeft;
		var posTop = (wHeight - eHeight)/2 + document.body.scrollTop||document.documentElement.scrollTop;
		
		$("#overLay").css({width:dWidth});
		$("#overLay").css({height:dHeight});
		$("#alertWra").css({left:posLeft});
		$("#alertWra").css({top:posTop});
		
		$("a#longTerm").click(function(){
			$("#alertTitle").attr("className","titleA");
			$("#alertCon").html(conA);
			$("select").hide();
			$("#overLay").css({display:"block"});//gg
			$("#comServiceWra").fadeIn(1000);
		});
		$("div#alertCloseBtn").click(function(){
		$("#overLay").css({display:"none"});//gg
			$("#alertWra").fadeOut("normal");
			setTimeout(function(){$("select").show();},1000);
		});
		
		$("a#shortTerm").click(function(){
			$("#alertTitle").attr("className","titleB");
			$("#alertCon").html(conB);		
			$("select").hide();
			$("#overLay").css({display:"block"});//gg
			$("#comServiceWra").fadeIn(1000);
		});
	}
});

/*$(document).ready(function(){
	if($("#servIcon").length >0){
		$("#servIcon ul li").each(function(i){
			$(this).mousemove(function(){
				$("#toolTips span").text($(this).text());
			});
		});
	}
});
*/
$(document).ready(function(){
	if($("#servIcon").length >0){
		     try{
				$("#toolTips span").text($("#servIcon ul li").eq(0).find("span").text());
	          }catch(e){}
	
		$("#servIcon ul li").each(function(i){
			$("#servIcon ul li").eq(i).find("img").mousemove(function(){
				$("#toolTips span").text($("#servIcon ul li").eq(i).find("span").text());
			});
		});
	}
});

$(document).ready(function(){
	if($("#serMore").length >0){
	$("#serMoreTips span").text($("#serMore ul li").eq(0).find("span").text());

		$("#serMore ul li").each(function(i){
			$("#serMore ul li").eq(i).find("img").mousemove(function(){
				$("#serMoreTips span").text($("#serMore ul li").eq(i).find("span").text());
			});
		});
	}
});

$(document).ready(function(){
	if($("#allNumber").length > 0){
		$("#moreNumber").hover(function(){$("#allNumber").fadeIn("normal")},function(){$("#allNumber").fadeOut("normal")});
	}
});


$(document).ready(function(){
	if($("#selectUs").length >0){
		var strA = "<div id=\"overLay\"></div>";
		var strB = "<div id=\"comServiceWra\"><div id=\"comServCloseBtn\">&nbsp;</div><div id=\"comName\"></div><div id=\"comServiceTableWra\"></div><div id=\"comServiceBottom\"></div></div>";
		if($("#overLay").length<1){
			$("body").append(strA);
		}
		$("body").append(strB);
		if($("#comService").length>0){
			$("#comName").html($("#servName").html());
			$("#comServiceTableWra").html($("#servTable").html());
		}
		$("#overLay").css({display:"none"});
		$("#comServiceWra").css({display:"none"});
		var eWidth = $("#comServiceWra").width();
		var eHeight = $("#comServiceWra").height();
		var wWidth = $(window).width();
		var wHeight = $(window).height();
		var dWidth = $(document).width();
		var dHeight = $(document).height();
		var scrollArr = getPageScroll();
		var scrollTop = scrollArr[0];
		var scrollLeft = scrollArr[1];
		
		var posLeft = (wWidth - eWidth)/2 + scrollLeft;
		var posTop = (wHeight - eHeight)/2 + scrollTop;
		
		$("#overLay").css({width:dWidth});
		$("#overLay").css({height:dHeight});
		$("#comServiceWra").css({left:posLeft});
		$("#comServiceWra").css({top:posTop});
		
		$("#servTitle").click(function(){
			$("select").hide();
			$("#overLay").css({display:"block"});//gg
			$("#comServiceWra").fadeIn(1000);
		});
		$("div#comServCloseBtn").click(function(){
			$("#overLay").css({display:"none"});//gg
			$("#comServiceWra").fadeOut("normal");
			setTimeout(function(){$("select").show();},1000);
			
		});
		
		$("div#overLay").click(function(){
			$("#overLay").css({display:"none"});//gg
			$("#comServiceWra").fadeOut("normal");
			setTimeout(function(){$("select").show();},1000);
			
		});	
		
		
		
		
	}
});
