var d=document,isCSS,isW3C,isIEMac,si,se=false,sb=new Array();
function getObject(obj){var theObj;if(typeof obj == "string")theObj = d.getElementById(obj);else theObj = obj;return theObj;}
function getStyle(obj){var theObj = getObject(obj);if (theObj && isCSS) theObj = theObj.style;return theObj;}
function shiftBy(obj, deltaX, deltaY){var theObj = getStyle(obj);if (theObj) {if (isCSS) {var units = (typeof theObj.left == "string") ? "px" : 0;theObj.left = getLeft(obj) + deltaX + units;theObj.top = getTop(obj) + deltaY + units;}}}
function getLeft(obj){var elem = getObject(obj);var result = 0;if (d.defaultView) {var style = d.defaultView;var cssDecl = style.getComputedStyle(elem, "");result = cssDecl.getPropertyValue("left");} else if (elem.currentStyle) {result = elem.currentStyle.left;} else if (elem.style) {result = elem.style.left;} else if (isNN4) {result = elem.left;}return parseInt(result);}
function getTop(obj){var elem = getObject(obj);var result = 0;if (d.defaultView) {var style = d.defaultView;var cssDecl = style.getComputedStyle(elem, "");result = cssDecl.getPropertyValue("top");} else if (elem.currentStyle) {result = elem.currentStyle.top;} else if (elem.style) {result = elem.style.top;} else if (isNN4) {result = elem.top;}return parseInt(result);}
function getElementStyle(e, ie, css){var elem = getObject(e);if (elem.currentStyle) {return elem.currentStyle[ie];} else if (window.getComputedStyle) {var compStyle = window.getComputedStyle(elem, "");return compStyle.getPropertyValue(css);}return "";}
function so(obj, up, dw, speed){this.index = sb.length;this.speed = speed;this.arr = [obj, 'ow'+this.index, 'iw'+this.index];this.obj = getObject(obj);this.obj.height = parseInt(getElementStyle(obj, "height", "height"));this.obj.width  = parseInt(getElementStyle(obj, "width", "width"));this.obj.content = '<div id="'+this.arr[1]+'"><div id="'+this.arr[2]+'">'+this.obj.innerHTML+'</div></div>';this.obj.innerHTML = this.obj.content;for (var i=0; i<=2; i++) {this.arr[i] = getObject(this.arr[i]);if (i>0) {this.arr[i].style.position = "absolute";this.arr[i].style.left = "0px";this.arr[i].style.top = "0px";this.arr[i].style.width = this.obj.width + "px";if (!isIEMac) this.arr[i].style.overflow = "hidden";if (i==1) this.arr[i].style.height = this.obj.height + "px";} else {this.arr[i].style.position = "relative";}}this.ow = this.arr[1];this.ow.height = parseInt(this.arr[1].style.height);this.iw = this.arr[2];this.iw.fontSize = parseInt(getElementStyle(this.arr[2], "fontSize", "font-size"));this.iw.height = (this.arr[2].scrollHeight) ? this.arr[2].scrollHeight : this.arr[2].offsetHeight;this.up = d.getElementById(up);this.dw = d.getElementById(dw);this.up.index = this.index;this.dw.index = this.index;this.in_so = in_so;}
function in_so(){this.up.onmousedown = handleScrollStart;this.up.onmouseup = handleScrollStop;this.up.oncontextmenu = blockEvent;this.dw.onmousedown  = handleScrollStart;this.dw.onmouseup = handleScrollStop;this.dw.oncontextmenu = blockEvent;}
function handleScrollStop(){se = false;}
function blockEvent(evt){evt = (evt) ? evt : event;evt.cancelBubble = true;return false;}
function handleScrollStart(evt){var evt, fontSize, speed, target, index;evt = (evt) ? evt : event;target = (evt.target) ? evt.target : evt.srcElement;index = target.index;speed = sb[index].speed;fontSize = sb[index].iw.fontSize;fontSize = (target.id.indexOf("up") != -1) ? fontSize : -fontSize;se = true;scrollBy(index, parseInt(fontSize/speed));si = setInterval("scrollBy(" + index + ", " + parseInt(fontSize/speed) + ")", 100);evt.cancelBubble = true;return false;}
function scrollBy(index, px){var s = sb[index];var elem = s.iw;var top = parseInt(elem.style.top);var scrollHeight = parseInt(s.iw.height);var height = s.ow.height;if (se && top + px >= -scrollHeight + height && top + px<=0) shiftBy(elem, 0, px);else clearInterval(si);}
function in_sb(){isCSS = (d.body && d.body.style) ? true : false;isW3C = (isCSS && d.getElementById) ? true : false;isIEMac = (navigator.appName.indexOf("Explorer") != -1 && navigator.userAgent.indexOf("Mac") != -1);sb[0] = new so("sw0", "up0", "dw0", 9);sb[0].in_so();}
