/*
 * wrapScroll
 * Copyright 2007 youmos <youmos.com@gmail.com>
 * http://youmos.com/labs/wrapscroll/
 * 
 * The wrapScroll is licensed under a 
 * Creative Commons Attribution-NonCommercial-ShareAlike License.
 *
 * http://creativecommons.org/licenses/by-nc-sa/3.0/
 *
 * It is provided "as is" and without warranty of any kind. If you wish to continue to use it,
 * free for personal or non-commercial use, $30 for commercial use,
 * or transform and build your script upon this work to distribute.
 * The permission is valid for all future versions of wrapScroll.
*/

/*--- wrapscroll.js ---*/
var wrapScroll=function(){this.initialize.apply(this,arguments);};wrapScroll.prototype={Version:'0.7.0',Interval:500,marginTop:0,marginBottom:0,initialize:function(self,parent,relative){this.Position=wrapPosition.create(self,parent,relative);Event.observe(window,'load',this.onLoadEvent.bind(this));},onLoadEvent:function(){if(this.Position.init()){this.onTimerEvent();}},onTimerEvent:function(){var delay=(this.Position.update(this,true))?20:this.Interval;setTimeout(this.onTimerEvent.bind(this),delay);}};var wrapPosition={create:function(self,parent,relative){var s=new Object();s.elem=self;var p=new Object();p.elem=parent;var r=new Object();r.elem=relative;return wrapPosition.prototype={init:function(){s.obj=document.getElementById(s.elem);p.obj=(p.elem)?document.getElementById(p.elem):s.obj.parentNode;r.obj=(r.elem)?document.getElementById(r.elem):null;return(s.obj&&p.obj);},update:function(proc,tween){var scroll_pos;var scroll_new;s.top=this.offset(s.obj);p.top=this.offset(p.obj);scroll_new=Math.max(this.scroll(),(r.obj)?this.offset(r.obj)+r.obj.offsetHeight:p.top)+proc.marginTop;scroll_new=Math.min((p.top+this.height(p.obj))-(s.obj.offsetHeight+proc.marginBottom),scroll_new);if(scroll_new!=s.top){s.obj.style.top=((tween)?s.top+this.tween(s.top,scroll_new):scroll_new)+'px';return true;}return false;},tween:function(s,e){var a=(e>s)?1:-1;return Math.round((e-s)*0.314)+a;},scroll:function(){return document.body.scrollTop||document.documentElement.scrollTop;},height:function(obj){return obj.offsetHeight||document.body.scrollHeight||document.documentElement.scrollHeight;},offset:function(obj){var off_y=obj.offsetTop;while(obj=obj.offsetParent){off_y+=obj.offsetTop;}return off_y;}}}};