function get(el) {
	return document.getElementById(el);
}

if (get("gotoCountry")) {
	get("gotoCountry").onclick = function() {
		window.location = get("countrySelector").value;
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement &&	document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var footerElement = get('footer');
			var leftsideHeight = get('side-left').offsetHeight;
			var rightsideHeight = get('side-right').offsetHeight;		
			var headerHeight = get('header').offsetHeight;
			var contentHeight = (rightsideHeight > leftsideHeight) ? rightsideHeight : leftsideHeight;
			var footerHeight = footerElement.offsetHeight;
			var pageHeight = headerHeight + contentHeight + footerHeight;
			// alert("windowHeight: " + windowHeight + " headerHeight: " + headerHeight + " leftsideHeight: " + leftsideHeight + " rightsideHeight: " + rightsideHeight + " footerHeight: " + footerHeight);
			if (windowHeight - pageHeight >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - pageHeight) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}

var brandPosition = 0;
var timerID;

get("showPrev").style.cursor = "pointer";
get("showNext").style.cursor = "pointer";

function startBrandsLoop() {
	timerID = setTimeout(function() {loopBrands()}, 6000);
}

function loopBrands() {
	brandPosition = (brandPosition == -150) ? 0 : brandPosition-50;
	get("brands").style.backgroundPosition = "0px " + brandPosition + "px";
	timerID = setTimeout(function() {loopBrands()}, 6000);
}

get("showPrev").onclick = function() {
	clearTimeout(timerID);
	brandPosition = (brandPosition == 0) ? -150 : brandPosition+50;
	get("brands").style.backgroundPosition = "0px " + brandPosition + "px";
	timerID = setTimeout(function() {loopBrands()}, 10000);
}

get("showNext").onclick = function() {
	clearTimeout(timerID);
	brandPosition = (brandPosition == -150) ? 0 : brandPosition-50;
	get("brands").style.backgroundPosition = "0px " + brandPosition + "px";
	timerID = setTimeout(function() {loopBrands()}, 10000);
}

setFooter();
startBrandsLoop();