/*
Faps 2005-10-12
Wangyou.com
*/

var rbox , rplayer
var o_w, o_h, t_x, t_y, t_p, src_ratio;

function set_reSizeBox(box , player)
{
	t_p = 0;
	rbox = _gObj(box);
	rplayer = _gObj(player);
	if (rplayer.height>0)
	{
		src_ratio = rplayer.width/rplayer.height;
	}
	try
	{
		rbox.OnSelectStart="return false;";
		var ctrl_block = document.createElement("div");
		ctrl_block.id = "ctrl_block";
		ctrl_block.style.cssText = "background:yellow;border:1px orange solid;filter:Alpha(style=0,opacity=10);opacity:0.3;-moz-opacity:0.3;width:20px;height:20px;margin:-22px 0 0 "+(rplayer.width-20)+"px;display:none;"
		ctrl_block.title = "拖动此处可以调整大小哦";
		rbox.appendChild(ctrl_block);
		rbox.onmouseover=function(){ctrl_block.style.display="block";}
		rbox.onmouseout=function(){ctrl_block.style.display="none";}
		ctrl_block.onmouseover=show_border;
		ctrl_block.onmouseout=hide_border;
		//alert(src_ratio);
	}
	catch(e)
	{
		//alert(e.description);
		return null;
	}

	if ((typeof(rbox)!="object") ||(typeof(rplayer)!="object"))
	{
		return null;
	}

	with(ctrl_block)
	{
		//onmousemove = show_border;
		onmousedown = startReSize;
		onmouseup = endReSize;
	}
	with(document.body)
	{
		onmousemove = draw_size;
		onmouseup = endReSize;
		onselectstart = function(){ return false; }
	}
}

function show_border()
{
	with(rbox.style)
	{
		border = "2px #cccccc dashed";
		margin = "2px";
		cursor = "nw-resize";
		width = rplayer.width;
	}
}

function hide_border()
{
	with(rbox.style)
	{
		border = "2px #ffffff solid";
		margin = "2px";
		cursor = "default";
	}
}

function draw_size()
{
	try
	{
		if(t_p)
		{
			var e_x, e_y
			if (typeof(event)=="object")
			{
				e_x = event.clientX - t_x;
				e_y = event.clientY - t_y;
			}
			else
			{
				e_x = argument[0].clientX - t_x;
				e_y = argument[0].clientY - t_y;
			}
			/*
			if ((o_w+e_x<=600) && (o_w+e_x>=120))
			{
				rplayer.width = o_w + e_x;
				rplayer.height = (o_w + e_x)*src_ratio;
			}
			//*/
			if((o_h+e_y<=600) && (o_h+e_y>=120))
			{
				rplayer.height = o_h + e_y;
				rplayer.width = (o_h + e_y)*src_ratio;
			}
			try{
				_gObj("ctrl_block").style.margin="-22px 0 0 "+(rplayer.width-20)+"px";
			}
			catch(e)
			{
				alert(e.description)
			}
		}
	}
	catch(e)
	{
		//alert(e.description);
		endReSize();
		return;
	}
}

function startReSize()
{
	if (event.button==1)
	{
		t_p = 1;
		if (typeof(event)=="object")
		{
			t_x = event.x;
			t_y = event.y;
		}
		else
		{
			t_x = argument[0].x;
			t_y = argument[0].y;
		}
		o_w = rplayer.offsetWidth;
		o_h = rplayer.offsetHeight;
	}
}

function endReSize()
{
	t_p = 0;
	hide_border();
	document.body.onselectstart = "";
}
