/* 
 Easy Scroll v1.0
 written by Alen Grakalic, provided by Css Globe (cssglobe.com)
 please visit http://cssglobe.com/post/1495/easy-scroll-accessible-content-scroller
 Modified by Compass Mobile Solutions
 */


this.easyscroll2 = function(prefijo_id_contenedor_scroll, height){

    // id of the container element 
    var id = prefijo_id_contenedor_scroll;
    // navigation buttons text
    var nav = ["Scroll", "", ""];
    
    //	id for each navigation button (OPTIONAL)
    var navId = ["leerScroll", "btnDown", "btnUp"];
	
	// altura destino (valor de top) al pulsar el boton de scroll
	var newHeight = 0;
    
    //
    // END CONFIG
    // do not edit below this line (unless you want to of course :) )
    //
    
    var obj = document.getElementById(id);
    
    obj.up = false;
    obj.down = false;
    
    var container = document.createElement("div");
    var parent = obj.parentNode;
    container.id = "easyscroll";
    parent.insertBefore(container, obj);
    parent.removeChild(obj);
    
    container.style.position = "relative";
    container.style.height = height + "px";
    container.style.overflow = "hidden";
    obj.style.position = "absolute";
    obj.style.top = "0";
    obj.style.left = "0";
    container.appendChild(obj);
    
	var btns = new Array();
	var ul = document.createElement("ul");
	ul.id = "easyscrollnav";
	for (var i = 0; i < nav.length; i++) {
		var li = document.createElement("li");
		li.innerHTML = nav[i];
		li.id = navId[i];
		btns.push(li);
		ul.appendChild(li);
	};
	parent.appendChild(ul);
	btns[1].onclick = function(){ // abajo
		obj.down = true;
		obj.up = false;
		newHeight -= height;
	};
	btns[2].onclick = function(){ // arriba
		obj.up = true;
		obj.down = false;
		newHeight += height;
	};
	if (obj.offsetHeight < height) { 
		// si el contenido no cabe en el espacio reservado= height, poner botones scroll si no, no.
		ul.style.display="none"
	}
    
    
	// funcion start
    this.start2 = function(){
        var newTop;
        var objHeight = obj.offsetHeight;		
        var top = obj.offsetTop;
				
//		objeto._x += (cordenadadestino - objeto._x)*0.10;
		
        if (obj.down) {
            newTop = ((objHeight + top) > height) ? top + ((newHeight-top)*0.19) : top;
            obj.style.top = newTop + "px";
			if (newTop <= newHeight || (objHeight + top) <= height) {
	            obj.down = false;
				newHeight= -objHeight + height;
			}
			
        }        
        if (obj.up) {
            newTop = (top < 0) ? top + ((newHeight-top)*0.19) : top;
            obj.style.top = newTop + "px"; 
			if ((top>=0)){  // objHeight + top < height
 	          	obj.up = false;
				newHeight=0;
			}
        };
    }; // fin start 
    obj.interval = setInterval("start2()", 1);
};

