// JavaScript Document
var timeout;

function stripScroll(move,dir) {
	if (dir == null) dir = "x";

	var iLayerLeft;
	var iLayerTop;
	var iLayerWidth;
	var iLayerHeight;
	var oScroller = $("#scroller");
 
	if (dir == "x") {
		if ( iLayerLeft == null ) iLayerLeft = oScroller.position().left;

		if ( iLayerWidth == undefined ) iLayerWidth = oScroller.width();
		
		if ( iLayerWidth <= oScroller.parents("div").width() ) return;
	} else {
		if ( iLayerTop == undefined ) iLayerTop = oScroller.position().top;
		
		if ( iLayerHeight == undefined ) iLayerHeight = oScroller.height();
		
		if ( iLayerHeight <= oScroller.parents("div").height() ) return;
	}

	if (move == 0) {
		if ( timeout != 'undefined' ) {
  	  clearTimeout( timeout );
	  }
		if (dir == "x") {
			if ( iLayerLeft > 20 ) oScroller.css("left","20px");
			else if ( iLayerWidth + iLayerLeft < oScroller.parents("div").width() - 20 ) oScroller.css("left",(oScroller.parents("div").width() - 20 - iLayerWidth) + "px");
		} else {
			if ( iLayerTop > 20 ) oScroller.css("top","20px");
			else if ( iLayerHeight + iLayerTop < oScroller.parents("div").height() - 20 ) oScroller.css("top",(oScroller.parents("div").height() - 20 - iLayerHeight) + "px");
		}
	} else {
		
		if (dir == "x") {
			iLayerLeft = iLayerLeft + move;

			if ( iLayerLeft > 20 ) {
				stripScroll(0,dir);
				return;
			} else if ( iLayerWidth + iLayerLeft < (oScroller.parents("div").width() - 20) ) {
				stripScroll(0,dir);
				return;
			}
			
			oScroller.css("left",iLayerLeft+"px");
		} else {
			iLayerTop = iLayerTop + move;

			if ( iLayerTop > 20 ) {
				stripScroll(0,dir);
				return;
			} else if ( iLayerHeight + iLayerTop < (oScroller.parents("div").height() - 20) ) {
				stripScroll(0,dir);
				return;
			}			
			
			oScroller.css("top",iLayerTop+"px");
		}
				
		timeout = setTimeout("stripScroll("+ move +",'"+ dir +"')", 10);
	}
}
