window.addEvent('domready', function(){
	
	var domain = "facal/";
	var images = $$('ul#menu li img[id*="page"]');
	var imagesSRCs = [];
	var imagesOver = [];
	
	images.each(function(image){
		imagesSRCs.push(image.get('src').replace(".png", "_over.png"));
		image.addEvent('mouseover', function(e){
			images.each(function(image, index){
				if(image === e.target){
					imagesOver[index].replaces(e.target);
					imagesOver[index].addEvent('click', function(e){
						var curLocation = window.location.toString();
						curLocation = curLocation.substring(0, curLocation.indexOf(domain) + domain.length)
						var newLocation = curLocation + e.target.get('id');
						window.location = newLocation;
					});
					imagesOver[index].addEvent('mouseout', function(e){
						imagesOver.each(function(imageOver, index){
							if(imageOver === e.target){ images[index].replaces(e.target); }
						});
					});
				}
			});
		});
	});
	
	for(var i = 0; i < imagesSRCs.length; i++){
		var imageOver = new Element('img', {
			src: imagesSRCs[i],
			id: images[i].get('id')
		});
		imagesOver.push(imageOver);
	}
	
});

window.addEvent('load', function(e){
	$$('html')[0].setStyle('opacity', 0);
	$$('html')[0].tween('opacity', 1);
});