var _x;
var _y;
window.onmousemove = TrackMousePosition;
function TrackMousePosition(e)
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		_x = window.event.clientX;
		_y = window.event.clientY;
	}
	else
	{
		_x = e.clientX;
		_y = e.clientY;
	}
}

function ChangeImage(img, link)
{
	img.src = link;
}

function MoveImage(img, x, y)
{
	var left = parseInt(img.parentNode.style.left);
	var top = parseInt(img.parentNode.style.top);
	img.parentNode.style.left = left + x + "px";
	img.parentNode.style.top = top + y + "px";
}

function ChangeClassName(obj, className)
{
	obj.className = className;
}

function RightClick(e)
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(event.button == 2)
		{
			ShowContextMenu(event.srcElement.id, event.clientX, event.clientY);
		}
	}
	else
	{
		if(e.which == 3)
		{
			ShowContextMenu(e.currentTarget.id, e.clientX, e.clientY);
		}
	}
}
var shownMenu;

function ShowContextMenu(targetedElement, _coordX, _coordY)
{
	if(shownMenu != null)
		shownMenu.style.display = 'none';
		
	var contextMenu = document.getElementById("div" + targetedElement);
	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		_x = window.event.clientX;
		_y = window.event.clientY;
	}
	
	if(_coordX == undefined)
		_coordX = _x;
	if(_coordY == undefined)
		_coordY = _y;
	
	//_coordX = _coordX - parseInt(contextMenu.style.width);
	
	contextMenu.style.left = _coordX + "px";
	contextMenu.style.top = _coordY + "px";
	
	contextMenu.style.display = '';
	
	shownMenu = contextMenu;
	
	opacityTween = new OpacityTween(contextMenu, Tween.reqularEaseIn, 0, 99, 1);
	opacityTween.start();
	
	//setTimeout('shownMenu.style.display = "none"', 10000);
}

function CloseMenu()
{
	if(shownMenu != undefined)
	{
		shownMenu.style.display = 'none';
	}
}

function AdViewImagePreview(pic)
{
	var output = document.createElement("div");
	output.id ="divImagePreview";
	var tmp_output = '<div id="divImagePreviewBack" style="position: absolute; width: 100%; height: 100%; top: 0px; left: 0px; background-color: #50010e; text-align: center; z-index: 101;"><img src="images/large_logo.png" alt="" /></div>';
	tmp_output += '<div style="position: absolute; left: 50px; z-index: 115; height: 100%; width: 100px;" id="ImagePreview"><img style="height: 100%; width: auto;" src="' + pic + '" alt="" /></div>';
	tmp_output += '<div style="position: absolute; right: 10px; top; 10px; z-index: 106; background-color: white; color: black; cursor: pointer;" onclick="CloseImagePreview();">إغلاق</div>';
	output.innerHTML = tmp_output;
	document.body.appendChild(output);
	var imgPrv = document.getElementById("ImagePreview");
	var width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
	var imgWidth = parseInt(imgPrv.style.width);
	imgWidth = 200;
	var newLeft = (width - imgWidth) / 2;
	imgPrv.style.left = newLeft + "px";
}

function CloseImagePreview()
{
	document.body.removeChild(document.getElementById("divImagePreview"));
}

function operateDisplayForElement(element)
{
	var ele = document.getElementById(element);
	if(ele.style.display == '')
		ele.style.display = 'none';
	else
		ele.style.display = '';
}

function ShowMCC(_type, _id)
{
	window.open("mc.swf?_type=" + _type + "&_id=" + _id, "mc", "status=0, height=580, width=730, resizable=0"); 
}