// globals
var questions, answers;
var showall = false;

if(!window.Node){
  var Node = {
    ELEMENT_NODE : 1,
    ATTRIBUTE_NODE : 2,
    TEXT_NODE : 3,
    CDATA_SECTION_NODE : 4,
    ENTITY_REFERENCE_NODE : 5,
    ENTITY_NODE : 6,
    PROCESSING_INSTRUCTIONS_NODE : 7,
    COMMENT_NODE : 8,
    DOCUMENT_NODE : 9,
    DOCUMENT_TYPE_NODE : 10,
    DOCUMENT_FRAGMENT_NODE : 11,
    NOTATION_NODE : 12
  }
}

// --------------------------------------------------

function checkNode(node, filter){
  return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}

// --- All Ancestors --------------------------------

function getAncestors(node){
  var result = new Array();
  while(node.parentNode != null){
    result[result.length] = node.parentNode;
    node = node.parentNode;
  }
  return result;
}

// --- All Children ---------------------------------

function getChildren(node, filter){
  var result = new Array();
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    if(checkNode(children[i], filter)) result[result.length] = children[i];
  }
  return result;
}
function getChildrenByElement(node){
  return getChildren(node, "ELEMENT_NODE");
}
function getChildrenByText(node){
  return getChildren(node, "TEXT_NODE");
}
function getChildrenByTagName(node, tag){
  return getChildren(node, tag);
}

// --- First Child ----------------------------------

function getFirstChild(node, filter){
  var child;
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    child = children[i];
    if(checkNode(child, filter)) return child;
  }
  return null;
}
function getFirstChildByElement(node){
  return getFirstChild(node, "ELEMENT_NODE");
}
function getFirstChildByText(node){
  return getFirstChild(node, "TEXT_NODE");
}
function getFirstChildByTagName(node, tag){
  return getFirstChild(node, tag);
}

// --- Last Child -----------------------------------

function getLastChild(node, filter){
  var child;
  var children = node.childNodes;
  for(var i = children.length-1; i >= 0; i--){
    child = children[i];
    if(checkNode(child, filter)) return child;
  }
  return null;
}
function getLastChildByElement(node){
  return getLastChild(node, "ELEMENT_NODE");
}
function getLastChildByText(node){
  return getLastChild(node, "TEXT_NODE");
}
function getLastChildByTagName(node, tag){
  return getLastChild(node, tag);
}

// --- All Descendents ------------------------------

function getDescendents(node, filter, result){
  if(!result) result = new Array();
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    if(checkNode(children[i], filter)) result[result.length] = children[i];
    getDescendents(children[i], filter, result);
  }
  return result;
}
function getDescendentsByElement(node){
  return getDescendents(node, "ELEMENT_NODE");
}
function getDescendentsByTagName(node, tag){
  return getDescendents(node, tag);
}

// --- All Siblings ---------------------------------

function getSiblings(node, filter){
  return getChildren(node.parentNode, filter);
}
function getSiblingsByElement(node){
  return getSiblings(node, "ELEMENT_NODE");
}
function getSiblingsByText(node){
  return getSiblings(node, "TEXT_NODE");
}
function getSiblingsByTagName(node, tag){
  return getSiblings(node, tag);
}

// --- Next Sibling ---------------------------------

function getNextSibling(node, filter){
  for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
    if(checkNode(sibling, filter)) return sibling;
  }
  return null;
}
function getNextSiblingByElement(node){
  return getNextSibling(node, "ELEMENT_NODE");
}
function getNextSiblingByText(node){
  return getNextSibling(node, "TEXT_NODE");
}
function getNextSiblingByTagName(node, tag){
  return getNextSibling(node, tag);
}

// --- Previous Sibling -----------------------------

function getPreviousSibling(node, filter){
  for(var sibling = node.previousSibling; sibling != null; sibling = sibling.previousSibling){
    if(checkNode(sibling, filter)) return sibling;
  }
  return null;
}
function getPreviousSiblingByElement(node){
  return getPreviousSibling(node, "ELEMENT_NODE");
}
function getPreviousSiblingByText(node){
  return getPreviousSibling(node, "TEXT_NODE");
}
function getPreviousSiblingByTagName(node, tag){
  return getPreviousSibling(node, tag);
}





// My Code Starts Here...
var currentID = "initial";
var over = "over";
var out = "out";


function initList(){
list = getChildrenByTagName(document.getElementById("theDistList"),'li');
tableDivs = getChildrenByTagName(document.getElementById("outerDist"),'div');
//alert(list.length);
//alert(stars.length);

	var str_docLocation = document.location.href
	var int_countryPosition = str_docLocation.indexOf('country=',0);
	var flag_ok = false;
	
	if(int_countryPosition != -1){
		var str_segment = str_docLocation.substring(int_countryPosition);
		var int_ampersandLocation = str_segment.indexOf('&',0);

		if(int_ampersandLocation != -1){
			var str_theCountry = str_segment.substring(8,int_ampersandLocation);
		} else {
			var str_theCountry = str_segment.substring(8);
		}
	}

	
	for(x=0;x<list.length;x++){
		if(list[x].id == str_theCountry){
			flag_ok = true;
		}

		list[x].onclick = function(){
			showIt(this.id);
		}

		list[x].onmouseover = function(){
			flipIt(this.id,over);
		}

		list[x].onmouseout = function(){
			flipIt(this.id,out);
		}
		
	}
	
	for(x=1;x<tableDivs.length;x++){
		tableDivs[x].style.display = "none";
	}
	
	if(flag_ok){		
		showIt(str_theCountry);
	}

}

function showIt(id){
	//alert(id);
	var myButtonObj = document.getElementById(id);
	var myDivObj = document.getElementById("div_" + id);
	
	if( (currentID != "") && (currentID != id) ){
		document.getElementById("div_" + currentID).style.display = "none";
		if(currentID != "initial"){
			document.getElementById(currentID).style.backgroundColor = "transparent";
			document.getElementById(currentID).style.color = "#000";
		}
	}

	currentID = id;
	myDivObj.style.display = "block";
	myButtonObj.style.backgroundColor = "#42548A";
	myButtonObj.style.color = "#fff";
}

function flipIt(id,type){
	//alert(id);
	if(currentID != id){
		var myButtonObj = document.getElementById(id);
		if(type == over){
			myButtonObj.style.backgroundColor = "#798DC2";
			myButtonObj.style.color = "#fff";
		} else {
			myButtonObj.style.backgroundColor = "transparent";
			myButtonObj.style.color = "#000";
		}
	}
}

/* Where */
/* White BG / Dark: #42548A / Light: #798DC2 / Grey: #888F94 */