
var intervals=new Array();

var keepSub = 0;
var lastSubNum = 0;
var keepSubFather = 0;
var e;

function doTrans(subNum , endVal ) {
	subObj = $("menuSub"+subNum);
	if (subObj && subObj.filters){
		if (subObj.filters[0].opacity < endVal){
			subObj.filters[0].opacity = parseInt (subObj.filters[0].opacity) + 33;
			setTimeout ("doTrans("+subNum+","+endVal+")" , 20);
		}else{
			subObj.filters[0].opacity = endVal;
		}
	}else{

	}
}

function flipFatherImg(fatherNum){
	if ((((keepSubFather && !(keepSubFather.indexOf(lastSubNum) > -1))) || !keepSubFather) && lastSubNum>0 ){
			lastSubNumHide = lastSubNum;
			while (allSubs[lastSubNumHide])
			{
				if (document.images["menuFatherIMG_"+lastSubNumHide])
					document.images["menuFatherIMG_"+lastSubNumHide].src = fatherOffImgs["fatherImg"+lastSubNumHide].src ;
				lastSubNumHide =  allSubs[lastSubNumHide];
				
			}
	}
	lastSubNumHide = fatherNum;
	while (allSubs[lastSubNumHide])
	{
		if (document.images["menuFatherIMG_"+lastSubNumHide])
			document.images["menuFatherIMG_"+lastSubNumHide].src = fatherOnImgs["fatherImg"+lastSubNumHide].src ;
		lastSubNumHide =  allSubs[lastSubNumHide];
	}
	//if (document.images["menuFatherIMG_"+fatherNum]){
		//document.images["menuFatherIMG_"+fatherNum].src =  fatherOnImgs["fatherImg"+fatherNum].src ;

}
function flipFatherImgPages(fatherNum){
	if ((((keepSubFather && !(keepSubFather.indexOf(lastSubNum) > -1))) || !keepSubFather) && lastSubNum>0 ){
			lastSubNumHide = lastSubNum;
			while (allPages[lastSubNumHide])
			{
				if (document.images["menuFatherIMG_"+lastSubNumHide])
					document.images["menuFatherIMG_"+lastSubNumHide].src = fatherOffImgs["fatherImg"+lastSubNumHide].src ;
				lastSubNumHide =  allPages[lastSubNumHide];
				if (allSubs[lastSubNumHide])
					flipFatherImg(lastSubNumHide);
					break;
			}
	}
	lastSubNumHide = fatherNum;
	while (allPages[lastSubNumHide])
	{
		if (document.images["menuFatherIMG_"+lastSubNumHide])
			document.images["menuFatherIMG_"+lastSubNumHide].src = fatherOnImgs["fatherImg"+lastSubNumHide].src ;
		lastSubNumHide =  allPages[lastSubNumHide];
		if (allSubs[lastSubNumHide])
				flipFatherImg(lastSubNumHide);
				break;		
	}
	//if (document.images["menuFatherIMG_"+fatherNum]){
		//document.images["menuFatherIMG_"+fatherNum].src =  fatherOnImgs["fatherImg"+fatherNum].src ;

}
function closeLastSub (subNum,evt){
	if (is_ie5)return;
	var add;
	//var subObj = $("menuSub" + subNum);
	var isInnerSub = (allPages[subNum]!='0');
	if (allPages[subNum]){
		//clearAllClosings ();
		keepSub = subNum ;
		subNumCurr = subNum;
		keepSubFather = "";
		while (allPages[subNumCurr])
		{
			keepSubFather = keepSubFather + allPages[subNumCurr] + ",";
			if (allPages[subNumCurr]){
				subNumCurr = allPages[subNumCurr];
			}
		}
		// closes all menus and children, except for keepSub
		closeAllSub();
		flipFatherImgPages(subNum);
	}
}

function openSub(subNum, evt){
	if (is_ie5)return;
	var add;
	var subObj = $("menuSub" + subNum);
	var isInnerSub = (allSubs[subNum]!='0');
	if (subObj && allSubs[subNum]){
		clearAllClosings ();
		keepSub = subNum ;
		subNumCurr = subNum;
		keepSubFather = "";
		while (allSubs[subNumCurr])
		{
			keepSubFather = keepSubFather + allSubs[subNumCurr] + ",";
			if (allSubs[subNumCurr]){
				subNumCurr = allSubs[subNumCurr];
			}
		}
			
		// closes all menus and children, except for keepSub
		closeAllSub();

		if (is_ie && ie55up){
			if (subObj.filters.length>0){
				subObj.filters[0].opacity = 0;
			}
		}
		subObj.style.visibility = "visible";
		var add  = 0;
		if (allSubs[subNum]=="0"){
			//add = (!is_opera)?(15):(0);

			add = (isIE)?(43):(30);

			subObj.style.top = ( getOffsetTop ($("menuFather" + subNum)) + add) + "px";

			add = 0;
			subObj.style.left = ( getOffsetLeft($("menuFather" + subNum)) + add) + "px";

			//fatherWidth = $("menuFather" + subNum).scrollWidth;
			//fatherWidth = 226;
			//subObj.style.width =  (fatherWidth ) + "px";


		}else{
			e = (isIE)? (window.event):(evt);
			var src = (e.srcElement)?(e.srcElement):(e.target);
			if (src.tagName=="IMG"){
				src=src.parentElement;
			}
			if (src)
			{
				add = 0;
				subObj.style.top = (getOffsetTop (src) + add) + "px" ;

				add = 2;
				subObj.style.left = (getOffsetLeft (src) + src.scrollWidth + add) +"px";
			}
		}

		flipFatherImg(subNum);

		lastSubNum = (keepSubFather>0)?(keepSubFather):(subNum);

		if (ie55up && subObj.filters){
			if (subObj.filters.length>0){
				doTrans(subNum , 100);
			}
		}


	}
}

function closeAllSub(){
	//alert (keepSubFather);
	//var tmpArr = new Array();
	//tmpArr = keepSubFather.split (',');
	for (var i in allSubs){
		if ($("menuSub" + i)){
			if (i!=keepSub && ((keepSubFather && !(keepSubFather.indexOf(i) > -1)) || !keepSubFather))  {
				$("menuSub" + i).style.visibility= "hidden";
				flipFatherImg(-1);
			}
		}
	}
}



var closeTimeoutAr = [] ;
var lastTimeoutId = 0;
function checkIfClose (num, evt){
	if (is_ie5)return;
	clearAllClosings ();
	e = (isIE)? (window.event):(evt);

	if (e){
		eEl = (isIE)?(e.toElement):(e.relatedTarget);
		if (eEl){
			eId = eEl.id.toLowerCase();
			// every html element must have an id with prefix "menu" to avoid automatic closnig when rolling out from it.
			if (eId.indexOf ("menu")!=0 ){

				keepSub = 0;
				keepSubFather = 0;

				lastTimeoutId = setTimeout (function(){closeAllSub(); } ,500 );
				closeTimeoutAr[closeTimeoutAr.length] = lastTimeoutId;


			}
		}
	}
}


function clearAllClosings(){
	do {
		//alert (closeTimeoutAr[0]);
		clearTimeout (closeTimeoutAr.shift());
	}
	while (closeTimeoutAr.length>0);
}






function getOffsetLeft (el) {
	if (!el)return ;
  var ol = el.offsetLeft;
  while ((el = el.offsetParent) != null)
    ol += el.offsetLeft;
  return ol;
}


function getOffsetTop (el) {
if (!el)return ;
  var ol = el.offsetTop;
  while ((el = el.offsetParent) != null)
    ol += el.offsetTop;
  return ol;
}
/*
if (document.captureEvents ){
	if(Event.MOUSEOUT ) {
		document.captureEvents( Event.MOUSEOUT);
	}
	if(Event.KEYDOWN ){
		document.captureEvents( Event.KEYDOWN );
	}
	if(Event.CLICK){
		document.captureEvents( Event.CLICK);
	}
}
*/
function Array_shift() {
  var A_s = 0
  var response = this[0]
  for (A_s = 0; A_s < this.length-1; A_s++) {
   this[A_s] = this[A_s + 1]
   }
  this.length--
  return response
  }

if (typeof (Array.prototype.shift) == "undefined") {
  Array.prototype.shift = Array_shift;
  }
