fireOn = Window.ie ? 'load' : 'domready';
window.addEvent(fireOn, function() {				
	var periodical;								 
								 
	if($('moveLeft')){
		x = $('pictures').style.left.toInt();
		if(x == "" || isNaN(x)) x= 0;
		if(x == 0) $('moveLeft').style.display='none';
		$('moveLeft').addEvent('click', function(e){
			x = $('pictures').style.left.toInt();		
			if(x == "" || isNaN(x)) x= 0;		
			newX = x +250;
			if(x < 0){
				$('moveLeft').style.display='block';
				$('pictures').effect('left',{ duration: 1000, transition: Fx.Transitions.Bounce.easeOut, wait:true }).start(x, newX );
			}
			if(newX >=0) $('moveLeft').style.display='none';
			images =  $$('#pictures a');
			aantal = images.length;
			if(aantal <= 5) $('moveRight').style.display='none'; else $('moveRight').style.display='block';
			return false;
		});
	}
	if($('moveRight')){
		images =  $$('#pictures a');
		aantal = images.length;
		if(aantal <= 5) $('moveRight').style.display='none'; else $('moveRight').style.display='block';
		$('moveRight').addEvent('click', function(e){
			x = $('pictures').style.left.toInt();		 
			if(x == "" || isNaN(x)) x= 0;
			images =  $$('#pictures a');
			aantal = images.length;
			maxP = (aantal * -50) + 250;
			newX = x -250;
			$('moveLeft').style.display='block';
			if(newX <= maxP)$('moveRight').style.display='none';
			if(x > maxP){
				$('pictures').effect('left',{ duration: 1000, transition: Fx.Transitions.Bounce.easeOut, wait:true }).start(x, newX);  
			}
			return false;
		});
	}
			
	var links =  $$('#galleryButtons a');
	for (i=0; i<links.length;i++)
	{
		if(links[i].id!="moveLeft" && links[i].id != "moveRight")
		{
			createOver(links[i]);
		}
	}
	
	
	
	function createOver(el)
	{
		if (!el) return false;
		el.addEvent('click', function(e){  
			$clear(periodical);									  
			doNext(el, false);
			//periodical = cls2.periodical(5000);
		});	
	}
	
	function doNext(el, NOTCLICK)
	{
		if(NOTCLICK)
		{
			INTERVALTELLER++;
			if(INTERVALTELLER > images.length) {INTERVALTELLER = 1; el = images[0]}
		}
		var outeffet = new Fx.Style($('galleryBig'), 'opacity', {duration:1000});
		outeffet.start.delay(0, outeffet, [1,0]);	
		var ineffet = new Fx.Style($('galleryBig'), 'opacity', {duration:1000});
		ineffet.start.delay(1000, ineffet, [0,1]);	
		var cls = function() {
			$('galleryBig').setStyle('background-image',  'url(' + el.href + ')');
		}.delay(1000);
		if($('collectionText')) {
			var outeffetText = new Fx.Style($('collectionText'), 'opacity', {duration:1000});
			outeffetText.start.delay(0, outeffetText, [1,0]);	
			var ineffetText = new Fx.Style($('collectionText'), 'opacity', {duration:1000});
			ineffetText.start.delay(1000, ineffetText, [0,1]);	
			var clsText = function() {
				$('collectionText').innerHTML = '' + el.title;
			}.delay(1000);				
		}
		removeClassNames();
		el.className="active";
		return false; 
	}
	
	function removeClassNames()
	{
		var links =  $$('#galleryButtons a');
		for (i=0; i<links.length;i++)
		{
			if(links[i].id!="moveLeft" && links[i].id != "moveRight")
			{
				links[i].className="";
			}
		}
	}
	
	var ToolTips = new Tips($$('.tipColor'),{ 
		onShow : function(toolTip)
		{
			color = this.text.innerHTML;
			this.toolTip.innerHTML = "<div style='background-color:"+color+"; border:1px solid #000000; width:126px; height:126px'></div>";
			this.toolTip.firstChild.parentNode.style.visibility = 'visible';
		}
	});
	
	$$('.tipCushion').each(function(cushion){	
		new Tips(cushion,{ 
			onShow : function(toolTip)
			{
				fileName = cushion.getElement('input[name=filename]').value;
				this.toolTip.innerHTML = "<img src='/uploads/images/126s/"+fileName+"' style='border:1px solid black;' />";
				this.toolTip.firstChild.parentNode.style.visibility = 'visible';
			}
		});
	});
	
	INTERVALTELLER = 1;			
	
	var cls2 = function(){			
		if($('pictures'))
		{
			doNext(images[INTERVALTELLER], true);
		}
		else
		{
			$clear(periodical);	
		}
	}

	var cls = function(){
		periodical = cls2.periodical(5000);
	}.delay(0);
	
	
	
});


/*
fireOn = Window.ie ? 'load' : 'domready';
window.addEvent(fireOn, function() {	
	if($('moveLeft')){
		x = $('pictures').style.left.toInt();
		if(x == "" || isNaN(x)) x= 0;
		//if(x == 0) $('moveLeft').style.display='none';
		$('moveLeft').addEvent('click', function(e){
			x = $('pictures').style.left.toInt();		
			if(x == "" || isNaN(x)) x= 0;		
			newX = x +250;
			//if(newX >= 0) $('moveLeft').style.display='none';
			console.log(x);
			if(x < 0){
				$('moveLeft').style.display='block';
				$('pictures').effect('left',{ duration: 1000, transition: Fx.Transitions.Bounce.easeOut, wait:true }).start(x, newX );
			}
			images =  $$('#pictures a');
			aantal = images.length;
			if(aantal <= 5) $('moveRight').style.display='none'; else $('moveRight').style.display='block';
			return false;
		});
	}
	if($('moveRight')){
		images =  $$('#pictures a');
		aantal = images.length;
		if(aantal <= 5) $('moveRight').style.display='none'; else $('moveRight').style.display='block';
		$('moveRight').addEvent('click', function(e){
			x = $('pictures').style.left.toInt();		 
			if(x == "" || isNaN(x)) x= 0;
			images =  $$('#pictures a');
			aantal = images.length;
			maxP = (aantal * -50) + 250;
			newX = x -250;
			$('moveLeft').style.display='block';
			if(newX <= maxP)$('moveRight').style.display='none';
			if(x > maxP){
				$('pictures').effect('left',{ duration: 1000, transition: Fx.Transitions.Bounce.easeOut, wait:true }).start(x, newX);  
			}
			return false;
		});
	}
			
	var links =  $$('#galleryButtons a');
	for (i=0; i<links.length;i++)
	{
		if(links[i].id!="moveLeft" && links[i].id != "moveRight")
		{
			createOver(links[i]);
		}
	}
	
	function createOver(el)
	{
		if (!el) return false;
		el.addEvent('click', function(e){   
			var outeffet = new Fx.Style($('galleryBig'), 'opacity', {duration:1000});
			outeffet.start.delay(0, outeffet, [1,0]);	
			var ineffet = new Fx.Style($('galleryBig'), 'opacity', {duration:1000});
			ineffet.start.delay(1000, ineffet, [0,1]);	
			var cls = function() {
				$('galleryBig').setStyle('background-image',  'url(' + el.href + ')');
			}.delay(1000);
			return false; 
		});	
	}
		
});
*/
