var slider_objs = new Array();

function smooth_slide(obj_id, display_area)
{
var x;
var obj = document.getElementById(obj_id);
this.set_height = set_slider_object_height;
this.set_width = set_slider_object_width;
this.set_size = set_slider_object_size;
this.obj = obj;
this.callback = null;//callback_func;
this.end_height = 0;
this.end_width = 0;
this.horiz_resize = true; //width resize;
this.display_obj = document.getElementById(display_area);
if(this.obj != null)
	{
	this.obj.style.width='0px';	
	}
if(this.display_obj != null)
	{	
	this.display_obj.style.clip = 'rect(0,0,0,0)';
	}
this.index = set_slider_object(this);
}

function set_slider_object(obj)
{
var index = slider_objs.length;
slider_objs[index] = obj;
return index;
}

function get_slider_object(index)
{
return slider_objs[index];
}

function set_slider_object_height(high, callback_func)
{
var current_height = 0;
var current_width = 0;
if(this.obj != null)
	{
	current_height = parseInt(this.obj.style.height);
	current_width = parseInt(this.obj.style.width);
	//alert(current_height + "," + current_width);
	}
this.callback = callback_func;
this.horiz_resize = false;
this.end_width = current_width;
this.end_height = high;

if(high != 0)
	{
	this.display_obj.style.clip = 'rect(0,0,0,0)';
	this.obj.style.display = '';
	this.display_obj.style.display = '';
	this.display_obj.style.visibility = 'hidden';
	}

if(this.callback != null)
	{
	//slide operation started;
	this.callback(this, 0);
	if(current_height == high)
		{
		//slide operation is complete
		this.callback(this, 1);
		return;
		}
	}	
resize_smooth_slider_object(this.index);
}

function set_slider_object_width(wide, callback_func)
{
var current_height = 0;
var current_width = 0;
if(this.obj != null)
	{
	current_height = parseInt(this.obj.style.height);
	current_width = parseInt(this.obj.style.width);
	}
this.horiz_resize = true;
this.callback = callback_func;
this.end_height = current_height;
this.end_width = wide;

if(wide != 0)
	{
	this.display_obj.style.clip = 'rect(0,0,0,0)';
	this.obj.style.display = '';
	this.display_obj.style.display = '';
	this.display_obj.style.visibility = 'hidden';
	}

if(this.callback != null)
	{
	//slide operation started
	this.callback(this, 0);
	if(current_width == wide)
		{
		//slide operation is complete	
		this.callback(this, 1);
		return;
		}
	}
resize_smooth_slider_object(this.index);
}

function set_slider_object_size(wide, high, callback_func)
{
var current_height = 0;
var current_width = 0;
if(this.obj != null)
	{
	current_height = parseInt(this.obj.style.height);
	current_width = parseInt(this.obj.style.width);
	}

this.callback = callback_func;
this.end_height = high;
this.end_width = wide;

if(high != 0 || wide != 0)
	{
	this.display_obj.style.clip = 'rect(0,0,0,0)';
	this.obj.style.display = '';
	this.display_obj.style.display = '';
	this.display_obj.style.visibility = 'hidden';
	}

if(this.callback != null)
	{
	//slide operation started	
	this.callback(this, 0);
	if(current_width == wide && current_height == high)
		{
		//slide operation is complete
		this.callback(this, 1);
		return;
		}
	}
resize_smooth_slider_object(this.index);
}

function resize_smooth_slider_object(obj_index)
{
//alert(obj_index);	
var slider_obj = get_slider_object(obj_index);
var refresh_timer = 0;
var delta_y = 0;
var delta_x = 0;

var current_height = 0;
var current_width = 0;
var display_height = 0;
var display_width = 0;
if(slider_obj.obj != null)
	{
	current_height = parseInt(slider_obj.obj.style.height);
	current_width = parseInt(slider_obj.obj.style.width);
	}
else
	{
	return;
	}	
if(slider_obj.display_obj != null)
	{
	display_height = parseInt(slider_obj.display_obj.style.height);
	display_width = parseInt(slider_obj.display_obj.style.width);
	}
else
	{
	return;
	}
if(isNaN(current_height) == false && current_height != null && (slider_obj.horiz_resize == false))
	{
	//alert(current_height);
	if(current_height != slider_obj.end_height)
		{
		delta_y = Math.round((slider_obj.end_height - current_height)/2);	
		if(delta_y != 0)
			{
			var sign = delta_y/Math.abs(delta_y);
			delta_y = Math.min(20, Math.abs(delta_y))*sign;
			current_height += delta_y;
			refresh_timer = 1;
			}
		else
			{
			//alert('hello');
			current_height = slider_obj.end_height;
			if(current_height == 0)
				{
				slider_obj.obj.style.display = 'none';
				slider_obj.display_obj.style.display = 'none';
				slider_obj.display_obj.style.visibility = 'hidden';
				}
			}	
		}

	if(slider_obj.display_obj != null)
		{
		slider_obj.display_obj.style.clip = 'rect(0,'+display_width+','+current_height+',0)';
		}
	if(slider_obj.obj != null)
		{
		slider_obj.obj.style.height = current_height + 'px';
		}
	//slider_obj.display_obj.style.clip.top = ;
	}	

if(isNaN(current_width) == false && current_width != null && (slider_obj.horiz_resize == true))
	{
	//alert('ndfd');
	if(current_width != slider_obj.end_width)
		{
		delta_x = Math.round((slider_obj.end_width - current_width)/2);
		if(delta_x != 0)
			{
			var sign = delta_x/Math.abs(delta_x);
			delta_x = Math.min(20, Math.abs(delta_x))*sign;
			current_width += delta_x;
			refresh_timer = 1;
			}
		else
			{
			current_width = slider_obj.end_width;
			if(current_width == 0)
				{
				slider_obj.obj.style.display = 'none';
				slider_obj.display_obj.style.display = 'none';
				slider_obj.display_obj.style.visibility = 'hidden';
				}
			}
		}
	//var clip_x = Math.abs(slider_obj.end_width - current_width);
	if(slider_obj.display_obj != null)
		{
		slider_obj.display_obj.style.clip = 'rect(0,'+display_width+','+display_height+','+(display_width-current_width)+')';
		}
	if(slider_obj.obj != null)
		{	
		slider_obj.obj.style.width = current_width + 'px';
		}
	//alert(clip_x);
	//slider_obj.display_obj.style.width = current_width + 'px';
	}	

var x = (findPosX(slider_obj.obj));
var wide1 = parseInt(slider_obj.obj.style.width);
var high =  parseInt(slider_obj.display_obj.style.height);
//alert(wide1);
var wide = parseInt(slider_obj.display_obj.style.width);
x = x + wide1 - wide + 1;
slider_obj.display_obj.style.left = x + 'px';
slider_obj.display_obj.style.top = (findPosY(slider_obj.obj) + 1) + 'px';
//slider_obj.obj.style.height = high + 'px';
if(slider_obj.end_width != 0 || slider_obj.end_height != 0)
	{
	slider_obj.display_obj.style.visibility = 'visible';
	}
//alert(delta_x + "," + delta_y + "," + current_width + "," + current_height);



if(refresh_timer == 1)
	{
	if(slider_obj.callback != null)
		{	
		//alert('hell');
		//slide operation is happening
		slider_obj.callback(slider_obj, 2);
		}
	setTimeout('resize_smooth_slider_object('+obj_index+')',50);
	}
else
	{
	if(slider_obj.callback != null)
		{	
		//alert('hell');
		//slide operation is complete
		slider_obj.callback(slider_obj, 1);
		}
	}	
}
