var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	try {
		var pageTracker = _gat._getTracker("UA-1809876-1");
		pageTracker._trackPageview();
	} catch(err) {}
var imgsToLoad = [
	'http://www.lucianoamodio.it/foto/fotografo.jpg',
	'http://www.lucianoamodio.it/foto/header02.jpg',
	'http://www.lucianoamodio.it/foto/header03.jpg',
	'http://www.lucianoamodio.it/foto/book-fotografici.jpg',
	'http://www.lucianoamodio.it/foto/header05.jpg',
	'http://www.lucianoamodio.it/foto/header06.jpg',
	'http://www.lucianoamodio.it/foto/provini-casting.jpg',
	'http://www.lucianoamodio.it/foto/header08.jpg',
	'http://www.lucianoamodio.it/foto/header09.jpg'
];

var image		= '',
	myImages	= '',
	current 	= 0,
	next 		= 0,
	timeToDelay = 2000,
	fxDuration	= 2000,
	containerID = 'imagerotator';
	
var colors		= [ 
					'bbee00',
					'bbef00',
					'bfef00',
					'bfff00',
					'bffe00',
					'bffd00',
					'bffc00',
					'bffb00',
					'bfeb00',
					'beeb00',
					'bdeb00',
					'bceb00',
					'bbeb00',
					'bbec00',
					'cbec00',
					'dbec00',
					'dbed00',
					'dbee00',
					'dbef00',
					'cbee00',
					'bbee00'
					],
	n			= 0;	
window.addEvent('domready', function() {
	
	image		= $$('#'+containerID+' img').getLast();
	myImages = new Asset.images(imgsToLoad, {
		onComplete: function(){
        	changeImg.periodical(timeToDelay*2 + 1000);
    	} 
	});
	
	mails = $$('.mail');
	mails.each(function(email){
		divs = email.getElements('div');
		correctName = '';
		correctDomine = '';
		hasChiocciola = false;
		divs.each(function(el){
			if(el.hasClass('chiocciola'))
			{
				hasChiocciola = true;
			}else if(!hasChiocciola)
				correctName = correctName+el.get('text');
			else
				correctDomine = correctDomine+el.get('text');
			el.dispose();
		});
		emailLink = new Element('a', {'href': 'mailto:'+correctName});
		if(hasChiocciola)
		{
			emailLink.set('html', correctName+'<span class="chiocciola">@</span>'+correctDomine);
			emailLink.set('href', 'mailto:'+correctName+'@'+correctDomine);
			emailLink.inject(email, 'top');
		}
		else
		{
			emailLink.set('html', correctName);
			emailLink.set('href', 'mailto:'+correctName);
			emailLink.addClass('')
			emailLink.inject(email, 'before');
			new Element('span', {'class': 'email'}).wraps(emailLink);
			email.dispose();
		}
	})
	
	var mailMe = $('mailMe');
	if(mailMe)	changeColor.periodical(2000, mailMe);
	
});

function changeColor()
{
	if(n>colors.length-1) n = 0;
	this.setStyle('color', '#'+colors[n]);
	n++;
}

function changeImg(){
	
	next = (current == imgsToLoad.length-1) ? 0 : next+1;
	
	myImages[next].setStyle('opacity', 1).inject(image, 'before');

	image.get('tween', {duration: fxDuration}).start('opacity', 0);

	image 	= myImages[next];
	current = next;
}