//***             Saudi Masters Explorer automatically generated script        ***//
window.attachEvent("onresize", KillAll);
document.all.tags("BODY")[0].attachEvent("onclick", KillAll);

//document.attachEvent ('onselectstart', MenuSelectStart);
//document.attachEvent ('oncontextmenu', MenuSelectStart);

function MenuSelectStart()
{
	return false;
}

var OpendMenusIDs;
var SelectedDropsItemsIDs = new Array();
var mChain;

function mo(MenuID) //mouse over
{
	var x, y;
	x = y = 0;
	var mFrom = MenuID.id.substr(0,4);
	//if(mFrom == "Drop" || mFrom == "Icon" || mFrom == "Arrow" || mFrom == "Baby") return;
	if(mFrom == "Drop") return;
	if(mFrom == "Logo")
	{
		HideAllMenus("Menu", "");
		return;
	}

	var k = MenuID.parentElement.parentElement.offsetParent;
	var m = "Drop" + MenuID.id.substr(4);
	
	var mObj = document.all.item(m);
	if(mObj != null)
	{
		if(mFrom == "Menu")
		{
			var xTable;
			xTable = document.all.item("TopMenuBar");
			if(mObj.style.display == "")
			{
				HideChildMenus("Menu", m);
				return;
			}

			HideAllMenus("Menu", "");
			mObj.style.display = "";
			SelectMenuStyle(MenuID)
			if(mDirection == "0") //arabic direction - RTL
			{
				if(mOrientation == "0") //horizontal
				{
					x = parseInt(k.offsetLeft) - parseInt(mObj.offsetWidth) + parseInt(MenuID.offsetLeft) + parseInt(MenuID.offsetWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetHeight) + parseInt(xTable.style.borderTopWidth);
				}
				else //vertical
				{
					x = parseInt(k.offsetLeft) - parseInt(mObj.offsetWidth) + parseInt(xTable.style.borderTopWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetTop);
				}
			}
			else //english direction - LTR
			{
				if(mOrientation == "0") //horizontal
				{
					x = parseInt(k.offsetLeft) + parseInt(MenuID.offsetLeft);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetHeight) + parseInt(xTable.style.borderTopWidth);
				}
				else //vertical
				{
					x = parseInt(k.offsetLeft) + parseInt(MenuID.offsetWidth) + parseInt(xTable.style.borderTopWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetTop);
				}
			}
		}
		else //Item
		{
			SelectItemStyle(MenuID);
			if(mObj.style.display == "")
			{
				HideChildMenus("Item", m);
				return;
			}

			HideAllMenus("Item", m);
			mObj.style.display = "";
						
			if(mDirection == "0") //arabic direction - RTL
			{
				if(mOrientation == "0") //horizontal
				{
				//done
					x = parseInt(k.offsetLeft) - parseInt(mObj.offsetWidth) + parseInt(mObj.style.borderLeftWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetTop);
				}
				else //vertical
				{
				//done
					x = parseInt(k.offsetLeft) - parseInt(mObj.offsetWidth) + parseInt(mObj.style.borderLeftWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetTop) + parseInt(mObj.style.borderTopWidth);
				}
			}
			else //english direction - LTR
			{
				if(mOrientation == "0") //horizontal
				{
					x = parseInt(k.offsetLeft) + parseInt(MenuID.offsetWidth) + parseInt(mObj.style.borderLeftWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetTop);
				}
				else //vertical
				{
					x = parseInt(k.offsetLeft) + parseInt(MenuID.offsetWidth) + parseInt(mObj.style.borderLeftWidth);
					y = parseInt(k.offsetTop) + parseInt(MenuID.offsetTop);
				}
			}
		}
	
		mObj.style.left = x;
		mObj.style.top = y;
		OpendMenusIDs = OpendMenusIDs + ";" + m;
		if(mFrom == "Menu")
			HideCombos();
	}
	else //no child - hide other childs at same level (cousines)
	{
		if(m.substr(0,4) == "Drop" && mFrom == "Menu") //top menu without drop
		{
			HideAllMenus("Menu", "");
			SelectMenuStyle(MenuID)
			OpendMenusIDs = OpendMenusIDs + ";" + m;
			ShowCombos();
			return;
		}

		if(MenuID.id.substr(0,5) == "Break")
		{
			HideChildMenus("Break", MenuID.id.length - 1);
			return;
		}
		else
			HideChildMenus("Sun", m);
		SelectItemStyle(MenuID);
	}
}

function HideAllMenus(e, xID)
{
	if(OpendMenusIDs != null && OpendMenusIDs != "")
	{
		var mArray = OpendMenusIDs.split(";");
		var i;
		for(i=0; i<mArray.length; i++)
		{
			var xObj = document.all.item(mArray[i]);
			if(xObj != null && xObj != "")
			{
				xObj.style.display = "none";
				var x = eval("Menu" + xObj.id.substr(4,2)); //Menu + 2 numbers
				if(x != null && x != "" && e == "Menu")
					NormalMenuStyle(x);
			}
			else //menus without drops
			{
				var j = mArray[i];
				if(j.length == 6 && j != "")
				{
					var x = eval("Menu" + j.substr(4,2));
					if(x != null && x != "" && e == "Menu")
						NormalMenuStyle(x);
				}
			}
		}
		OpendMenusIDs = "";
	}
	
	if(e == "") return;
	
	//re-show parent
	if(e == "Item")
	{
		var x = 2; //all items are xx - 2 digits
		var mFather = xID.substr(0, xID.length - x); //just to start with
		while(mFather.length >= 6)
		{
			mFather = xID.substr(0, xID.length - x);
			var xObj = document.all.item(mFather);
			if(xObj != null && xObj != "")
			{
				xObj.style.display = "";
				OpendMenusIDs = OpendMenusIDs + ";" + mFather;
			}
			x += 2;
		}
	}
}

function HideChildMenus(e, xID)
{
 	var j;
	if(e == "Break")
	{
		j = xID;
		e = "Sun";
	}
	 else
		j = xID.length;

	var gArray = OpendMenusIDs.split(";"); //Grands Array
	var p;
	for(p=0; p<gArray.length; p++)
	{
		if( (gArray[p].length > j) || (gArray[p].length == j && e == "Sun"))
		{
			var gObj = document.all.item(gArray[p]);
			if(gObj != null && gObj != "")
			{
				gObj.style.display = "none";
				gArray[p] = "";
			}
		}
	}
	OpendMenusIDs = "";
	for(p=0; p<gArray.length; p++)
		OpendMenusIDs = OpendMenusIDs + ";" + gArray[p];
}

function tt(MenuID) //ItemMouseOut
{
	var mIcon = eval("Icon" + MenuID.id.substr(4));
	var mBaby = eval("Baby" + MenuID.id.substr(4));
	var mArrow = eval("Arrow" + MenuID.id.substr(4));

	//Icon
	mIcon.style.backgroundColor = mIconBackColor;
	mIcon.style.borderTopColor = mIconBackColor;
	mIcon.style.borderBottomColor = mIconBackColor;
	
	//Baby
	mBaby.style.backgroundColor = mBabyBackColor;
	mBaby.style.borderTopColor = mBabyBackColor;
	mBaby.style.borderBottomColor = mBabyBackColor;
	mBaby.style.textAlign = mBabyAlign;
	mBaby.style.color = mBabyForeColor;
	mBaby.style.fontSize = mBabyFontSize;
	mBaby.style.fontFamily = mBabyFontFamily;
	mBaby.style.fontWeight = mBabyFontWeight;
	mBaby.style.fontStyle = mBabyFontStyle;
	mBaby.style.textDecoration = mBabyTextDecor;

	//Arrow
	mArrow.style.backgroundColor = mBabyBackColor;
	mArrow.style.color = mArrowForeColor;
	mArrow.style.borderTopColor = mBabyBackColor;
	mArrow.style.borderBottomColor = mBabyBackColor;

	if(mDirection == "0")
	{
		mIcon.style.borderRightColor = mIconBackColor;
		mArrow.style.borderLeftColor = mBabyBackColor;
	}
	else
	{
		mIcon.style.borderLeftColor = mIconBackColor;
		mArrow.style.borderRightColor = mBabyBackColor;
	}
	
	//caught by mouseout remove it from selection array
	if(mChain == "Active") return;
	var j;
	for(j=0; j<SelectedDropsItemsIDs.length; j++)
	{
		if(SelectedDropsItemsIDs[j] == MenuID.id)
			SelectedDropsItemsIDs[j] = "";
	}
}

function ic(mURL, mTarget) //ItemClicked
{
	if(mTarget != "")
		window.open(mURL, "_" + mTarget);
	else
		document.location.href = mURL;
}

function NormalMenuStyle(e)
{
	e.style.backgroundColor = mMenubarBackColor;
	e.style.borderRightColor = mMenubarBackColor;
	e.style.borderBottomColor = mMenubarBackColor;
	e.style.borderLeftColor = mMenubarBackColor;
	e.style.borderTopColor = mMenubarBackColor;
	e.style.textAlign = mMenubarAlign;
	e.style.color = mMenubarForeColor;
	e.style.backgroundImage = mMenubarBackImage;
	e.style.fontSize = mMenubarFontSize;
	e.style.fontFamily = mMenubarFontFamily;
	e.style.fontWeight = mMenubarFontWeight;
	e.style.fontStyle = mMenubarFontStyle;
	e.style.textDecoration = mMenubarTextDecor;
}

function SelectMenuStyle(e)
{
	//MENU STYLE - SELECTED
	e.style.backgroundColor = mSelectedBackColor;
	e.style.borderRightColor = mSelectedBorderColor;
	e.style.borderBottomColor = mSelectedBorderColor;
	e.style.borderLeftColor = mSelectedBorderColor;
	e.style.borderTopColor = mSelectedBorderColor;
	e.style.textAlign = mSelectedAlign;
	e.style.color = mSelectedForeColor;
	e.style.backgroundImage = mSelectedBackImage;
	e.style.fontSize = mSelectedFontSize;
	e.style.fontFamily = mSelectedFontFamily;
	e.style.fontWeight = mSelectedFontWeight;
	e.style.fontStyle = mSelectedFontStyle;
	e.style.textDecoration = mSelectedTextDecor;
	
	ShowSelectedChain(null);
}

function SelectItemStyle(e)
{
	var mIcon = eval("Icon" + e.id.substr(4));
	var mBaby = eval("Baby" + e.id.substr(4));
	var mArrow = eval("Arrow" + e.id.substr(4));
	
	//add this item to selection array if not already exists
	var j, m, mFound, mDrop;
	mFound = false;
	mDrop = false;
	m = mArrow.innerText;
	if(m == "3" || m == "4") mDrop = true;
	for(j=0; j<SelectedDropsItemsIDs.length; j++)
	{
		if(SelectedDropsItemsIDs[j] == e.id)
			mFound = true;
	}
	if(mDrop && !mFound)
	{
		SelectedDropsItemsIDs[SelectedDropsItemsIDs.length] = e.id;
		//SelectedDropsItemsIDs.push(e.id); //save selected items with drops
	}

	if(mDirection == "0")
	{
		mIcon.style.borderRightColor = mSelectedBorderColor;
		mArrow.style.borderLeftColor = mSelectedBorderColor;
	}
	else
	{
		mIcon.style.borderLeftColor = mSelectedBorderColor;
		mArrow.style.borderRightColor = mSelectedBorderColor;
	}
	
	//Icon
	mIcon.style.backgroundColor = mSelectedBackColor;
	mIcon.style.borderTopColor = mSelectedBorderColor;
	mIcon.style.borderBottomColor = mSelectedBorderColor;
		
	//Baby
	mBaby.style.backgroundColor = mSelectedBackColor;
	mBaby.style.borderTopColor = mSelectedBorderColor;
	mBaby.style.borderBottomColor = mSelectedBorderColor;
	mBaby.style.textAlign = mSelectedAlign;
	mBaby.style.color = mSelectedForeColor;
	mBaby.style.fontSize = mSelectedFontSize;
	mBaby.style.fontFamily = mSelectedFontFamily;
	mBaby.style.fontWeight = mSelectedFontWeight;
	mBaby.style.fontStyle = mSelectedFontStyle;
	mBaby.style.textDecoration = mSelectedTextDecor;

	//Arrow
	mArrow.style.backgroundColor = mSelectedBackColor;
	mArrow.style.color = mSelectedForeColor;
	mArrow.style.borderTopColor = mSelectedBorderColor;
	mArrow.style.borderBottomColor = mSelectedBorderColor;

	if(mChain == "Active") return;
	ShowSelectedChain(e);
}

function ShowSelectedChain(e)
{
	mChain = "Active";
	var k;
	
	if(e == null)
		k = "";
	else
		k = e.id;
	
	//clear selected ones
	var i;
	for(i=0; i<SelectedDropsItemsIDs.length; i++)
	{
		if(SelectedDropsItemsIDs[i] != "" && SelectedDropsItemsIDs[i] != k)
		{
			var mObj = document.all.item(SelectedDropsItemsIDs[i]);
			tt(mObj);
		}
	}
	SelectedDropsItemsIDs.length = 0;

	if(e == null) //called from menu; no chaining is required
	{
		mChain = "";
		return;
	}
	
	//activate new chain
	var x = e.id;
	var y = e.id.length - 2;
	while(y >= 8)
	{
		m = x.substr(0, y);
		var xObj = document.all.item(m);
		if(xObj != null && xObj != "")
		{
			SelectItemStyle(xObj)
		}
		y -= 2;
	}
	mChain = "";
}

function KillAll()
{
	HideAllMenus("Menu", "");
	ShowCombos();
}

function HideCombos()
{
	var mCombos = document.all.tags("SELECT");
	if(mCombos != null)
	{
		for(var i=0; i<mCombos.length; i++)
		{
			if(mCombos[i].style.visibility != "hidden")
				mCombos[i].style.visibility = "hidden";
		}
	}
}

function ShowCombos()
{
	var mCombos = document.all.tags("SELECT");
	if(mCombos != null)
	{
		for(var i=0; i<mCombos.length; i++)
			mCombos[i].style.visibility = "visible";
	}
}
