function scroll_up(div_id, scroll_height) {
	$(div_id+'_container').scrollTop = $(div_id+'_container').scrollTop - scroll_height;
	update_scroll(div_id);
}

function scroll_down(div_id, scroll_height) {
	$(div_id+'_container').scrollTop = $(div_id+'_container').scrollTop + scroll_height;
	update_scroll(div_id);
}

function update_scroll(div_id) {
	scroll_ascenseur_height = $(div_id+'_scroll_ascenseur').getDimensions().height;
	ascenseur_height = $(div_id+'_ascenseur').getDimensions().height;
	content_height = $(div_id+'_content').getDimensions().height - main_content_height;
	
	height1 = scroll_ascenseur_height - ascenseur_height;
	scroll_top = $(div_id+'_container').scrollTop;
	postion = Math.round(height1 * (scroll_top / content_height));
	$(div_id+'_ascenseur').style.top = postion;
}

function init_scroll(div_id, scroll_height) {
	
	if (!scroll_height) scroll_height = 20;
	
	main_content_top = $(div_id).cumulativeOffset().top;
	main_content_height = $(div_id).getDimensions().height;
	main_content_width = $(div_id).getDimensions().width;
	
	if (main_content_height == 0) {
		window.setTimeout('init_scroll(\''+div_id+'\', '+scroll_height+')', 1);
		return true;
	}
	
	var new_div = new Element('div', {'id': div_id+'_content'}).update($(div_id).innerHTML);
	var new_div_container = new Element('div', {'id': div_id+'_container', 'style': 'width: '+(main_content_width - 13)+'px; height: '+(main_content_height)+'px; float: left; overflow: hidden;'}).insert(new_div);
	var new_scroll = new Element('div', { 'style': 'width: 13px; height: '+main_content_height+'px; float: right;' }).update(
		'<div style="height: 13px; width: 13px;">'+
		'<img src="http://images.superloterie.net/new/asc_up.gif" width="13" height="13" border="0" onClick="scroll_up(\''+div_id+'\', '+scroll_height+')">'+
		'</div>'+
		'<div id="'+div_id+'_scroll_ascenseur" style="height: '+(main_content_height - 16)+'px; width: 13px; background-image:url(http://images.superloterie.net/new/asc_fond.gif);">'+
		'<img src="http://images.superloterie.net/new/ascenseur.gif" width="13" height="36" border="0" id="'+div_id+'_ascenseur">'+
		'</div>'+
		'<div style="height: 13px; width: 13px;">'+
		'<img src="http://images.superloterie.net/new/asc_down.gif" width="13" height="13" border="0" onClick="scroll_down(\''+div_id+'\', '+scroll_height+')">'+
		'</div>'
	);
	
	$(div_id).update('');
	$(div_id).insert(new_div_container);
	$(div_id).insert(new_scroll);	
	
	$(div_id).observe('DOMMouseScroll', function() {
		if (event.wheelDelta) delta = event.wheelDelta / 120;
		else if (event.detail) delta = event.detail / (-3);
		else delta = 0;
		
		if (delta > 0) scroll_up(div_id, scroll_height);
		else if (delta < 0) scroll_down(div_id, scroll_height);
	});
	$(div_id).observe('mousewheel', function() {
		if (event.wheelDelta) delta = event.wheelDelta / 120;
		else if (event.detail) delta = event.detail / (-3);
		else delta = 0;
		
		if (delta > 0) scroll_up(div_id, scroll_height);
		else if (delta < 0) scroll_down(div_id, scroll_height);
	});
	
	content_top = main_content_top;
	ascenseur_height = $(div_id+'_ascenseur').getDimensions().height;
	scroll_ascenseur_height = $(div_id+'_scroll_ascenseur').getDimensions().height;
	
	content_height = $(div_id+'_content').getDimensions().height - main_content_height;
	
	$(div_id).scrollTop = content_top - main_content_top - (scroll_height * 13);
	
	new Draggable(div_id+'_ascenseur',{
	snap: function(x,y,draggable) {
	  function constrain(n, lower, upper) {
		if (n > upper) return upper;
		else if (n < lower) return lower;
		else return n;
	  }
	 
	  element_dimensions = Element.getDimensions(draggable.element);
	  parent_dimensions = Element.getDimensions(draggable.element.parentNode);
	  return[
		constrain(x, 0, parent_dimensions.width - element_dimensions.width),
		constrain(y, 0, parent_dimensions.height - element_dimensions.height)];
	},
	onDrag: function() {
		ascenseur_top = $(div_id+'_ascenseur').cumulativeOffset().top;
		scroll_ascenseur_top = $(div_id+'_scroll_ascenseur').cumulativeOffset().top;
		scroll_ascenseur_height = $(div_id+'_scroll_ascenseur').getDimensions().height;
		ascenseur_height = $(div_id+'_ascenseur').getDimensions().height;
		content_height = $(div_id+'_content').getDimensions().height - main_content_height;
		
		height1 = scroll_ascenseur_height - ascenseur_height;
		top1 = ascenseur_top - scroll_ascenseur_top;
		position = Math.round(content_height * (top1 / height1));
		$(div_id+'_container').scrollTop = position;
		//$('test').update(position+'-'+$(div_id+'_content').scrollTop);
	}
	});
	
	update_scroll(div_id);
}
