function ImageLoader_Add(_sId, _oImg, _sClass)
{
	var imgPreloader = new Image();
	imgPreloader.setAttribute('jsid', _sId);
	imgPreloader.onload=function(e){
		var jsid = this.getAttribute('jsid');
		if (document.getElementById(jsid))
		{
			var img = document.getElementById(jsid);
			img.src = this.src;
			if (_sClass != null)
				COMMON_SetClass(img, _sClass);
		}
		return false;
	}
	_oImg.src = "./img/loading.png";
	return imgPreloader;
}

function ImageLoader_Activate(imgPreloader, realSrc)
{
	imgPreloader.src = realSrc;
}

function Image_AddHoverChangeSrc(obj, firstSrc, finalSrc)
{
	//imgHoverChangeList[imgHoverChangeListCount] = obj;
	obj.onmouseover = function(e) {
		obj.src = finalSrc;
	}
	obj.onmouseout =  function(e) {
		obj.src = firstSrc;
	}
	//imgHoverChangeListCount++;
}

function initImageHoverChange()
{
	if (document.getElementById("menuSettings"))
		Image_AddHoverChangeSrc(document.getElementById("menuSettings"), "./img/settings.png","./img/settings_hover.png");
	if (document.getElementById("menuCom"))
		Image_AddHoverChangeSrc(document.getElementById("menuCom"), "./img/communication.png", "./img/communication_hover.png");
	if (document.getElementById("menuLogOut"))
		Image_AddHoverChangeSrc(document.getElementById("menuLogOut"), "./img/logout.png", "./img/logout_hover.png");
	if (document.getElementById("box_open_close"))
		Image_AddHoverChangeSrc(document.getElementById("box_open_close"), "./img/box_openall.png", "./img/box_openall_hover.png");
	if (document.getElementById("play_button"))
		Image_AddHoverChangeSrc(document.getElementById("play_button"), "./img/play_button.png", "./img/play_button_hover.png");
	if (document.getElementById("universeOptions"))
		Image_AddHoverChangeSrc(document.getElementById("universeOptions"), "./img/universe_options.png", "./img/universe_options_hover.png");
}

function registerCard(divName)
{
	var div = document.getElementById(divName);
	if (!div)
		return;
	var imgList = div.getElementsByTagName("img");
	for (i = 0; i < imgList.length; i++)
	{
		if (COMMON_GetClass(imgList[i]) == "friend_profil")
		{
			imgList[i].onmouseover = image_generatecard;
			imgList[i].onmouseout = image_cancelgeneraterequest;			
		}
	}
	document.getElementById('linkOwner').onmouseover = image_generatecard;
}

function registerCardCommunication()
{
	var imgList = document.getElementsByTagName('img');
	for (i = 0; i < imgList.length; i++)
	{
		sClass = COMMON_GetClass(imgList[i]);
		if (sClass == "avatarNotif"
			|| sClass == "avatarNotifComment"
			|| sClass == "friend_profil")
		{
			imgList[i].onmouseover = image_generatecard;
			imgList[i].onmouseout = image_cancelgeneraterequest;			
		}
	}
	document.getElementById('linkOwner').onmouseover = image_generatecard;
}
function image_generatecard(e)
{
	target = COMMON_GetTarget(e);
	document.getElementById('easyfavcard').style.display = "none";
	document.getElementById('easyfavcard').style.top = COMMON_GetTopPos(target);
	left = COMMON_GetLeftPos(target);
	if (left + 230 > COMMON_GetClientWidth())
		left = left - 230 + target.offsetWidth;
	document.getElementById('easyfavcard').style.left = left;
	if (g_cached_card[this.parentNode.getAttribute('title')])
	{
		g_show_card_json = g_cached_card[this.parentNode.getAttribute('title')];
		if (g_timer_show_card)
			clearTimeout(g_timer_show_card);		
		g_timer_show_card = setTimeout('Delayed_Show_Card()', 1000);
	}
	else
		AJAX_SendRequest('./ajax/users.php?n=' + escape(this.parentNode.getAttribute('title')));
}

function image_cancelgeneraterequest(e)
{
	if (g_timer_show_card)
		clearTimeout(g_timer_show_card);
	g_timer_show_card = null;
}
