
floating_areas = new Array();
floating_elements = new Array();
floating_obj = null;
floating_index = null;
floating_clone = null;

floating_element_offsetX = 20;

/** IE7 FIX **/
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

function getCursorX(event){
	var val;
	if (event.pageX != null){val = event.pageX;}
	else{val=event.clientX + document.documentElement.scrollLeft;}
	return val;
}

function getCursorY(event){
	var val;
	if (event.pageY != null){val = event.pageY;}
	else{val = event.clientY + document.documentElement.scrollTop;}
	return val;
}

function register_float(id1,id2)
{
	obj = document.getElementById(id1);
	obj.onmouseover = new Function('show_float(this)');
	obj.onmouseout = new Function('hide_float(this)');
	obj.onmousemove = move_float;
	floating_areas.push(obj);
	obj = document.getElementById(id2);
	floating_elements.push(obj);
	obj.style.display = 'none';
}

function register_float_all()
{
	var loop = 1;
	while(document.getElementById('area_'+loop)){
		if (document.getElementById('float_'+loop)){
			register_float('area_'+loop,'float_'+loop);
		}
		loop++;
	}
}

function show_float(obj)
{
	floating_index = floating_areas.indexOf(obj);
	floating_clone = document.body.appendChild(floating_elements[floating_index].cloneNode(true));
}

function hide_float(obj)
{
	document.body.removeChild(floating_clone);
	floating_clone = null;
	floating_index = null;
}

function move_float(e)
{
	if (e != null) //IE fix
		event = e;
	if (floating_clone == null)
		return;
	floating_clone.style.display = 'block';
	
	if ((floating_element_offsetX + getCursorX(event) + floating_clone.clientWidth) < document.body.clientWidth)
		floating_clone.style.left = (getCursorX(event) + floating_element_offsetX) + 'px';
	else
		floating_clone.style.left = (getCursorX(event) - floating_element_offsetX - floating_clone.clientWidth) + 'px';
		
	floating_clone.style.top  = getCursorY(event) + 'px';
}

/* HIDE PANEL */
function floating_panel_display_check(name,size)
{
	if (document.body.clientWidth > size){
		document.getElementById(name).style.display = 'block';
	} else {
		document.getElementById(name).style.display = 'none';
	}
}