/*

	Filename: tabs.js
	Author: J Christopher Garcia (http://jx-opher.com)
	Created: October 15, 2004
	
	Description: Functions to make tab-like interface work.


*/

	
var $containers = new Object();
var $anchors = new Array();
	
$anchors.push( 'kerryLink' );
$anchors.push( 'bushLink' );
$anchors.push( 'naderLink' );

function setTabs() {
		
	for ( $i = $anchors.length - 1; $i >= 0; $i-- ) {
		
		$anchor = document.getElementById( $anchors[$i] );
		
		$targetNodeId = getAnchorFromHref( $anchor.href );
		
		$containers[$targetNodeId] = removeNodeById( $targetNodeId );
				
		$anchor.onclick = function() {
		
			// redraw all bottom borders for tabs
			for ( $j = 0; $j < $anchors.length; $j++ ) {
				
				$tab = document.getElementById( $anchors[$j] );
				$tab.style.background = '#fff url(../imgs/tabs-bg.gif) bottom center repeat-x';
				
				
				var agt=navigator.userAgent.toLowerCase();
							
				if ( ( document.styleSheets != null ) && ( document.styleSheets['IEJSHook'] != null ) && ( document.styleSheets['IEJSHook'].rules.length > 0 ) ) {
														
					document.styleSheets['IEJSHook'].removeRule();
					
					$anchors[$j].innerHMTL = $anchors[$j].innerHTML;
									
				}
				
			
			}
				
			$mediaContainer = document.getElementById( 'media' );
				
			// remove all (any) content from the media DIV
			for ( $j = $mediaContainer.childNodes.length - 1; $j > 0 ; $j-- ) {
				
				$mediaContainer.removeChild( $mediaContainer.childNodes[$j] );
			
			}
				
				
			$targetNodeId = getAnchorFromHref( this.href );
				
			$mediaContainer.appendChild( $containers[$targetNodeId] );
				
			this.style.background = '#fff';
			
			if ( ( document.styleSheets != null ) && ( document.styleSheets['IEJSHook'] != null ) ) {
									
				document.styleSheets['IEJSHook'].addRule( '#tabs li #' + this.id, 'background-image: none' );
				
				this.innerHTML = this.innerHTML;
				
			}
				
			this.blur();
				
			return false;
		
		}	
	
	}
			
	$anchor.onclick();
	
} // end setTabs



function getAnchorFromHref( $href ) {

	return $href.slice( $href.indexOf('#') + 1 );
	
} // end getAnchorFromHref


function removeNodeById( $nodeId ) {

	var $node = document.getElementById( $nodeId );

	if ( $node && $node.parentNode != null ) {
						
		return $node.parentNode.removeChild( $node );
		
	}
	
	return false;
	
} //  end removeNodeById