var carList;
var carCurrent;
var carCurrentIndex;
var carTimer;

function carChangeManual(img) {
	if(!carList) return;
	
	clearTimeout(carTimer);
	carChange(img);
	carSetTimeout(15);
}

function carChange(img) {
	var nextIndex = 0;
	
	for(var i = 0; i < carList.length; i++) {
		if(carList[i] == img) {
			nextIndex = i;
			break;
		}
	}
	
	if(nextIndex != carCurrentIndex) {
		carList[carCurrentIndex].className = '';
		carList[carCurrentIndex].setAttribute('class', '');
		img.className = 'active';
		img.setAttribute('class', 'active');
		carCurrentIndex = nextIndex;
	}
	
	var tdiv = carCurrent.getElementsByTagName('div')[0];
	carCurrent.style.backgroundImage = 'url('+img.src+')';
	eval('carCurrent.onclick = function() { location.href = "'+img.parentNode.href+'"; }');
	tdiv.firstChild.nodeValue = img.title;
}

function carChangeTimed() {
	carChange(carList[(carCurrentIndex+1) % carList.length]);
	carSetTimeout(10);
}

function carOnLoad() {
	carList = document.getElementById('hlcarrousel').getElementsByTagName('img');
	carCurrent = document.getElementById('carrousel');
	for(var i = 0, n = carList.length; i < n; i++) {
		if(carList[i].className == 'active') {
			carCurrentIndex = i;
			carChange(carList[i]);
			break;
		}
	}
	carSetTimeout(10);
}

function carSetTimeout(secs) {
	carTimer = setTimeout('carChangeTimed();', secs * 1000);
}

if(window.addEventListener) {
	window.addEventListener('load', carOnLoad, false);
} else if(window.attachEvent) {
	window.attachEvent('onload', carOnLoad);
}