//var menuTimeoutVar = new Array(2);
//   menuTimeoutVar(1) = null;
//   menuTimeoutVar(2) = null;
menuTimeoutVar = null;
var menuTime = 500;
var numOfMenus = 3;
var timeOutVar;
var scrollSpeed;
var scrollOffset;


function loadImages() {
       var docu = document;
        var arraySz = 22;
        var firstarraySz = 10;
  if (docu.images)
    {
       if (!docu.PW_img) {
 	     docu.PW_img = new Array(arraySz);
 		 for(j=1; j<=arraySz; j++) {
            docu.PW_img[j] = new Image;
        } // for
		for (j=1; j<firstarraySz; j++)
		{
	        docu.PW_img[j].src = "Images/top/btn_" + (j) + "n.jpg";
     	}  // for loading
		for (j=11; j<=22; j++)
		{
	        docu.PW_img[j].src = "Images/top/btn_" + (j) + "n.jpg";
     	}  // for loading
	   }
	}
//    var theBody = $("bbb");
//    theBody.observe('resize', myresize());

    showNews();

}

function myresize() {
	alert("resize");
}

function showNews()
{
//	alert("called");
var browserName=navigator.appName; 
if (browserName=="Netscape")
{ 
     scrollSpeed = 100;
//	 scrollOffset  = 90;
	 scrollOffset  = 110;
}
else 
{ 
 if (browserName=="Microsoft Internet Explorer")
 {
     scrollSpeed = 110;
//     scrollSpeed = 1500;
//	 scrollOffset  = 98;
	 scrollOffset  = 118;  // must be > theLoc.y
 }
 else
  {
     scrollSpeed = 100;
	 scrollOffset  = 120;
   }
}



    	clearTimeout(timeOutVar);
			var newsObj = $("theNews");
				 newsObj.style.display="";
				 newsObj.visibility = "show";
				 refPoint = 	"btn_8";
				 btnHeight = Element.getDimensions($(refPoint)).height;
				 absButton = absPosLocal($(refPoint));
                 newsObj.style.top = absButton.y + btnHeight+40;
//				 alert(newsObj.style.top);
  				 newsWidth = Element.getDimensions(newsObj).width;
                btnWidth = Element.getDimensions($(refPoint)).width;
   				widthOffset = newsWidth - btnWidth
                newsObj.style.left = absButton.x - widthOffset+20;

              timeOutVar =       setTimeout("doScroll()",1000);
//               doScroll();
}

function doScroll() {
			var newsObj = $("theScrolled");
			theLoc = 	absPosLocal(newsObj);
			contentHeight = Element.getDimensions($("theScrolled")).height;
			contenairHeight = Element.getDimensions($("theNews")).height;
          if (contenairHeight < contentHeight)
          {
  //			alert(theLoc.y);
            theNewLoc = theLoc.y-scrollOffset;
			newsObj.style.top  =  theNewLoc+"px";
//			alert(newsObj.style.top);

           // if we scrolled too much start of the beginning
//		   $("debugDiv").innerHTML = "theLoc.y [" + theLoc.y + "] contentHeight [ " + contentHeight + "] [" + theNewLoc+"px scollOffset" + scrollOffset + "[[[]]]";
		   if (Math.abs(theNewLoc) > contentHeight)
		   {
				newsObj.style.top  =  contenairHeight + "px";
         timeOutVar =      setTimeout("doScroll()",1000);
//				alert("now");
	      } else {
         timeOutVar =      setTimeout("doScroll()",scrollSpeed);
		  }
//    alert(theNewLoc);
        }

}

function stopScroll() {
	clearTimeout(timeOutVar);
}

function resumeScroll() {
//	alert("here");
         timeOutVar =  setTimeout("doScroll()",100);
}
  
  function ImgOn (picNum)
{
   fImage = eval("document.btn_" + picNum);
   fImage.src = "Images/top/btn_" + picNum + "n.jpg";
}

function ImgOff (picNum)
{
   fImage = eval("document.btn_" + picNum);
   fImage.src = "Images/top/btn_" + picNum  + ".jpg";
}


function showSub(theID, theBtn, menuNum) {
//		alert(theID);
		var obj = $(theID);
		hideOtherMenus(menuNum);
		clearTimeOut();
//		alert(obj);
		if (!obj) {
//			return false;
		}
		else if (obj.style) {
			if (obj.style.display == "none") {
				 obj.style.display="";
				 obj.visibility = "show";
				 btnHeight = Element.getDimensions($(theBtn)).height;
//				alert("here1");
				 btnWidth = Element.getDimensions($(theBtn)).width;
				 menuWidth = Element.getDimensions($(theID)).width;
				 widthOffset = menuWidth - btnWidth
//					 alert("btnWidth: " + btnWidth + " menuWidth: " + menuWidth + " widthOffset: " + widthOffset);
//				 alert(menuWidth);
				 absButton = absPosLocal($(theBtn));
                 obj.style.top = absButton.y + btnHeight;
                 obj.style.left = absButton.x - widthOffset;
//				 obj.onMouseOut=timeout1(theID);
//				 obj.onMouseOver=clearTimeOut();
			} else {
//				obj.style.display="none";
			}
		}
}

function hideOtherMenus(curId) 
{
	for (idx=1; idx <= numOfMenus; idx++)
	{
		if (idx != curId)
		{
             hideSub("sub" + idx)
		}
	}
	// also also a special case for 7
	if (curId != 6)
	{
             hideSub("sub6")
	}
}

function clearTimeOut() {
//	alert("clear");
   if (menuTimeoutVar) {
	   clearTimeout(menuTimeoutVar);
	   menuTimeoutVar = null;
   }
}

function timeout1(theID)
{
		var obj = $(theID);
//		alert(theID);
		menuTimeoutVar = setTimeout(function() {hideSub(theID)},menuTime);
//				obj.style.display="none";
}

function hideSub(theID) {
		var obj = $(theID);
		obj.style.display="none";
}

function absPosLocal(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}  // if
	return {x:curleft, y:curtop};
}

function hltMenu(theID)
{
		var obj = $(theID);

//		var attStr = "";
//	    for (var key in obj.style) {
//		    attStr = attStr + key + " " + obj.style[key] + "\n";
//	    }
//		alert(attStr);
//		obj.style.background="#5192ca";
//        alert(obj.style.background);
        var txtObj = $(theID + "_txt");
		txtObj.style.color = "ffffff";
        txtObj.style.fontWeight = "bold";
//        obj.style.cursor='hand';
        obj.setStyle({background:"#5192ca", cursor:"pointer"});

}

function dehltMenu(theID)
{
		var obj = $(theID);
//		alert(obj);
//		obj.style.background="#ffffff";
        var txtObj = $(theID + "_txt");
		txtObj.style.color = "000000";
        txtObj.style.fontWeight = "normal";
//        obj.style.cursor='default';
//         obj.setStyle({cursor:"default"});
        obj.setStyle({background:"#ffffff", cursor:"default"});

}

function showVideo(sng)
{
     openTheWindow('videoPlayer.asp','RYranchPlayer','width=500,height=450,resizable=no,status=no');
}

function openTheWindow (theURL,winName,features)
{
   theWindow = window.open(theURL,winName,features);
}


