

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;
  }

var intervals=new Array();

var keepSub = 0;
var keepSubFather = 0;
var e;

function doTrans(subNum , endVal ) {
	subObj = $ ("menuSub"+subNum);
	if (subObj){
		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 getSrc(e){
	return (e.srcElement)?(e.srcElement):(e.target);
}

function openSub(subNum,evt){

	if (is_ie5)return;
	var add;
	var subObj = $("menuSub" + subNum);

	if (subObj && allSubs[subNum]){
		clearAllClosings ();
		keepSub = subNum ;
		keepSubFather = allSubs[subNum] ;
		// 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";
		e = (isIE)? (window.event):(evt);
		if (subNum=="9999"){
			togglePromo(true);
		}
		if (allSubs[subNum]=="0"){
			var add = (!is_opera)?(10):(-20);
			subObj.style.top = ( getOffsetTop ($("menuFather" + subNum)) + add) + "px";

			add = (!is_opera)?(-5):(-200);
			//subObj.style.left = ( $("menuFather" + subNum).offsetLeft + add ) + "px";


			subObj.style.left = (getOffsetLeft (getSrc(e))+add) + "px";
			if (subNum==9999)subObj.style.left = (parseInt(subObj.style.left)-46)+"px";

			fatherWidth = $("menuFather" + subNum).scrollWidth;
			fatherWidth = (fatherWidth<130)?(130):(fatherWidth);
			if (is_ie7)fatherWidth=150;
			subObj.style.width =  (fatherWidth ) + "px";


		}else{


			subObj.style.top = getOffsetTop (getSrc(e)) + "px" ;
			subObj.style.left = getOffsetLeft (getSrc(e)) + "px";//+e.srcElement.scrollWidth ;
		}

		lastSubNum = subNum;

		if (ie55up && subObj.filters){
			if (subObj.filters.length>0){
				doTrans(subNum , 100);
			}
		}


	}
}

function closeAllSub(){

	for (var i in allSubs){
		if ($("menuSub" + i)){
			if (i!=keepSub && i!=keepSubFather ) {
				$("menuSub" + i).style.visibility= "hidden";
			}
		}
	}
}

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;
				if (num=="9999"){
					setTimeout (function(){togglePromo(false);}, 500);
				}

				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 togglePromo(toHide){
	$("promoBox").className = toHide?"off":"";
}
