var tempX = "";
var tempY = "";
function addMyDataBefore(type, id, name, iconId){
	tempX = $(iconId).offsetLeft;
	tempY = $(iconId).offsetTop;
	beforeMove(iconId);
	onad(iconId);

//	return false;
	window.setTimeout("addMyData('"+type+"', '"+id+"', '"+name+"', '"+iconId+"');", 500);
	return false;
}
function addMyData(type, id, name, imgId){
	setOffline(imgId, name);
	if (!activeMyDataMenu)
		displayMyData(type, id);
	else
		ajaxReloadMyDataArea("", type, id);
}
// displays the 
var activeMyDataMenu = false;
function displayMyData(type, id){
	if (activeMyDataMenu){
		with ($("my_data_div_area").style){
			display = "none";
			visibility = "hidden";
		}
		$("my_data_img").src = "/images/basic/my_data.jpg";
		activeMyDataMenu = false;
		ajaxReloadMyDataArea("", type, id);
	} else {
		ajaxReloadMyDataArea("", type, id);
		with ($("my_data_div_area").style){
			display = "inline";
			visibility = "visible";
		}
		$("my_data_img").src = "/images/basic/my_date_active.jpg";
		activeMyDataMenu = true;
	}
}
function setOffline(id, name){
	$(id).onclick="";
	$(id).title=name;
	$(id).style.cursor="";
	
	iconMoveBack(id);
}
var mnaTime = "";
var XX = "";
var YY = "";
var endX = "";
var endY = "";
var xstep = "";
var ystep = "";
var delay_time = "";
var chX = "";
var chY = "";
var ohX = "";
var ohY = "";
var yon = "";
var ie = "";
var ns6 = "";
function beforeMove(clipIcon){
	if ($(clipIcon)){
		XX = $(clipIcon).offsetLeft; // start X position of the scrolling object
		YY = $(clipIcon).offsetTop; // start Y position of the scrolling object
		parentX = $("my_data_div_holder").parentNode.offsetLeft;
		parentY = $("my_data_div_holder").parentNode.offsetTop;
		endX = $("my_data_div_holder").offsetLeft + 95 + parentX; // end X position of the scrolling object
		endY = $("my_data_div_holder").offsetTop + 30 + parentY;// end Y position of the scrolling object
//		alert(XX+" "+YY);
//		alert(parentX+" "+parentY);
//		alert(endX+" "+endY);
		
		if (hasSpecialDiv(clipIcon)){
			endX = getRecursiveOffset(clipIcon, endX, true);
			endY = getRecursiveOffset(clipIcon, endY, false);
		}
//		alert(XX+" "+YY);
		
		xstep = Math.ceil((XX - endX) / 40); // moving step x
		ystep = Math.ceil((endY - YY) / 40); // moving step y
		delay_time = 1; // delay in miliseconds
		chX = 0;
		chY = 0;
		ohX = 0;
		ohY = 0;
		yon = 0;
		ie = (navigator.userAgent.indexOf("Firefox") == -1) ? true : false;
		ns6 = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;
		if (ie){ // IE
			$(clipIcon).style.left = XX;
			$(clipIcon).style.top = YY;
		} else if (ns6){ // FF
			$(clipIcon).style.left = XX + "px";
			$(clipIcon).style.top = YY + "px";
		}
	}
}
function reloc1(clipIcon){
	if (yon == 0){
		XX = XX - xstep;
		YY = YY + ystep;
	}
	if (ie)	{
		// IE
		chX = document.body.clientWidth;
		chY = document.body.clientHeight;
	}else if(ns6){
		// FF
		chX = window.innerWidth;
		chY = window.innerHeight;
	}
	if ($(clipIcon)){
		ohX = $(clipIcon).offsetWidth;
		ohY = $(clipIcon).offsetHeight;
	} else {
		ohX = 0;
		ohY = 0;
	}
	if (XX >= endX){
		yon = 1;
		if ($(clipIcon)){
			$(clipIcon).style.visibility = "hidden";
		}
	}
//	alert(XX+" "+YY+" "+endX+" "+endY+" "+yon);
	if (XX >= (chX - ohX)){
		yon = 0;
		XX = (chX - ohX);
		YY = (chY + ohY);
	}
	if ($(clipIcon)){
		$(clipIcon).style.left = XX + "px";
		$(clipIcon).style.top = YY + "px";
	}
}
function onad(clipIcon){
	if ($(clipIcon))
		loopfunc(clipIcon);
}
function loopfunc(clipIcon){
	reloc1(clipIcon);
	if (yon == 0){
		mnaTime = setTimeout("loopfunc('"+clipIcon+"')", delay_time);
	}
}
function iconMoveBack(clipIcon){
	window.clearTimeout(mnaTime);
	$(clipIcon).style.left = tempX + "px";
	$(clipIcon).style.top = tempY + "px";
	$(clipIcon).src = "/images/basic/fond_clip_minus.gif";
	$(clipIcon).style.marginLeft = "0px";
	$(clipIcon).style.marginTop = "0px";

	var text_id = "text" + clipIcon.substring(clipIcon.indexOf("_"));
	if ($(text_id) && $(clipIcon).title_add){
		$(text_id).innerHTML = "&nbsp;" + $(clipIcon).title_add;
	}
}

function getRecursiveOffset(objId, dim, left){
//alert("usao sa "+dim);
	var node = $(objId).parentNode;
	while (node.className != "special"){
		node = node.parentNode;
	}

	if (left){
		dim -= node.offsetLeft;
	} else {
		dim -= node.offsetTop;
	}

	return dim;
}

function hasSpecialDiv(objId){
	var ret = false;

	var node = $(objId).parentNode;
	while (node != null && node.className != "special"){
		node = node.parentNode;
	}

	if (node != null && node.className == "special"){
		ret = true;
	}

	return ret;
}
