var timer;
var which;

function do_top_nav (which) {

	// "where are we" sniffer
	l  = document.location.pathname;
	
	a1 = '<a href="';
	a2 = '"';
	a3o = ' class="orangelink" style="color:#cc6600"';
	a3w = ' class="whitelink"';
	a4 = '>';
	ac = '</a>';
	s  = '<span class="selectednavlink">';
	sc = '</span>';
	
	var towrite = '';
	
	towrite += ('<div id="homenav" style="display: ');
	if (which == 'home') {
		towrite += 'block';
	}
	else {
		towrite += 'none; color: white; background: #f90;" onmouseover="do_over(\'atadv\', this);" onmouseout="do_out(\'atadv\', this)';
	}
	towrite += (';">');
	
	for (i = 0; i < topth.length; i++) {
	  if (l.indexOf(topuh[i]) != -1) towrite += (s);
	  towrite += (a1 + topuh[i] + a2);
	  if (l.indexOf(topuh[i]) != -1) towrite += (a3o);
	  else if (which == 'adv') towrite += (a3w);
	  towrite += (a4 + topth[i] + ac);
	  if (l.indexOf(topuh[i]) != -1) towrite += (sc);
	  if (i < (topth.length - 1)) towrite += (' | ');
	}

	towrite += ('</div>\n\n');
	
	towrite += ('<div id="advnav" style="display: ');
	if (which == 'adv') {
		towrite += 'block';
	}
	else {
		towrite += 'none; color: white; background: #f90;" onmouseover="do_over(\'athome\', this);" onmouseout="do_out(\'athome\', this)';
	}
	towrite += (';">');
	
	for (i = 0; i < topta.length; i++) {
	  if (l.indexOf(topua[i]) != -1) towrite += (s);
	  towrite += (a1 + topua[i] + a2);
	  if (l.indexOf(topua[i]) != -1) towrite += (a3o);
	  else if (which == 'careers') towrite += (a3w);
	  towrite += (a4 + topta[i] + ac);
	  if (l.indexOf(topua[i]) != -1) towrite += (sc);
	  if (i < (topta.length - 1)) towrite += (' | ');
	}

	towrite += ('</div>\n');

// to debug, uncomment the following line
//alert(towrite);

	document.write(towrite);
	
}

function do_over (which) {

	if (timer) {
		clearTimeout(timer);
		really_do_out();
	}
	if (which == 'athome') {
		document.getElementById('advimg').src='http://www.cnetnetworks.com/i/shared/dbwu_over.gif';
		//document.getElementById('homenav').style.display = 'none';
		//document.getElementById('advnav').style.display  = 'block';
	}
	else {
		document.getElementById('homeimg').src='http://www.cnetnetworks.com/i/shared/about_us_over.gif';
		//document.getElementById('homenav').style.display = 'block';
		//document.getElementById('advnav').style.display  = 'none';
	}

}

function do_out (where) {

	which = where;
	timer = setTimeout('really_do_out()', 2);

}

function really_do_out () {

	if (which) {
		if (which == 'athome') {
			document.getElementById('advimg').src='http://www.cnetnetworks.com/i/shared/dbwu_off.gif';
			//document.getElementById('advnav').style.display  = 'none';
			//document.getElementById('homenav').style.display = 'block';
		}
		else {
			document.getElementById('homeimg').src='http://www.cnetnetworks.com/i/shared/about_us_off.gif';
			//document.getElementById('homenav').style.display = 'none';
			//document.getElementById('advnav').style.display  = 'block';
		}
	}

}

