/**************************************************************
*   Copyright: TWIinteractive                                 *
*	Author: Laurent Muchacho                                  *
***************************************************************/

function scroller(name,parentDiv,contentDiv,barDiv,slidderDiv){
this.name=name;
this.s_speed=(bw.ns6)?16:8;
this.timer=setTimeout("",10);
this.on_drag=false;
this.parentDiv=parentDiv;
this.parent_o=createObjCss(this.parentDiv);
this.parent_height=get_Height(this.parent_o);
this.parent_top=yTop_pos(this.parent_o);
this.contentDiv=contentDiv;
this.content_o=createObjCss(this.contentDiv,this.parentDiv);
this.content_style=(bw.ns)? this.content_o : this.content_o.style;
this.content_top=0;
this.content_height=get_Height(this.content_o);
this.content_delta=this.content_height-this.parent_height;
this.content_stop=this.content_delta-(2*this.content_delta);
this.barDiv=barDiv;
this.bar_o=createObjCss(this.barDiv,this.parentDiv);
this.bar_style=(bw.ns)?this.bar_o:this.bar_o.style;
this.bar_height=this.parent_height-(2*13)-11;
//this.bar_style.visibility = (this.content_delta>0)? 'visible':'hidden';
this.slidderDiv=slidderDiv;
this.slidder_o=createObjCss(this.slidderDiv,this.parentDiv);
this.slidder_style=(bw.ns)? this.slidder_o : this.slidder_o.style ;
this.slidder_style.visibility = (this.content_delta>0)? 'visible':'hidden';
this.slidder_top=yTop_pos (this.slidder_o);
this.slidder_o.parentObject=this.name;
	if(bw.ns){
		this.slidder_o.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
	}
this.slidder_o.onmousedown = begin_drag ;
this.slidder_o.onmouseup = end_drag ;
this.content_quotient=this.bar_height/this.content_delta;//
this.slidder_quotient=this.content_delta/this.bar_height;//quotient_dcontent_ddrag
this.slidder_offset= this.slidder_quotient*13
this.scroll=scrolling;
}

function drag_drag(e){
	var str_obj = this.parentObject
	var obj = eval(str_obj);
	var y_pos=(bw.ns||bw.ns6)? e.pageY : event.y;
	var height_diff=obj.parent_top;
	var mouse_pointer=(y_pos-(height_diff+5));
	obj.content_top = (-obj.slidder_quotient*obj.slidder_top)+obj.slidder_offset;
	obj.slidder_top = mouse_pointer 
	if((y_pos<=(height_diff+16))||(y_pos>=obj.parent_height+height_diff-16)){
		return false;
	}
	if (obj.on_drag) {
		obj.content_style.top = obj.content_top 
		obj.slidder_style.top = obj.slidder_top
		return false;
	}else {
	    return true;
	}
}

function begin_drag(e){
var str_obj = this.parentObject
var obj=eval(str_obj);
var which_button=(bw.ns||bw.ns6)?e.which:event.button;
	if (which_button == 1) {
		if(bw.ns){
			this.captureEvents(Event.MOUSEMOVE);
		}
		obj.on_drag=true;
		this.onmousemove=drag_drag;
		return false;
	}else{//right click
		return true;	
	}
}

function end_drag(e){
var str_obj = this.parentObject
var obj=eval(str_obj);
var which_button=(bw.ns||bw.ns6)?e.which:event.button;
	if (which_button == 1) {
		if(bw.ns){
		    this.releaseEvents(Event.MOUSEMOVE);
		}
		obj.on_drag=false;
		this.onmousemove=null;
		return false;
	}else{//right click
		return true;	
	}
}

function scrolling(direction){
	if(direction=='stop'||this.content_delta<=0){
		clearTimeout(this.timer);
		return false;
	}
var str_obj=this.name;
var obj = eval(str_obj);
var str_fn=str_obj+'.scroll("'+direction+'")'
var c_top=this.content_style.top;
var s_top=this.slidder_style.top;
this.content_top = (c_top=="")? this.content_top : parseInt(c_top);
this.slidder_top = (s_top=="")? this.slidder_top : parseInt(s_top);
this.slidder_top=(-this.content_quotient * this.content_top)+13;
	if(direction=='up'){
		if(this.content_top<=this.content_stop || this.content_delta<=0 ){
			clearTimeout(this.timer);
			return false;
		}else{
			this.content_top-=this.s_speed
		}
	}else if(direction=='down' && this.content_top<=0 ){
		this.content_top+=this.s_speed
	}
this.slidder_top=(-this.content_quotient * this.content_top)+13;
if(this.slidder_top<13){
	this.content_top=0;
	this.slidder_top=13
}else if(this.slidder_top>(this.parent_height-24)){
	this.slidder_top=this.parent_height-23
}
this.content_style.top=this.content_top;
this.slidder_style.top=this.slidder_top;
this.timer=setTimeout(""+str_fn+"",20);
return true;
}