var newsMover		= null;
var currNewsShowing = 0;
var newsCount		= 0;
var currNewsA       = null;
var newsAr          = null;

function initScrollNews() {
	if(document.getElementById("newsBarContainer")){
		newsAr = document.getElementById("newsBarContainer").childNodes
		newsCount = parseInt(newsAr.length)-1;
	
		if(newsCount >= 1){
			typeNewsStart(0);
		}
	}
	 initScrollVideo();
}

function typeNewsStart(nb) {
	currNewsShowing = nb;
	
	currNewsA = document.getElementById("currNews");

	currNewsA.setAttribute("href", newsAr[currNewsShowing].getAttribute("href"));
	
	if(currNewsA.firstChild){
		currNewsA.removeChild(currNewsA.firstChild);
	}

	currNewsA.appendChild(document.createTextNode(""));
	
	setOpacity(document.getElementById("newsBarContainer"), 1);

	//Calculate margin...
	HN = document.getElementById("hiddenNews");
	if(!HN) {
		HN = document.createElement("div");
		HN.setAttribute("style", "display: block; position: absolute; left: -1000px; top: -1000px;");
		HN.setAttribute("id", "hiddenNews");
		document.getElementsByTagName("body")[0].appendChild(HN);
	}

	HN.innerHTML = "";
	aaa = newsAr[nb].cloneNode(true);
	aaa.setAttribute("style", "overflow: hidden; width: 0px; white-space: nowrap; display: block;");
	HN.appendChild(aaa);

	document.getElementById("newsBarContainer").style.marginLeft = (340-(parseInt(aaa.scrollWidth)/2))+"px";

	
	window.setTimeout(typeChar, 75);

}

function typeChar(){
	//DO IT
	currLen = currNewsA.firstChild.nodeValue.length;
	currNewsA.firstChild.nodeValue = String(newsAr[currNewsShowing].firstChild.nodeValue).substr(0, currLen+1);

	// SI OK : 
	if(currLen+1 < newsAr[currNewsShowing].firstChild.nodeValue.length){
		window.setTimeout(typeChar, 75);
	} else {
		if(currNewsShowing+1 == newsCount){
			currNewsShowing = -1;
		}
		window.setTimeout(startFadeNews, 1000);											// Increase value eventually
	}
}

function startFadeNews(){
	startFade(document.getElementById("newsBarContainer"), 0, false, function(){ window.setTimeout("typeNewsStart("+parseInt(++currNewsShowing)+");", 1000); } );
}

/************************************ Images now... *********************************/
var imgAr = null;
var imgCount = null;
var currImgShowing = null;

function initScrollVideo() {
	if(document.getElementById("newsBarContainer")){
		imgAr = document.getElementById("videoBoxImgSurround").getElementsByTagName("img");
		imgCount = parseInt(imgAr.length)-1;
	
		if(imgCount >= 1){
			startAnim(0);
		} else if(imgCount == 0) {
			imgAr[0].style.display = "block";
			return;
		}
	}
}

function startAnim(nb) {
	currImgShowing = nb;
	
	if(imgCount > 0) {
		startShowImg(0);
	}
}

function startFadeImg(){
	if(currImgShowing >= imgCount) {
		nextImg = 0;
	} else {
		nextImg = currImgShowing+1;
	}	
	startFade(imgAr[currImgShowing], 0, true, function(){ window.setTimeout("startShowImg("+parseInt(nextImg)+");", 1000); } );
	currImgShowing = nextImg;
}

function startShowImg(nb) {
	startShow(imgAr[nb], waitToHide);
}

function waitToHide() {
	window.setTimeout(startFadeImg, 1000);
}


window.onload = initScrollVideo;