//-------- based on Prototype ---------
var current = 'pager_01';
var switchDelay = 5000;
var delayBeforeResume = 25*1000; 
var switcherLocked = false; 
var resumePeriodical = false;
var effectDuration = 0.5;
var lockTimeout = 750;
var carousel = $$('.prod-item');
var	total = carousel.length;

$(current).addClassName('act');

function timedSwitch() {
	if (switcherLocked) return false;
	switcherLocked = true;
	curr = parseInt($(current).id.sub('pager_0',''));
	if (curr < total) { next = curr+1; } else { next = 1 };
	$('pager_0'+curr).removeClassName('act');
	$('pager_0'+next).addClassName('act');
	Effect.Fade($('item_0'+curr),{duration:effectDuration});
	Effect.Appear($('item_0'+next),{duration:effectDuration});
	current = 'pager_0'+next;
	setTimeout('switcherLocked = false;',lockTimeout);
	periodical = setTimeout('timedSwitch()',switchDelay);
	return false;
}
if (total>1) periodical = setTimeout('timedSwitch()',switchDelay);

function switchItem(e){
	if (e.id==current) return false;
	if (switcherLocked) return false;
	switcherLocked = true;
	clearInterval(periodical);
	if (resumePeriodical) clearInterval(resumePeriodical);
	$(current).removeClassName('act');
	$(e.id).addClassName('act');
	Effect.Fade($('item_0'+current.sub('pager_0','')),{duration:effectDuration});
	Effect.Appear($('item_0'+e.id.sub('pager_0','')),{duration:effectDuration});
	current = e.id;
	setTimeout('switcherLocked = false;',lockTimeout);
	if (delayBeforeResume) resumePeriodical = setTimeout("periodical = setTimeout('timedSwitch()',switchDelay);",delayBeforeResume);
//	setControlState('pause');
	return false;
};
function switchPrev(e){
	if (switcherLocked) return false;
	switcherLocked = true;
	curr = parseInt($(current).id.sub('pager_0',''));
	clearInterval(periodical);
	if (curr > 1) prev = curr-1; else prev = total;
	$('pager_0'+curr).removeClassName('act');
	$('pager_0'+prev).addClassName('act');
	Effect.Fade($('item_0'+curr),{duration:effectDuration});
	Effect.Appear($('item_0'+prev),{duration:effectDuration});
	current = 'pager_0'+prev;
	setTimeout('switcherLocked = false;',lockTimeout);
	periodical = setTimeout('timedSwitch()',switchDelay);
//	setControlState('pause')
	return false;
};
function switchNext(e){
	if (switcherLocked) return false;
	switcherLocked = true;
	curr = parseInt($(current).id.sub('pager_0',''));
	clearInterval(periodical);
	if (curr < total) next = curr+1; else next = 1;
	$('pager_0'+curr).removeClassName('act');
	$('pager_0'+next).addClassName('act');
	Effect.Fade($('item_0'+curr),{duration:effectDuration});
	Effect.Appear($('item_0'+next),{duration:effectDuration});
	current = 'pager_0'+next;
	setTimeout('switcherLocked = false;',lockTimeout);
	periodical = setTimeout('timedSwitch()',switchDelay);
//	setControlState('pause')
	return false;
};
/*
function setControlState(state){
	control = $('control_button');
	$(control).removeClassName('play');
	$(control).removeClassName('pause');
	$(control).addClassName(state);			
}
function togglePlay(e) {
	clearInterval(periodical);
	if (resumePeriodical) clearInterval(resumePeriodical);
	if ($(e).hasClassName('pause')) {
		setControlState('play');
	} else {
		setControlState('pause');
		periodical = setTimeout('timedSwitch()',250);
	}
	return false;
};
*/

