$(function() {
		$('.text .photo').lightBox();
		$('.text .lightbox').lightBox();
});


function Rotator(newName, newId)
{
	var name = newName;
	var id = newId;
	var objects;
	var timer=null;
	var anim=false;
	var step=0;
	var open=0;
	var pause=false;
	var direction=0;
	var prev;
	
	function getAmount()
	{
		return objects.length+1;
	}
	this.getAmount = getAmount;
	
	function animation()
	{
		step+=Math.abs(direction)*5;
		try {
			objects[open].style.opacity=step/100;
			objects[prev].style.opacity=(100-step)/100;
			objects[open].style.filter='alpha(opacity='+step+')';
			objects[prev].style.filter='alpha(opacity='+(100-step)+')';
		} catch (e) {}
		if(step>=100)
		{
			anim=false;
			objects[prev].style.display='none';
			objects[prev].style.position='static';
			if(!pause) { timer = setTimeout(name+'.go(1)', 4000); }
		}
		else
		{
			timer = setTimeout(name+'.animation()', 50);
		}
	}
	this.animation = animation;
	
	function go(newDirection)
	{
		if(!anim&&getAmount()>1)
		{
			direction = newDirection;
			clearTimeout(timer);
			anim=true;
			step=0;
			prev=open;
			open+=direction;
			if(open>=objects.length){open=0;}
			else if(open<0) { open=objects.length-1; }
			objects[prev].style.position='absolute';
			objects[open].style.display='block';
			try { document.getElementById('rotator-navigator').getElementsByTagName('li')[prev].className=''; } catch (e) {}
			document.getElementById('rotator-navigator').getElementsByTagName('li')[open].className='selected';
			try {
				objects[prev].style.opacity=1;
				objects[open].style.opacity=0;
				objects[prev].style.filter='alpha(opacity=100)';
				objects[open].style.filter='alpha(opacity=0)';
			} catch (e) {}
			timer = setTimeout(name+'.animation()', 50);
		}
	}
	this.go = go;
	
	function openImage(nr) { go(nr-open); }
	this.openImage = openImage;
	
	function init()
	{
		objects = document.getElementById(id).getElementsByTagName('li');
		if(objects.length>0)
		{
			for(a=0;a<objects.length;a++)
			{
				objects[a].style.display='none';
			}
			open=0;
			objects[0].style.display='block';
			timer = setTimeout(name+'.go(1)', 5500);
		}
	}
	this.init=init;
	
}
