/* top nav menu */

// the timeout for the menu
var timeout = 500;

// not very clean but simple
// the function can be run in the HTML for faster display
// window.onload=initMenu;

// hide the first ul element of the current element
function timeoutHide(obj)
{

//hideUlUnder(this.id);

//eval("timeoutA"+obj.id+" = window.setTimeout('document.getElementById(\""+obj.id+"\").style.backgroundColor=\"#73D0FF\"' ,100);");
obj.style.backgroundColor="#FFFFFF";

    // start the timeout
    eval( "timeout" + obj.id + " = window.setTimeout('hideUlUnder( \"" + obj.id + "\" )', " + timeout + " );");
}

// hide the ul elements under the element identified by id
function hideUlUnder(id)
{
	
	 var imgs = document.getElementById(id).getElementsByTagName('IMG');
	 if (imgs[0]) {
      var newimgsrc = imgs[0].src.replace(/_on.gif/, ".gif");
      //imgs[0].src = newimgsrc;
	 }
	 
    var uls=document.getElementById(id).getElementsByTagName('ul');
    if (uls.length>=1) {
      uls[0].style['visibility'] = 'hidden';
      
     
      
      
    }
}


// show the first ul element found under this element
function showMenu(obj)
{
	//if (img && imgsrc) MM_swapImage(img,'',imgsrc,1);

	var imgs = obj.getElementsByTagName('IMG');
	if (imgs[0]) {
      var newimgsrc = imgs[0].src;
      if (!newimgsrc.match(/_on.gif/)) {
      newimgsrc = newimgsrc.replace(/.gif/, "_on.gif");
      //imgs[0].src = newimgsrc;
      }
	}
	
obj.style.backgroundColor="#6cbcc5";
//if (eval("typeof(timeoutA"+obj.id+")") != "undefined") eval ( "clearTimeout( timeoutA"+ obj.id +");" );

    // show the sub menu
    var uls=obj.getElementsByTagName('ul');
    if (uls.length>=1) {


// see whether we should move the menu
var ul=uls[0];
var botWin =  document.body.clientHeight;
var topPos = nwGetY(ul);
var botPos = topPos + ul.offsetHeight;
if (botPos > botWin) {
  var newPos = ul.offsetTop - (botPos - botWin);
  ul.style.top = newPos;
}



      uls[0].style['visibility'] = 'visible';
    }
    // clear the timeout
if (eval("typeof(timeout"+obj.id+")") != "undefined")
    eval ( "clearTimeout( timeout"+ obj.id +");" );
    hideAllOthersUls( obj );
}

// hide all ul on the same level of  this list item
function hideAllOthersUls( currentLi )
{
    var ul = currentLi.parentNode;
    //alert(lis.childNodes.length);
    for ( var i=0; i<ul.childNodes.length; i++ )
    {
        if ( ul.childNodes[i].id && ul.childNodes[i].id != currentLi.id )
        {
            hideUlUnderLi( ul.childNodes[i] );
        }
    }
}

// hide all the ul wich are in the li element
function hideUlUnderLi( li )
{
	
	var imgs = li.getElementsByTagName('IMG');
	if (imgs[0]) {
      var newimgsrc = imgs[0].src.replace(/_on.gif/, ".gif");
      //imgs[0].src = newimgsrc;
	}
	
	
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ )
    {
        uls.item(i).style['visibility'] = 'hidden';
	
	
      
      
    }
} 

// get Y position of the object on a page
function nwGetY(obj) {
  return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+nwGetY(obj.offsetParent) );
}

/**/

function popularStoriesShow(id) {
    var area1 = document.getElementById('p1');
    var area2 = document.getElementById('p2');
    var areax = document.getElementById(id);
    if (areax == area1) {
        area1.style.display = 'block';
        area2.style.display = 'none';
    } else {
        area1.style.display = 'none';
        area2.style.display = 'block';
    }
    
//	document.getElementById('p1').style.display = 'none';
	//document.getElementById('p2').style.display = 'none';
	//document.getElementById(id).style.display = 'block';
}

function Delicious() {
    window.open('http://del.icio.us/post?v=4&jump=close&url='+encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title),'delicious','toolbar=0,width=700,height=400');
    return false;
}
function Digg() {
    window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title));
    return false;
}
function Reddit() {
    window.open('http://reddit.com/submit?url='+encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title));
    return false;
}
function shownews (id) {
	document.getElementById('newsid1').style.display = 'none';
	document.getElementById('newsid2').style.display = 'none';	
	document.getElementById('newsid3').style.display = 'none';	
	document.getElementById(id).style.display = 'block';
    
    // switch images
    var img1 = document.getElementById("newstabcompany");
    var img2 = document.getElementById("newstabindustry");
    var img3 = document.getElementById("newstabpeople");
    if (id == "newsid1") {
        img1.src = '/images/tab_company_on.gif';
        img2.src = '/images/tab_industry.gif';
        img3.src = '/images/tab_people.gif';
    } else if (id == "newsid2") {
        img1.src = '/images/tab_company.gif';
        img2.src = '/images/tab_industry_on.gif';
        img3.src = '/images/tab_people.gif';
    } else if (id == "newsid3") {
        img1.src = '/images/tab_company.gif';
        img2.src = '/images/tab_industry.gif';
        img3.src = '/images/tab_people_on.gif';
    }
}

function showspecial (id, obj) {
	document.getElementById('special1').style.display = 'none';
	document.getElementById('special2').style.display = 'none';	
	document.getElementById('special3').style.display = 'none';	
	document.getElementById('special4').style.display = 'none';	
	document.getElementById(id).style.display = 'block';
    
    var links = document.getElementById('special_tabs').getElementsByTagName("A");
    for(var i=0; i<links.length; i++) {
        if (links[i] == obj) {
            //alert(i + " on");
            links[i].className = "active";
        } else {
            //alert(i + " off");
            links[i].className = "";
        }
    }
}

function showvideo (id, total) {
    for (var i=0; i<total; i++) {
        if (id == i) {
            document.getElementById('video'+i).style.display = 'block';
        } else {
            document.getElementById('video'+i).style.display = 'none';
        }
    }
}

function printPage() {
    window.print();
}

function openPopup(url) {
    var w=650;
    var h=400;
    var params = "menubar=no,toolbars=no,statusbar=no,location=no,left=100,top=100,scrollbars=yes,resizable=yes,width="+w+",height="+h;
    var popup = window.open('','mhtpopup',params);
    popup.location.href = url;
    if (popup.focus) {popup.focus()}
}

function openVideoPopup(url) {
    var w=550;
    var h=450;
    var params = "menubar=no,toolbars=no,statusbar=no,location=no,left=100,top=100,scrollbars=yes,resizable=yes,width="+w+",height="+h;
    var popup = window.open('','mhtvideopopup',params);
    popup.location.href = url;
    if (popup.focus) {popup.focus()}
}




