/* Homepage */
function startSlideshow()
{
	showTimeBar('#cbd400', 40);
}

var timer;
function showTimeBar(color, duration)
{	
	new Effect.Morph('timeBar', { style: 'width: 1px;', duration: 0.01});
	new Effect.Morph('timeBar', { style: 'background: '+color, duration: 0.1});
	new Effect.Morph('timeBar', { style: 'width: 990px;', duration: duration});
	clearTimeout(timer);
	part1();
}

function part1(){
	// start timing for next movement
	timer = setTimeout("part2()",41000);
}

function part2(){
	// do the function
	homeSlideForward('carrousel', 40, 0);
}
		 	

	function homeSlideBack(id, time)
	{
		
		var handlepos = $(id).getStyle('left');
		handlepos = handlepos.substr(0,(handlepos.length-2));
		
		var next_position = -(parseFloat(handlepos)+990);
		var max_position = -1;	
			
		if(next_position > max_position)
		{
			new Effect.Move(id, { x: 990, duration: 0.1, mode: 'relative' });
			var currSlide = (990/handlepos)+2;	
			setCurrenthSlide('currerntSlide', currSlide,3);
			showTimeBar('#cbd400', time);	
		}
	}


	function homeSlideForward(id, time, mode)
	{
		// check current position
		var handlepos = $(id).getStyle('left');
		handlepos = handlepos.substr(0,(handlepos.length-2));
		
		var next_position = handlepos - 990;
		var max_position = -((3-1)*990);

		if (mode == 1 && (next_position+1) > max_position  )
		{
			new Effect.Move(id, { x: -990, duration: 0.1, mode: 'relative' });
			var currSlide = (handlepos/-990)+2;	
			setCurrenthSlide('currerntSlide', currSlide,3);
			showTimeBar('#cbd400', time);		
		}
		else
		{
			if(mode==0)
			{
				if(max_position > next_position)
				{
					
					new Effect.Move(id, { x: (990*2), duration: 0.5, mode: 'relative' });
					showTimeBar('#cbd400', time);						
					setCurrenthSlide('currerntSlide', 1,3);
				}
				else
				{
					new Effect.Move(id, { x: -990, duration: 1.0, mode: 'relative' });
					var currSlide = (handlepos/-990)+2;	
					setCurrenthSlide('currerntSlide', currSlide,3);
					showTimeBar('#cbd400', time);	
				}
			}
		}
	}
	

	
	function setCurrenthSlide(id, currentSlide,items)
	{
		var currslide = Math.ceil(currentSlide);
		var slides = currslide + '/' + items;
		if(currslide > 1)
		{
			var navLeft = '<a href="javascript: void(0);" title="&lt; vorige" onclick="homeSlideBack(\'carrousel\', 40);">&lt;</a>';
		}
		else
		{
			var navLeft = '&lt;';
		}
		
		if(currslide < 3)
		{
			var navRight = '<a href="javascript: void(0);" title="volgende &gt; " onclick="homeSlideForward(\'carrousel\', 40, 1);">&gt</a>';
		}
		else
		{
			var navRight = '&gt';	
		}
		
		$(id).innerHTML = '<p>'+navRight+'</p><p id="slideCount">'+slides+'</p><p>'+navLeft+'</p>';
	}
	
	
	selected_id='';
	
	function dissapearDetail()
	{
		if(selected_id != '')
		{
			id1 = 'l'+selected_id;
			id2 = 'p'+selected_id;
			new Effect.Appear(id2, {from: 1.0, to: 0.0,duration: 0.2});
			new Effect.Move(id1, {x: 0, y: 0, mode: 'absolute', delay: 0.2, duration: 0.3});
			
			selected_id = '';
		}
	}
	
	function appearDetail(id)
	{
		dissapearDetail();
		id1 = 'l'+id
		id2 = 'p'+id
		
		var handlepos = $(id1).getStyle('left');
		handlepos = handlepos.substr(0,(handlepos.length-2));
		if( handlepos < 21 && handlepos != 20)
		{		selected_id = id;
			new Effect.Move(id1, {x: 20, y: 0, mode: 'absolute', duration: 0.3});
			new Effect.Appear(id2, {from: 0.0, to: 1.0, duration: 0.2, delay: 0.2});
			
		}
	}
	
	
	
	/* Ajax GetFILES*/
	
function GetPage(url) 
{

	
	new Ajax.Request(url, { 
	 method: 'GET', 
		onComplete: function(transport) { 
  			$('phoneMe').innerHTML = transport.responseText;

		 },
		onFailure: function (transport) {
			//new Effect.Opacity('Content_Dynamic', { from: 0.0, to: 1.0, duration: 1.0, delay: 0.2 });return false;
			$('phoneMe').show();
		}
	}); 	
}
	
	
/* Producten */
current_prod = '1';
function arrowMove(id)
{
	if(current_prod!=id)
	{
		if(id==1)	
		{
			var_x = 45;
		}
	
		if(id==2)	
		{var_x = 145;}
		
		if(id==3)	
		{var_x = 235;}
	
		if(id==4)	
		{var_x = 355;}
	
	
		new Effect.toggle('prod_'+current_prod, 'appear', {queue: 'product', duration: 0.2});
		new Effect.toggle('prod_'+id, 'appear', {queue: 'product', duration: 0.2, delay: 0.2});
		new Effect.Move('arrow', {x: var_x, y: -8, mode: 'absolute', duration: 0.2});	
		current_prod = id;
	}
}


