(function(){
	var init=function(){
		var tags=document.getElementsByTagName('*'),doms=[],intervalo=false,timeout=false,time=20;
		for(var i=0;i<tags.length;i++){
			if(tags[i].getAttribute('rel')!=null){
				if(tags[i].getAttribute('rel')=='subir'){
					doms.push(tags[i]);
				}
			}
		}
		for(var i=0;i<doms.length;i++){
			doms[i].onclick=function(){
				var id=this.getAttribute('href').split('#')[1],dom=document.getElementById(id),offsetTop=0,elm=dom;
				while(elm.offsetParent){
					offsetTop+=elm.offsetTop;
					elm=elm.offsetParent;
				}
				if(intervalo)clearInterval(intervalo);
				if(timeout)clearTimeout(timeout);
				var act=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
				time=time>1?time:2;
				intervalo=setInterval(function(){
					if(act==offsetTop){clearInterval(intervalo);clearTimeout(timeout);}
					act=(act>offsetTop?Math.floor(act-((act-offsetTop)/time)):Math.ceil(act+((offsetTop-act)/time)));
					window.scrollTo(0,act);
				},1);
				timeout=setTimeout(function(){clearInterval(intervalo);},time*1000); // ESTO ES POR SI SE TRABA, EN UNOS SEGUNDOS LO LIBERAMOS
				return false;
			};
		}
	};
	if(window.addEventListener){
		window.addEventListener('load',init,false);
	}else if(window.attachEvent){
		var f=function(){init.call(window,window.event);};
		window.attachEvent('onload',f);
		window[init.toString()+'load']=f;
	}else{
		window['onload']=init;
	}
})();
