﻿/* To manipulate img in a zone */
	silsilNewWidth = 0;
	silINIT = false;
	var timeoutamim;
	var timeoutautoscroll;
	silPOS = 0;
	numberofdiapos = 0;
	lastDiapo = 1;
	moving=false;
	direction="up";
	
	/* Start scrolling */
	function startscrolling(numDiapo) {
	    UpdatesilNewWidth();
	    value = 20;
	    cran = numDiapo - 1;
	    stop = (cran * silNewWidth);
	    if (lastDiapo > numDiapo) {
	        value = -value;
	        cran = numDiapo - 1;
	    }
	    document.getElementById("idNewsWindow").scrollLeft += value;
	    silPOS += value;
	    if ((lastDiapo < numDiapo && silPOS >= stop)
	        || (lastDiapo > numDiapo && silPOS <= stop)) {
	        clearInterval(timeoutamim);
	        updatenavigation(numDiapo);
	        lastDiapo = numDiapo;
			moving=false;
	        timeoutautoscroll = setInterval(function () { AutoScroll(); }, 10000);
	    }
	}
	/* Ask to scroll */
	function Scroll(numdiapo) {

	    clearInterval(timeoutautoscroll);
	    if (!silINIT) { Initialize(); }
	    if (numdiapo != lastDiapo && !moving) {
			moving=true;
	        timeoutamim = setInterval(function () { startscrolling(numdiapo); }, 20);
	    }
	}
	/* silINIT to be able to scroll */
	function Initialize() {
	    UpdatesilNewWidth();
	    silINIT = true;
	    updatenavigation(1);
	}
	/* Calculation Newwith */
	function UpdatesilNewWidth() {
	    try {

	        if (document.getElementById("idNewsWindow").children[0]) {
	            silNewWidth = parseInt(document.getElementById("idNewsWindow").children[0].width)
	            numberofdiapos = parseInt(document.getElementById("idNewsWindow").children.length);
	        }
	        else {
	            silNewWidth = parseInt(document.getElementById("idNewsWindow").childNodes[0].width)
	            numberofdiapos = parseInt(document.getElementById("idNewsWindow").childNodes.length);
	        } 
	    }
	    catch (err) { ; }

	}
	/* start autoscroll */
	function AutoScroll() {
		if (!moving){
		    if (!silINIT) { Initialize(); }
		    clearInterval(timeoutautoscroll);
			if (lastDiapo == numberofdiapos){
				direction="down";
			}
			if (lastDiapo == 1){
				direction="up";
			}
		    if (direction=="up"){
				Scroll(lastDiapo +1);
		    }
		    if (direction=="down"){
				Scroll(lastDiapo -1);
			}
		}
	}
	
	/* update navigation buttons */
	function updatenavigation(numdiapo){
	    if (document.getElementById("idNewsControls").children[0]) {
			document.getElementById("idNewsControls").children[lastDiapo-1].style.border = "none";
			document.getElementById("idNewsControls").children[numdiapo-1].style.border = "1px solid gray";
		}
	    else {
			document.getElementById("idNewsControls").childNodes[lastDiapo-1].style.border = "none";
			document.getElementById("idNewsControls").childNodes[numdiapo-1].style.border = "1px solid gray";
	    
	    }
	}
	

