function Yonca_Scroll_Markup(controlkey){
	this.scroll = Dom.get(controlkey + '_scroll');
	this.scrollkey = null;
	this.content = Dom.get(controlkey + '_content');
	this.plist = Dom.get(controlkey + '_list');
	this.controlkey = controlkey;
	this.scroll_max_height = 152;
	this.ddcontrol = null;
	this.move_scroll = 0;
	this.first_y = 0;
	this.last_y = 0;
	this.inited = false;
	this.is_scrollable = true;
	
	this.pre_init();
}

Yonca_Scroll_Markup.prototype.pre_init = function()
{
	if (!this.is_operational())
	{
		return false;
	}
	
	if (Dom.getStyle(this.content.parentNode, 'display') != 'none')
	{
		Event.on(window, 'load', this.init, this, true);
	}
	
	this.mouse_move_init();
};

Yonca_Scroll_Markup.prototype.is_operational = function()
{
	return !(!this.content || !this.scroll || !this.plist || this.inited);	
};

Yonca_Scroll_Markup.prototype.init = function()
{
	if (this.content.scrollHeight == 0)
	{
		this.is_scrollable = false;
		return false;
	}
	
	var move_scroll = this.content.scrollHeight - this.content.offsetHeight;
	if (move_scroll <= 0)
	{
		this.is_scrollable = false;
		return false;
	}
	
	var height = Math.max(1, this.content.offsetHeight - Math.min(move_scroll, this.scroll_max_height)), 
		div = document.createElement('div'),
		scroll_top = div.cloneNode(false), 
		scroll_bottom = div.cloneNode(false), 
		scroll_center = div.cloneNode(false);

	scroll_top.className = 'top';
	scroll_bottom.className = 'bottom';
	scroll_center.className = 'center';

	Dom.setStyle(scroll_center, 'height', '20px');
	
	div.className = 'scrollcontrol';
	
	div.appendChild(scroll_top);
	div.appendChild(scroll_center);
	div.appendChild(scroll_bottom);
	
	this.scrollkey = div;
	
	this.scroll.appendChild(this.scrollkey);
	this.scroll_init();
	this.move_scroll = move_scroll;
	
	this.ddinit();
	
	Event.on(window, 'resize', this.scroll_init_iedelay, this, true);
	
	this.inited = true;
};

Yonca_Scroll_Markup.prototype.ddinit = function()
{
	if (this.ddcontrol)
	{
		this.ddcontrol.unreg();
	}
	
	this.ddcontrol = new YAHOO.util.DD(this.scrollkey);
	
	var left = 0, right = 0, top = 0, bottom = this.content.offsetHeight - this.scrollkey.offsetHeight;
	
	this.ddcontrol.setXConstraint(left, right);
	this.ddcontrol.setYConstraint(top, bottom);
	
	var _this = this;
	this.ddcontrol.onDrag = function()
	{
		_this.scroll_move();
	};
};

Yonca_Scroll_Markup.prototype.mouse_move_init = function()
{
	Event.on(this.plist, 'mousemove', this.mouse_move, this, false);
	Event.on(this.plist, 'mouseover', this.mouse_over, this, false);	
};

Yonca_Scroll_Markup.prototype.hide = function()
{
	if (!this.is_scrollable)
	{
		return false;
	}
	
	Dom.setStyle(this.scrollkey, 'display', 'none');	
};

Yonca_Scroll_Markup.prototype.show = function()
{
	if (!this.is_scrollable)
	{
		return false;
	}
	
	if (!this.inited)
	{
		this.init();
	}
	
	Dom.setStyle(this.scrollkey, 'display', '');	
};

Yonca_Scroll_Markup.prototype.scroll_init = function()
{
	var xy = Dom.getXY(this.scroll);
	Dom.setXY(this.scrollkey, xy, false);
	
	this.first_y = xy[1];
};

Yonca_Scroll_Markup.prototype.scroll_init_iedelay = function()
{
	var _this = this;
	setTimeout(function()
	{ 
		_this.last_y = 0;
		_this.scroll_init();
		_this.ddinit();
	}, 0);	
};

Yonca_Scroll_Markup.prototype.scroll_move = function()
{
	var coordy = Dom.getY(this.scrollkey) - this.first_y;
	var move = (this.move_scroll / this.scroll_max_height) * coordy;
	this.content.scrollTop = move;
};

Yonca_Scroll_Markup.prototype.mouse_move = function(e)
{
//	var y = Event.getPageY(e), diff = (-1 * (this.last_y - y) / 2), newscroll = this.content.scrollTop + diff;
//	this.content.scrollTop = newscroll;
//	this.last_y = y;
};

Yonca_Scroll_Markup.prototype.mouse_over = function(e)
{
	this.last_y = Event.getPageY(e);
};
