var slideSpeed_out = 10;	// Steps to move sub menu at a time ( higher = faster)
var slideSpeed_in = 10;
var slideTimeout_out = 25;	// Microseconds between slide steps ( lower = faster)
var slideTimeout_in = 10;	// Microseconds between slide steps ( lower = faster)
var fixedSubMenuWidth = 180;	// Width of sub menu items - A number(width in pixels) or false when width should be dynamic
var dhtmlgoodies_menuObj;   // Reference to the menu div 
var currentZIndex = 1000; 
var liIndex = 0; 
var visibleMenus = new Array(); 
var activeMenuItem = false; 
var timeBeforeAutoHide = 1200; // Microseconds from mouse leaves menu to auto hide. 
var dhtmlgoodies_menu_arrow = '/images/on.png'; 
var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false; 
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox')>=0?true:false; 
var navigatorVersion = navigator.appVersion.replace(/.*?MSIE ([0-9]\.[0-9]).*/g,'$1')/1; 
var menuBlockArray = new Array(); 
var menuParentOffsetLeft = false;    

//Get the current location Info
//var thisLocationArray = location.href.split(/\//);
var fileNameThis = location.pathname;//thisLocationArray[thisLocationArray.length-1];

if(fileNameThis.indexOf('?')>0)fileNameThis = fileNameThis.substr(0,fileNameThis.indexOf('?'));
if (fileNameThis.indexOf('#') > 0) fileNameThis = fileNameThis.substr(0, fileNameThis.indexOf('#'));
if (fileNameThis.lastIndexOf('htm') == -1) {
    fileNameThis = fileNameThis + 'index.htm';
}

if (document.getElementsByName) {
    var metaArray = document.getElementsByName('AlternatePage');
    for (var i = 0; i < metaArray.length; i++) {
        fileNameThis = metaArray[i].content;
    }
}

//For firefox, we need to get the leftPos of the menu table since leftpos of relative items
//is measured against the nearest aboslutely positioned item
var ffTopMenuLeftPos = 0;
if (isFirefox) {
    var tableArr = document.getElementsByTagName("Table")
    for (var i = 0; i < tableArr.length; i++) {
        if (tableArr[i].className == "menu") {
            ffTopMenuLeftPos = tableArr[i].offsetLeft;
            break;
        }
    }
}
	

/** 
* Return specific style attribute for an element 
* 
* @param Object el = Reference to HTML element 
* @param String property = Css property 
* @private 
*/        
function getStyle(el,property) 
{        

  if (document.defaultView && document.defaultView.getComputedStyle) { 

     var retVal = null;              
     var comp = document.defaultView.getComputedStyle(el, ''); 
     if (comp){ 
        retVal = comp[property]; 
          
        if(!retVal){ 
           var comp = document.defaultView.getComputedStyle(el, null); 
           retVal = comp.getPropertyCSSValue(property); 
        }          
     }

     if (retVal == null)
        retVal=''; 
      
     return el.style[property] || retVal; 
  } 
  if (document.documentElement.currentStyle && MSIE){    
     var value = el.currentStyle ? el.currentStyle[property] : null; 
     return ( el.style[property] || value ); 
                                          
  } 
  return el.style[property];              
} 
      
function getTopPos(inputObj) 
{   
    var returnValue = inputObj.offsetTop;
    if (isFirefox)
        returnValue=returnValue +1 ;
    else
        returnValue = returnValue +2 ;
    //while((inputObj = inputObj.offsetParent) != null)
    return returnValue;
} 
    
function getLeftPos(inputObj) 
{ 
    var returnValue = inputObj.offsetLeft; 
  
    var topOfMenuReached = false; 
    while((inputObj = inputObj.offsetParent) != null){ 
        if(inputObj.parentNode.id=='dhtmlgoodies_menu') {
            topOfMenuReached=true; 
        }
        if(topOfMenuReached && !inputObj.className.match(/menuBlock/gi)){ 
            var style = getStyle(inputObj,'position'); 
            if(style=='absolute' || style=='relative')
                return returnValue; 
        } 
        returnValue += inputObj.offsetLeft; 
    } 

    return returnValue; 
} 

function OpenDemoWindow(theURL,width,height)
  {window.open(theURL,'demo','left=50,top=50,screenX=0,screenY=10,width='+width+',height='+height+',location=no');}
  
function showHideSub() 
{ 

    var attr = this.parentNode.getAttribute('currentDepth'); 
    if(navigator.userAgent.indexOf('Opera')>=0){ 
        attr = this.parentNode.currentDepth; 
    } 
    
    this.className = 'currentDepthover'; 
    
    if(activeMenuItem && activeMenuItem!=this){ 
         activeMenuItem.className=activeMenuItem.className.replace(/over/,''); 
    } 
    activeMenuItem = this; 

    var numericIdThis = this.id.replace(/[^0-9]/g,''); 
    var exceptionArray = new Array(); 
    // Showing sub item of this LI 
    var sub = document.getElementById('subOf' + numericIdThis); 
    if(sub){ 
        visibleMenus.push(sub); 
        sub.style.display=''; 
        sub.parentNode.className = sub.parentNode.className + 'over'; 
        exceptionArray[sub.id] = true;
     
        //display the arrow at the end of the line
        if (activeMenuItem.getElementsByTagName('IMG')[0])
            activeMenuItem.getElementsByTagName('IMG')[0].style.display = "inline";
    }
    
    // Showing parent items of this one        
    var parent = this.parentNode; 
    while(parent && parent.id && parent.tagName=='UL'){ 
        visibleMenus.push(parent); 
        exceptionArray[parent.id] = true; 
        parent.style.display=''; 
      
        var li = document.getElementById('dhtmlgoodies_listItem' + parent.id.replace(/[^0-9]/g,'')); 
        if(li.className.indexOf('over')<0) {
            li.className = li.className + 'over'; 
        }
        //display the arrow at the end of the line
        if (li.getElementsByTagName('IMG')[0])
            li.getElementsByTagName('IMG')[0].style.display = "inline";
        parent = li.parentNode; 
      
    }  

    hideMenuItems(exceptionArray); 
} 
   
function initShowHideSub() 
{ 
    var attr = activeMenuItem.parentNode.className;
    attr = attr.substring(9); 
    if(navigator.userAgent.indexOf('Opera')>=0){ 
        attr = activeMenuItem.parentNode.currentDepth; 
    } 
      
    activeMenuItem.className = 'currentDepthover';
    activeMenuItem.getElementsByTagName('A')[0].className = 'currentDepthover';

    //display the arrow at the end of the line
    if (activeMenuItem.getElementsByTagName('IMG')[0])
        activeMenuItem.getElementsByTagName('IMG')[0].style.display = "inline";
           
    var numericIdThis = activeMenuItem.id.replace(/[^0-9]/g,''); 
    var exceptionArray = new Array(); 
    // Showing sub item of this LI 
    var sub = document.getElementById('subOf' + numericIdThis);
    if (sub) {
        visibleMenus.push(sub);
        sub.style.display = '';
        sub.parentNode.className = sub.parentNode.className + 'over';
        exceptionArray[sub.id] = true;
    }
        
    // Showing parent items of this one 
       
    var parent = activeMenuItem.parentNode; 
    while(parent && parent.id && parent.tagName=='UL'){ 
         visibleMenus.push(parent); 
         exceptionArray[parent.id] = true; 
         parent.style.display=''; 
          
         var li = document.getElementById('dhtmlgoodies_listItem' + parent.id.replace(/[^0-9]/g,'')); 
         if(li.className.indexOf('over')<0) {
            li.className = li.className + 'over';
         }
         //display the arrow at the end of the line
         if (li.getElementsByTagName('IMG')[0])
            li.getElementsByTagName('IMG')[0].style.display = "inline";
         parent = li.parentNode; 
          
    } 
       
    hideMenuItems(exceptionArray); 
} 

function hideMenuItems(exceptionArray) 
{ 
    /* Hiding visible menu items */ 
    var newVisibleMenuArray = new Array();
    for (var no = 0; no < visibleMenus.length; no++)
    {
        if (visibleMenus[no].className != 'menuBlock1' && visibleMenus[no].id)
        {
            if (!exceptionArray[visibleMenus[no].id])
            { 
                var el = visibleMenus[no].getElementsByTagName('A')[0]; 
                visibleMenus[no].style.display = 'none';         
                var li = document.getElementById('dhtmlgoodies_listItem' + visibleMenus[no].id.replace(/[^0-9]/g,''));
                if (li.className.indexOf('over') > 0) 
                {
                    //hide the arrow at the end of the line
                    //li.getElementsByTagName('IMG')[0].style.display = "none";
                    li.className = li.className.replace(/over/,''); 
                }
                if (li.getElementsByTagName('IMG')[0]) 
                {
                    //hide the arrow at the end of the line
                    li.getElementsByTagName('IMG')[0].style.display = "none";
                }
            }
            else
            {              
                newVisibleMenuArray.push(visibleMenus[no]); 
            } 
        } 
    }        
    visibleMenus = newVisibleMenuArray;        
} 
    
var menuActive = true; 
var hideTimer = 0; 
function mouseOverMenu() 
{ 
      menuActive = true;        
} 
    
function mouseOutMenu() 
{ 
      menuActive = false;   
}   
    
function initSubMenus(inputObj,initOffsetLeft,currentDepth) 
{    
    var subUl = inputObj.getElementsByTagName('UL');
    if (subUl.length > 0)
    { 
        var ul = subUl[0]; 
      
        ul.id = 'subOf' + inputObj.id.replace(/[^0-9]/g,''); 
        ul.setAttribute('currentDepth' ,currentDepth); 
        ul.currentDepth = currentDepth; 
        ul.className='menuBlock' + currentDepth;
        ul.onclick = mouseOverMenu; 
        currentZIndex+=1; 
        ul.style.zIndex = currentZIndex; 
        menuBlockArray.push(ul); 
        ul = dhtmlgoodies_menuObj.appendChild(ul);
        ul.style.top = getTopPos(document.getElementById('dhtmlgoodies_menu')) + 'px'; //getTopPos(inputObj);

        if (isFirefox) {
            if (currentDepth == 2)
                ul.style.left = ffTopMenuLeftPos / 1 + fixedSubMenuWidth + 'px';
            else
                ul.style.left = getLeftPos(inputObj) / 1 + fixedSubMenuWidth + 'px';
        }
        else {
            ul.style.left = getLeftPos(inputObj) / 1 + fixedSubMenuWidth + 'px';
        }
     
        ul.style.position = 'absolute'; 
        var li = ul.getElementsByTagName('LI')[0];
        while (li)
        {
            if (li.tagName == 'LI')
            {    
                //li.className='currentDepth' + currentDepth;                
                li.className='currentDepth';                
                li.id = 'dhtmlgoodies_listItem' + liIndex; 
                liIndex++;              
                var uls = li.getElementsByTagName('UL'); 
                li.onclick = showHideSub; //li.onmouseover = showHideSub; 
           
                //if this is the current location, tag it
                if (li.getElementsByTagName('A')[0].href.indexOf(fileNameThis) >= 0 && li.getElementsByTagName('A')[0].href.charAt(li.getElementsByTagName('A')[0].href.length - 1) != '#') 
                {
                    activeMenuItem = li;
                }

                if (uls.length > 0) {
                    var offsetToFunction = li.getElementsByTagName('A')[0].offsetWidth+2; 
                    if(navigatorVersion<6 && MSIE)offsetToFunction+=15;   // MSIE 5.x fix 
                        initSubMenus(li,offsetToFunction,(currentDepth+1)); 
                }
                if (MSIE)
                { 
                    var a = li.getElementsByTagName('A')[0]; 
                    a.style.width=li.offsetWidth+'px'; 
                    a.style.display='block'; 
                }                
            } 
            li = li.nextSibling; 
        } 
        ul.style.display = 'none';    
     //if(!document.all){ 
        //dhtmlgoodies_menuObj.appendChild(ul); 
     //} 
    }    
} 
   
/* 
Initializing menu 
*/ 
function initDhtmlGoodiesMenu() 
{ 
    dhtmlgoodies_menuObj = document.getElementById('dhtmlgoodies_menu'); 
      
    var aTags = dhtmlgoodies_menuObj.getElementsByTagName('A');
    for (var no = 0; no < aTags.length; no++)
    {          
        var subUl = aTags[no].parentNode.getElementsByTagName('UL');
        if (subUl.length > 0 /*&& aTags[no].parentNode.parentNode.parentNode.id != 'dhtmlgoodies_menu'*/)
        { 
            var img = document.createElement('IMG'); 
            img.src = dhtmlgoodies_menu_arrow;
            img.style.display = "none";
            img.height = 11;
            img.width = 16;
            img.align = "absbottom";
            aTags[no].appendChild(img);              
        } 
    }
          
    var mainMenu = dhtmlgoodies_menuObj.getElementsByTagName('UL')[0]; 
    mainMenu.className='menuBlock1'; 
    mainMenu.style.zIndex = currentZIndex; 
    mainMenu.setAttribute('currentDepth' ,1); 
    mainMenu.currentDepth = '1'; 
    mainMenu.onclick = mouseOverMenu;

    var mainMenuItemsArray = new Array(); 
    var mainMenuItem = mainMenu.getElementsByTagName('LI')[0]; 
    mainMenu.style.height = mainMenuItem.offsetHeight -1 + 'px';
    while (mainMenuItem)
    {
        
       /* var mainMenuItemA = mainMenuItem.getElementsByTagName('A')[0];
        var img = document.createElement('IMG'); 
        img.src = dhtmlgoodies_menu_arrow;
        img.style.display = "none";
        mainMenuItemA.appendChild(img);*/

        mainMenuItem.className='currentDepth'; 
        mainMenuItem.id = 'dhtmlgoodies_listItem' + liIndex; 
        mainMenuItem.onclick = showHideSub; //mainMenuItem.onmouseover = showHideSub; 
        liIndex++;
 
 //****Added 2009-04-16 BEGIN
        //if this is the current location, tag it
        try {
            if (mainMenuItem.getElementsByTagName('A')[0].href.indexOf(fileNameThis) >= 0 && mainMenuItem.getElementsByTagName('A')[0].href.charAt(mainMenuItem.getElementsByTagName('A')[0].href.length - 1) != '#') {
                activeMenuItem = mainMenuItem;

            } 
        } catch (stuff) { }  
//****Added 2009-04-16 END

        if (mainMenuItem.tagName == 'LI')
        { 
            mainMenuItemsArray[mainMenuItemsArray.length] = mainMenuItem; 
            initSubMenus(mainMenuItem,0,2); 
        }          
      
        mainMenuItem = mainMenuItem.nextSibling;   
    } 

    for(var no=0;no<mainMenuItemsArray.length;no++){ 
        initSubMenus(mainMenuItemsArray[no],0,2);          
    } 
    
    menuParentOffsetLeft = getLeftPos(dhtmlgoodies_menuObj);    
    //window.onresize = resizeMenu;    
    dhtmlgoodies_menuObj.style.visibility = 'visible';

    if (activeMenuItem) {
        initShowHideSub();
    } 
}

function PreloadImages() { //v1.2
  if (document.images) {
    var imgFiles = PreloadImages.arguments;
    var preloadArray = new Array();
    for (var i=0; i<imgFiles.length; i++) {
      preloadArray[i] = new Image;
      preloadArray[i].src = imgFiles[i];
    }
  }
}
function MouseOver(imgName) {
	if(document.images) {
		if (imgName.src.indexOf("-on") ==-1){
			// get the image type
			suffixType = imgName.src.substring(imgName.src.lastIndexOf("."),imgName.src.length);
			// swap to new image
			if (imgName.src.indexOf("-over") == -1) {
				imgName.src = imgName.src.substring(0,(imgName.src.indexOf(suffixType))) + "-over" + suffixType;
			}
		}
	}
}

function MouseOut(imgName) {
	if(document.images) {
		// get the image type
		suffixType = imgName.src.substring(imgName.src.lastIndexOf("."),imgName.src.length);
		
		// swap image back to original
		if (imgName.src.indexOf("-over") != -1) {
			imgName.src = imgName.src.substring(0,(imgName.src.indexOf("-over"))) + suffixType;
		}
	}
}

function SetCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}


function ReadCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return "";
}


function DeleteCookie(name)
{
  SetCookie(name, "", -1);
}

function doShow(paraNum){
    //Show a DIV
    paraNum.style.display = "";
}

function doHide(paraNum){
	//Hide a Div
	paraNum.style.display="none"
}

function showHideContactBtn(callee) {
    var showFlag = "none";
    var inputArr = document.getElementsByTagName("input")
    for (var i = 0; i < inputArr.length; i++) {
        if (inputArr[i].type == "checkbox") {
            if (inputArr[i].checked) {
                showFlag = "";
                break;
            }
        }
    }
    callee.style.display = showFlag;
    if (showFlag == "none") { document.getElementById("ContactDetails").style.display = showFlag; }
}

function doChkBxEditions(featureListDiv, ChkBxTblON, ChkBxTblOFF, blnShow) {
    if (blnShow) { featureListDiv.style.display = ""; ChkBxTblON.style.display = ""; ChkBxTblOFF.style.display = "none"; }
    else { featureListDiv.style.display = "none"; ChkBxTblON.style.display = "none"; ChkBxTblOFF.style.display = ""; }
}

function collapseAllExpDivs(exceptionDiv) {
    var inputArr = document.getElementsByTagName("div")
    for (var i = 0; i < inputArr.length; i++) {
        if (inputArr[i].id.indexOf('exp') == 0 && inputArr[i].id.indexOf('ticks') == -1 && inputArr[i].id != exceptionDiv && inputArr[i].id != 'expbutton') {
            inputArr[i].style.display = "none";
        }
    }
}

function doEditions(paraNum,arrowNum){
	//expand the paragraph and rotate the arrow; collapse and rotate it back
	var endStrPos = arrowNum.src.lastIndexOf('.');
	var OnOFF = arrowNum.src.substr(endStrPos -1,1);
	//alert(OnOFF);
	if (OnOFF==0){paraNum.style.display="";arrowNum.src="/images/exp1.png"}
	else{paraNum.style.display="none";arrowNum.src="/images/exp0.png"}
}

function doEditionspreviouslcollapse(paraNum,arrowNum){
	//Collapse the paragraph and reset the arrow
	if (paraNum.style.display==""){paraNum.style.display="none";arrowNum.src="/images/exp0.png"}
	else{paraNum.style.display="none";arrowNum.src="/images/exp0.png"}

}

function doExpand1(paraNum){
	//expand the paragraph
	if (paraNum.style.display=="none"){paraNum.style.display="";}
	else{paraNum.style.display="none";}
}

function doCollapse1(paraNum){
	//Collapse the paragraph and reset the arrow
	if (paraNum.style.display==""){paraNum.style.display="none";}
	else{paraNum.style.display="none";}

}

function doExpand2(paraNum,arrowNum){
	//expand the paragraph and rotate the arrow; collapse and rotate it back
	if (paraNum.style.display=="none"){paraNum.style.display="";arrowNum.src="/images/exp1.png"}
	else{paraNum.style.display="none";arrowNum.src="/images/exp0.png"}
}

function doCollapse2(paraNum,arrowNum){
	//Collapse the paragraph and reset the arrow
	if (paraNum.style.display==""){paraNum.style.display="none";arrowNum.src="/images/exp0.png"}
	else{paraNum.style.display="none";arrowNum.src="/images/exp0.png"}

}

function doExpand(paraNum,arrowNum){
	//expand the paragraph and rotate the arrow; collapse and rotate it back
		var endStrPos = arrowNum.src.lastIndexOf('.');

		//Number, either 0 or 1
		var OnOFF = arrowNum.src.substr(endStrPos -1,1)

		//Name string without the number (ie: /images/arrow)
		var startStr = arrowNum.src.substr(0,endStrPos-1)

		//End of string including period (ie: .png)
		var endStr = arrowNum.src.substr(endStrPos ,arrowNum.src.length-1)

		//To get the whole string
		//startStr + OnOFF  + endStr


	if (paraNum.style.display=="none"){paraNum.style.display="";arrowNum.src=startStr+"1"+endStr}
	else{paraNum.style.display="none";arrowNum.src=startStr+"0"+endStr}
}

function doCollapse(paraNum,arrowNum){
	//expand the paragraph and rotate the arrow; collapse and rotate it back

		var endStrPos = arrowNum.src.lastIndexOf('.');
		var OnOFF = arrowNum.src.substr(endStrPos -1,1);
		var startStr = arrowNum.src.substr(0,endStrPos-1);
		var endStr = arrowNum.src.substr(endStrPos ,arrowNum.src.length-1);

		paraNum.style.display="none";arrowNum.src=startStr+"0"+endStr;
}

function CheckInput(display,itemToDisplay){
	if (display)
  		itemToDisplay.style.display = "";
	else
  		itemToDisplay.style.display="none";
}


function changeBackground(imagename,imagenum) {
    var picbackground = new Image();
    var randNumber = Math.round(Math.random() * parseInt(imagenum));
    var endStrPos = imagename.indexOf('.');
    var endStr = imagename.substr(endStrPos ,imagename.length-1)
    picbackground.src = imagename.substr(0,endStrPos) + randNumber + endStr;
    
    document.getElementById('thetable').style.background = "url(" + picbackground.src + ")";
    // alert(picbackground.src);
}

function SubmitQuery() {
//    var SearchText = document.getElementById("QueryTextBox")
//    if (SearchText.value != "") {
//        window.location = "http://www.time-and-space.com/SearchLucene.aspx?QueryText=" + document.getElementById("QueryTextBox").value;
    //    }
    var SearchText = document.getElementById("QueryTextBox")
    if (SearchText.value != "") {
        window.location = "http://www.time-and-space.com/SearchTimewatch.aspx?QueryExpr=" + escape(document.getElementById("QueryTextBox").value);
    }
}


window.onload = initDhtmlGoodiesMenu;


