
function show_hover_infos( id ) {
	$('hover_infos_'+id).style.display = 'block';
	$('product_'+id).removeClassName( 'borderwhite' );
	$('product_'+id).addClassName( 'borderyellow' );
}

function hide_hover_infos( id ) {
	$('hover_infos_'+id).style.display = 'none';
	$('product_'+id).removeClassName( 'borderyellow' );
	$('product_'+id).addClassName( 'borderwhite' );
}

var catalogMouseDown = 0;
var catalogDirection = 'right';

Event.observe(window, 'load', function() {
	if($('catalogScrollLeftButton') != null)
	{
		$('catalogScrollLeftButton').observe('mouseup', catalogOverviewReleaseMouse);
		$('catalogScrollLeftButton').observe('mousedown', catalogOverviewScrollEvent);
	}
	
	if($('catalogScrollRightButton') != null)
	{
		$('catalogScrollRightButton').observe('mouseup', catalogOverviewReleaseMouse);
		$('catalogScrollRightButton').observe('mousedown', catalogOverviewScrollEvent);
	}
});


function catalogOverviewReleaseMouse()
{

}

function catalogOverviewScrollEvent(event)
{
	element =  Event.element(event);

	if(catalogMouseDown != 0)
	{
	
		return;
	}
	
	catalogMouseDown = 1;
	catalogOverviewScroll(element);

}

function catalogOverviewScroll(element)
{
	var catalogScrollGap = 750;
	var anchor = element.up().readAttribute('href');

	oldScroll = $('innerScrollBox').getStyle('left').replace(/px/, '');
	scrollWidth = $('innerScrollBox').getStyle('width').replace(/px/, '');
 
	newScroll = catalogScrollWidth[anchor].position * catalogScrollGap;
	newScroll = newScroll * -1;

	if(catalogScrollWidth[anchor].prev != '')
		$('catalogScrollLeft').writeAttribute('href', catalogScrollWidth[anchor].prev)
	if(catalogScrollWidth[anchor].next !='')
		$('catalogScrollRight').writeAttribute('href', catalogScrollWidth[anchor].next)
	
	if(!$('catalogScrollLeftButton').visible())
	{
		$('catalogScrollLeftButton').show();
	}
		
	if(!$('catalogScrollRightButton').visible())
	{
		$('catalogScrollRightButton').show();
	}
	

	$('innerScrollBox').morph('left: ' + newScroll + 'px', {duration: 0.8, afterFinish: catalogToggleArrows});

}

function catalogToggleArrows()
{
	if((Math.abs(newScroll) + 750) >= scrollWidth)
	{
		if(!$('catalogScrollLeftButton').visible())
		{
			$('catalogScrollLeftButton').show();
		}
		
		if($('catalogScrollRightButton').visible())
		{
			$('catalogScrollRightButton').hide();
		}
	}
	
	if(newScroll >= 0)
	{
		if($('catalogScrollLeftButton').visible())
		{
			$('catalogScrollLeftButton').hide();
		}
		
		if(!$('catalogScrollRightButton').visible())
		{
			$('catalogScrollRightButton').show();
		}
	}
	
	catalogMouseDown = 0;
}

function show_article_hover_button(obj, info){
	var btn = $('article_hover_button');
	btn.update(info).show();

	Event.observe(obj,'mousemove',function(event){
		var newTop = (event.pointerY() + 22);
		var newLeft = (event.pointerX() + 1);

		var viewPort = document.viewport.getDimensions();
		var offSets = document.viewport.getScrollOffsets();

		var viewPortMaxY = viewPort.height + offSets[1] - 2;
		var viewPortMaxX = viewPort.width + offSets[0] - 2;

		if( newTop > viewPortMaxY ) {
			newTop = viewPortMaxY;
		}

		if( newLeft > viewPortMaxX ) {
			newLeft = viewPortMaxX;
		}

		btn.style.top = newTop + 'px';
		btn.style.left = newLeft +'px';
	});
}

function hide_article_hover_button(obj){
	$('article_hover_button').hide().update('');
	Event.stopObserving(obj,'mousemove');
}
