var actual = getAnchor();
var padding = 0;

window.addEvent('resize', function(){
	repadding();
	actual = getAnchor();
	go(actual);
	
});

window.addEvent('domready', function() {
	
	
	repadding();
	actual = getAnchor();
	/*go(actual);*/
	
	
	/* Gooo */		
	$$(".goo").addEvent('click', function(e){
		e.stop();
		//Pharsejo el anchor
		var re = new RegExp('#[a-z0-9\_\-]+');
		var m = re.exec(this.href);
		
		//goto anchor
		if (m) {
			//Elimino #
			var s ="";	for (i = 0; i < m.length; i++) {s = s + m[i] + "\n";	} 
			s= s.replace(/#/, "");
			s= s.replace(/\n/, "");
			
			//Go!!
			go(s);
			actual = s;
		} 
		
	});
	
	//Fade
	$$('.fade').addEvents({
	    'mouseover': function(){
			$$('.'+this.rel).fade(0.4);
			this.fade(1);
			//$((this.rel)).addClass('hover');
	    },
	    'mouseout': function(){
			$$('.'+this.rel).fade(0.15);
			//$((this.rel)).removeClass('hover');
		}
	});
	
	//HSpot
	$$('.hspot').addEvents({
		'mouseover': function(){
			this.fade(1);

		},
		'mouseout': function(){
			this.fade(0.6);

		}
	});
	
	
});

/* Funcions */
function go(to) {
	repadding() 
	var myFx = new Fx.Scroll($(document), {
		wait: false,
		duration: 1000,
		offset: {'x': (110-padding), 'y': 0},
		transition: Fx.Transitions.Quad.easeInOut
	}).toElement($(to));	

}	

function getAnchor() {
	var loc = String(document.location);
	var idx = loc.indexOf('#');
	return -1 == idx ? "" : loc.substring(idx + 1);
} 

function repadding() {
	dimension = window.getSize();
	if ( (padding = (dimension.x - 1000 )/2) < 1 ) { padding = 0; };
}