// Requires MooTools
// Fixes the navigation bar (aka left-bar) to the left of the screen, while vertically it
// acts as position:fixed
function fixNaviBar() {
	// Let's scroll the bar left when the user scrolls right. That compensates for the position fixed
	var leftBar = $('left-bar');
	var f = function() {	
		leftBar.setStyle('left', -window.getScroll().x);
	};
	window.addEvents({'load': f, 'scroll': f, 'resize': f});
}

// Requires MooTools
// Adds the smooth scrolling to all the inner anchors
function addSmoothScrolls() {
	var isInnerAnchor = new RegExp("\#([^/]+)$"); // Check and match the end of the URL since IE always gives absolute URLs
	var innerAnchors = $$('a').filter(function(a,index,array) {
			return isInnerAnchor.test(a.getAttribute('href'));
		});
	innerAnchors.each(function(a,index,array) {
		try {
			var posOrigen = a.getPosition();
			var posTarget = $(isInnerAnchor.exec(a.getAttribute('href'))[1]).getPosition(); // The target anchors have the name as id as well
			var duration = Math.max(1000, 0.7 * Math.abs(posOrigen.y - posTarget.y));
			new SmoothScroll({
				links: new Array(a), 
				fps: 25, 
				duration: duration, 
				offset: {x: -posTarget.x, y: 0}, 
				transition: Fx.Transitions.Quad.easeInOut 
			});
		} catch(err) {/* Let's ignore the error */}
	});
}

window.addEvent('domready', function() {
	try { fixNaviBar(); } catch(err) {}
});

window.addEvent('load', function() {	try { addSmoothScrolls(); } catch(err) {} });
