// JavaScript Document

function init() {
	
	// quit if this function has already been called
	if (arguments.callee.done) return;
	
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;
	
	//Get the area we need
	var col_left = document.getElementById( 'col_left' );
	var col_right = document.getElementById( 'col_right' );
	
	// Get the links and the areas
	var selectors = col_left.getElementsByTagName('a');
	var text_areas = col_left.getElementsByTagName('div');
	var quotes = col_right.getElementsByTagName('div');
	
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
  
  	//Close them all
	resetAll();
	
	//If there is an url fragment, use it
	if(self.document.location.hash.substring(1) && document.getElementById(self.document.location.hash.substring(1) + "_text")) {
		showArea(self.document.location.hash.substring(1));
	//Or get the first one
	} else {
		selectors[0].className = "selector selector_on";
		text_areas[0].style.display = "block";
		quotes[0].style.display = "block";
	}
	
	//attach onclick
	for(i = 0; i < selectors.length; i++) {
		selectors[i].onclick = function() {
			var area = this.id;
			return showArea(area);
		};
	}
		
	//close all selectors and areas
	function resetAll() {
		for(i = 0; i < selectors.length; i++) {
			selectors[i].className = "selector selector_off";
		}
		for(i=0; i < text_areas.length; i++) {
			if(text_areas[i].className == "text")
				text_areas[i].style.display = "none";
		}
		for(i=0; i < quotes.length; i++) {
			if(quotes[i].className.indexOf("quote_box") > -1)
				quotes[i].style.display = "none";
		}
	
	}
	
	//Show me that area!
	function showArea(area) {
		resetAll();
		stopVid();
		document.getElementById(area).className = "selector selector_on";
		document.getElementById(area + "_text").style.display = "block";
		document.getElementById(area + "_quote").style.display = "block";
		return true;
	}
	
	function stopVid() {
		for(j = 0; j < selectors.length; j++) {
			if(document.getElementById(selectors[j].id + '_video')) {
				var flashVideoPlayer = (isIE) ? window[selectors[j].id + '_video'] : document[selectors[j].id + '_video'];
				if(flashVideoPlayer) {
					flashVideoPlayer.pauseResume();
				}
			}
		}
	}
}

DomLoaded.load(init);