/*
 * EverythingScroller
 * 
 * @author Jean-Francois Müller
 * @charset utf-8 
 * 
 * Copyright (c) styled4u.com Jean-Francois Müller, all rights reserved.
 * 
 * Known Bugs:
 * TODO: If the surrounding container has a border defined, 
 *       than problems will occure with reaching the far right end.
 *       The better way is to define another div around the container and 
 *       give it the necessary border.
 *  
 */
function Scroller(b,c,d){this.maxSpeed=(typeof c!="undefined")?c:10;this.refreshrate=(typeof d!="undefined")?d:50;this.ContainerNode=b;this.ContentNode=false;this.LeftScroller=false;this.RightScroller=false;this.bInitiated=false;this.UpScroller=false;this.DownScroller=false;this.curSpeedX=0;this.curSpeedY=0;this.bScrollLeft=false;this.bScrollRight=false;this.bScrollUp=false;this.bScrollDown=false;this.maxScrollX=0;this.maxScrollY=0;this.intervallIndicator=0;var a=this;this.setLeftScroller=function(e){this.LeftScroller=e;this.LeftScroller.onmouseover=function(){a.scrollLeft()};this.LeftScroller.onmouseout=function(){a.stopScrollLeft()}};this.setRightScroller=function(e){this.RightScroller=e;this.RightScroller.onmouseover=function(){a.scrollRight()};this.RightScroller.onmouseout=function(){a.stopScrollRight()}};this.setUpScroller=function(e){this.UpScroller=e;this.UpScroller.onmouseover=function(){a.scrollUp()};this.UpScroller.onmouseout=function(){a.stopScrollUp()}};this.setDownScroller=function(e){this.DownScroller=e;this.DownScroller.onmouseover=function(){a.scrollDown()};this.DownScroller.onmouseout=function(){a.stopScrollDown()}};this.init=function(e){if(this.bInitiated&&!e){return}if(!this.ContainerNode.getElementsByTagName("div")[0]){throw"no necessary inner div is defined!"}this.ContentNode=this.ContainerNode.getElementsByTagName("div")[0];this.ContainerNode.style.position="relative";this.ContentNode.style.position="absolute";this.ContentNode.style.top=0+"px";this.maxScrollX=-(this.ContentNode.offsetWidth-this.ContainerNode.offsetWidth);this.maxScrollY=-(this.ContentNode.offsetHeight-this.ContainerNode.offsetHeight);this.maxScrollX=(this.maxScrollX>=0)?0:this.maxScrollX;this.maxScrollY=(this.maxScrollY>=0)?0:this.maxScrollY;if(this.intervallIndicator){window.clearInterval(this.intervallIndicator)}this.intervallIndicator=window.setInterval(function(){a.scrollIt()},this.refreshrate);this.bInitiated=true};this.scrollIt=function(){if(this.m_bScrollLeft&&this.curSpeedX<=this.maxSpeed){this.curSpeedX+=1}if(this.m_bScrollRight&&this.curSpeedX>=(this.maxSpeed*-1)){this.curSpeedX+=-1}if(this.m_bScrollUp&&this.curSpeedY<=this.maxSpeed){this.curSpeedY+=1}if(this.bScrollDown&&this.curSpeedY>=(this.maxSpeed*-1)){this.curSpeedY+=-1}if(this.curSpeedX!=0&&!this.m_bScrollLeft&&!this.m_bScrollRight){this.curSpeedX+=(this.curSpeedX>0)?-1:1}if(this.curSpeedY!=0&&!this.m_bScrollUp&&!this.bScrollDown){this.curSpeedY+=(this.curSpeedY>0)?-1:1}var e;if(this.curSpeedX!=0){e=parseInt(this.ContentNode.style.left);if(isNaN(e)){e=0}e+=this.curSpeedX;if(e>0){e=0}if(e<this.maxScrollX){e=this.maxScrollX}if(e==0||e==this.maxScrollX){this.curSpeedX=0}this.ContentNode.style.left=e+"px"}if(this.curSpeedY!=0){e=parseInt(this.ContentNode.style.top);if(isNaN(e)){e=0}e+=this.curSpeedY;if(e>0){e=0}if(e<this.maxScrollY){e=this.maxScrollY}if(e==0||e==this.maxScrollY){this.curSpeedY=0}this.ContentNode.style.top=e+"px"}};this.scrollLeft=function(){this.init();this.stopScrollRight();this.m_bScrollLeft=true};this.stopScrollLeft=function(){this.m_bScrollLeft=false};this.scrollRight=function(){this.init();this.stopScrollLeft();this.m_bScrollRight=true};this.stopScrollRight=function(){this.m_bScrollRight=false};this.scrollUp=function(){this.init();this.stopScrollDown();this.m_bScrollUp=true};this.stopScrollUp=function(){this.m_bScrollUp=false};this.scrollDown=function(){this.init();this.stopScrollUp();this.bScrollDown=true};this.stopScrollDown=function(){this.bScrollDown=false}};
