﻿var projNavClicked = null;
var nextClick = 0;
var projArray = new Array();
var total;
var timeOut;

projArray = [
{
	name:"关於朝阳区环球金融中心",
	details:"环球金融中心(简称wfc)，位於世界经济发展焦点 ──中国北京商务中心区，是城中的国际顶尖商务综合大楼，",
	banner:"/gb/images/altProjectFocus.jpg",
	link:"/gb/html/projects/projectBJ.asp",
	target:"_self",
	color:"#294F95",
	bgImage:"/gb/images/shadow_proj1.gif",
	careers:[
		{name:"会计经理", link:"123.asp", target:"_blank"},
		{name:"项目经理 - 企业策划部(北京)", link:"123.asp", target:"_blank"}
	]
},
{
	name:"关於恒基<span class='bull'>&bull;</span>凯旋门",
	details:"「恒基<span class='bull'>&bull;</span>凯旋门」全期建筑面积共72万平方米（约775万平方尺），分三期而建，设有豪华住宅、业主会所、小区设施及康乐配套，其中5号栋楼王楼高33层，",
	banner:"/gb/images/altProjectFocus_2.jpg",
	link:"/gb/html/projects/projectCS.asp",
	target:"_self",
	color:"#1b7dd3",
	bgImage:"/gb/images/shadow_proj2.gif",
	careers:[
		{name:"会计经理", link:"123.asp", target:"_blank"},
		{name:"项目经理 - 企业策划部(北京)", link:"123.asp", target:"_blank"}
	]
}
];


genProject();

function genProject()
{
	var obj = projArray;
	var nav = d.getElementById("projectFocusNav");
	total = obj.length;
	
	for (var i=0; i<total; i++)
	{
		var div = createDiv("projectFocus_"+i);
		
		div.num = i;
		div.onclick = function() {changeProject(this.num)};
		
		nav.appendChild(div);
	}
	
	changeProject(0);
}

function setTime()
{
	clearInterval(timeOut);
	
	var timeCompleted = function()
	{
		nextClick ++;
		
		if (nextClick >= total)
		{
			nextClick = 0;
		}
		
		changeProject(nextClick);
	}
	timeOut = setInterval(timeCompleted, 7000);
}

function changeProject(i)
{
	if (i == projNavClicked)	return;
	
	var nav = d.getElementById("projectFocus_"+i);
	nav.className = "active";
	
	if (projNavClicked != null)
	{
		var nav1 = d.getElementById("projectFocus_"+projNavClicked);
		nav1.className = "";
	}
	
	genProjectContent(i);
	
	projNavClicked = i;
	nextClick = i;
	setTime();
	startFading("projectFocus");
}

function genProjectContent(i)
{
	var imgDiv = d.getElementById("projectFocusImg");
	var linksDiv = d.getElementById("projectFocusLinks");
	var txtDiv = d.getElementById("projectFocusText");
	var topDiv = d.getElementById("projectFocusTop");
	var obj = projArray[i];
	
	imgDiv.innerHTML = "";
//	linksDiv.innerHTML = "招聘职位:&nbsp;&nbsp;&nbsp;";
	txtDiv.innerHTML = "";
	
	var img = createImg(obj.banner, obj.name, 232, 130, obj.link, obj.target);
	imgDiv.appendChild(img);
	
	for (var j=0; j<obj.careers.length; j++)
	{
		var obj1 = obj.careers[j];
		var a = createA(obj1.link, obj1.target, ("&#8226;&nbsp;" + obj1.name));
//		linksDiv.appendChild(a);
	}
	
	var h2 = d.createElement("h2");
	h2.innerHTML = obj.name + "﹕";
	txtDiv.appendChild(h2);
	
	var p = d.createElement("p");
	p.innerHTML = obj.details;
	var a = createA(obj.link, obj.target, "更多>");
	p.appendChild(a);
	txtDiv.appendChild(p);
	
	d.getElementById("projectFocus").style.visibility = "visible";
	topDiv.style.background = "url("+obj.bgImage+") no-repeat bottom center "+obj.color+"";
}

function createImg(src, alt, w, h, link, t, className)
{
	var img = d.createElement('img');
	if (src)	img.setAttribute('src', src);
	if (alt)	img.setAttribute('alt', alt);
	if (w)	img.setAttribute('width', w);
	if (h)	img.setAttribute('height', h);
	if (className)	img.className = className;
	
	if (link)
	{
		img.setAttribute('border', 0);
		
		var a = d.createElement('a');
		a.setAttribute('href', link);
		if (t && typeof(t) != 'undefined')	a.setAttribute('target', t);
		a.appendChild(img);
		return a;
	}
	else
	{	
		return img;
	}
}

function startFading(id) {
//  var el = document.getElementById('fading_image_container').getElementsByTagName("div")[nextImage];
  var el = document.getElementById(id);

  el.style.visibility = 'visible';
  el.style.zIndex = 2;
  setOpacity(el, 0);
  fadeImage(el,0);
}

function fadeImage(el, currentOpacity) {

  currentOpacity += 10;

  if (currentOpacity > 100) {
    setOpacity(el, 100);
//    var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
//    var prevEl = document.getElementById('fading_image_container').getElementsByTagName("div")[1];
//    prevEl.style.visibility = 'hidden';
    el.style.zIndex = 1;
  }
  else {
    setOpacity(el, currentOpacity);
    window.setTimeout(function() { fadeImage(el, currentOpacity); }, 20);
  }
}

function setOpacity(el, opacity) {

	opacity /= 100;

	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";

}

function createA(link, t, txt, id, className)
{		
	var a = d.createElement('a');
	if (link)	a.setAttribute('href', link);
	if (t && typeof(t) != 'undefined')	a.setAttribute('target', t);
	
	//if (txt)	a.appendChild(d.createTextNode(txt));
	if (txt)	a.innerHTML = txt;
	if (id)	a.setAttribute('id', id);
	if (className)	a.className = className;
	
	return a;
}

function createDiv(id, className, txt)
{		
	var div = d.createElement('div');
	if (id)	div.setAttribute('id', id);
	if (className)	div.className = className;
	//if (txt)	div.appendChild(d.createTextNode(txt));
	if (txt)	div.innerHTML = txt;
	return div;
}

function createTag(tag, id, className)
{		
	var div = d.createElement(tag);
	if (id)	div.setAttribute('id', id);
	if (className)	div.className = className;
	return div;
}

function createInput(name, type, value, className)
{		
	var input = d.createElement('input');
	if (name)	input.setAttribute('name', name);
	if (type)	input.setAttribute('type', type);
	if (value)	input.setAttribute('value', value);
	if (className)	input.className = className;
	return input;
}



