﻿var projNavClicked = null;
var nextClick = 0;
var projArray = new Array();
var total;
var timeOut;
var loop = false;
var d = document;

projArray = [

{
	name:"Postgraduate Diploma Programme",
	banner:"/cidp/images/CenterFlash/1125postdip.jpg",
	link:"news/info/details.html#1125postdip",
	target:"_self"
},

{
	name:"Online Application",
	banner:"/cidp/images/CenterFlash/centerFlashAltImg_freeonl.jpg",
	link:"https://w3.hkuspace.hku.hk/eform/CIDP/OnlineForm.php",
	target:"_blank"
},



{
	name:"CIDP Information Seminar",
	banner:"/cidp/images/CenterFlash/1127infosem.jpg",
	link:"news/info/details.html#1127infosem",
	target:"_self"
},

{
	name:"Online Application",
	banner:"/cidp/images/CenterFlash/centerFlashAltImg_freeonl.jpg",
	link:"https://w3.hkuspace.hku.hk/eform/CIDP/OnlineForm.php",
	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 loopStart()
{
	loop = true;
	setTime();
}

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;
	if (loop)	setTime();
	startFading("flashCenter");
}

function genProjectContent(i)
{
	var imgDiv = d.getElementById("photoSlideImg");
	//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, 431, 263, 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+"";*/
	
	d.getElementById("photoSlideImg").style.visibility = "visible";
}

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;
}



