/* 
/* All scripts Copyright (c) 2007 OSKAR D bvba (http://www.oskard.be)
/* except 'Effect.Move' Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us)
/* under MIT License
/* do not remove this credits
*/

var interval		= 5000; // milliseconds
var clicks			= 0;
var screenW			= 0;
var workArea		= 0;
var visibleItems	= 0;
var showScrollBar	= true;
var hpInterv		= null;
var currPos			= 0;
var hotproducts		= null;

window.onresize = setHotProducts;

function moveHP(dir) {
	if((numItems*151) > workArea) {
		clicks += dir;
		if((clicks<=0 && dir=='1') || (clicks>=-(numItems-visibleItems) && dir=='-1')) {
			hotproducts.custom(currPos, (clicks*151));
			currPos = (clicks*151);
			//new Effect.Move('hotproducts_moveme', {x: (clicks*151), y: 0, mode: 'absolute'});
			var negClicks = -clicks;
			for(i=1; i<=numItems; i++) document.getElementById('hotproducts_item_'+i).className = (i <= negClicks || i > (visibleItems+negClicks)) ? 'hotproducts_hidden' : 'hotproducts_visible';
			return true;
		} else {
			clicks -= dir; // restore after doing nothing
			return false;
		}
	} else {
		return false;
	}
}

function setHotProducts() {
	checkHotProducts();
	clicks = 0;
	//new Effect.Move('hotproducts_moveme', {x: 0, y: 0, mode: 'absolute'});
	hotproducts.custom(currPos, 0);
	currPos = 0;
}

function startHotProducts() {
	hotproducts = new fx.Style('hotproducts_moveme', 'margin-left', {duration:1000});
	checkHotProducts();
	playHP();
}

function checkHotProducts() {
	getScreenW();
	workArea = (screenW-240);
	document.getElementById('hotproducts_container_hp').style.width = workArea+'px';
	visibleItems = Math.floor(workArea/151);
	if (visibleItems >= numItems) {
		visibleItems = numItems;
		showScrollBar = false;
		document.getElementById('hotproducts_scrollbar_hp').style.display = 'none';
		if (hpInterv) clearInterval(hpInterv);
	} else {
		showScrollBar = true;
		document.getElementById('hotproducts_scrollbar_hp').style.display = 'block';
		playHP();
	}
	for(i=1; i<=numItems; i++) document.getElementById('hotproducts_item_'+i).className = (i <= visibleItems) ? 'hotproducts_visible' : 'hotproducts_hidden';
}

function getScreenW() {
	if(typeof( window.innerWidth ) == 'number') { // non-IE
		screenW = window.innerWidth;
	} else if(document.documentElement && document.documentElement.clientWidth) { // IE6 + in 'standards compliant mode'
		screenW = document.documentElement.clientWidth;
	} else if(document.body && document.body.clientWidth) { // IE4 compatible
		screenW = document.body.clientWidth;
	}
}

function playHP() {
	if (hpInterv) clearInterval(hpInterv);
	if (showScrollBar) {
		hpInterv = setInterval('loopHP()', interval);
		document.getElementById('hotproducts_play').style.display = 'none';
		document.getElementById('hotproducts_pauze').style.display = 'inline';
	}
}

function loopHP() {
	if (!moveHP(-1)) {
		setHotProducts();
	}
}

function pauzeHP() {
	if (hpInterv) clearInterval(hpInterv);
	if (showScrollBar) {
		document.getElementById('hotproducts_play').style.display = 'inline';
		document.getElementById('hotproducts_pauze').style.display = 'none';
	}
}
