//import AnimationManager;

// Sets the navigation menu to up-state
//function setNavUp(navElement){
//  navElement.style.backgroundPosition = '-415px 0px';
//}

// Sets the navigation menu to over-state
//function setNavOver(navElement){
//  navElement.style.backgroundPosition = '-215px 0px';
//}

// Sets the navigation menu to down-state
//function setNavDown(navElement){
//  navElement.style.backgroundPosition = '-15px 0px';
//}


var currentAccordianTabs = new Object();
function openAccordianTab(masterTabId, tabElement, openHeight, closeHeight){
  var oldTabElement = currentAccordianTabs[masterTabId];
  if(oldTabElement == null){
    oldTabElement = document.getElementById(masterTabId);
  }
  if(tabElement != oldTabElement){
    tabElement.focus();
    if(oldTabElement){
      var oldTabContent = getVisibleChild(oldTabElement, 1);
      if(oldTabContent){
        addAnimation(oldTabContent, "visibility", "$value$", "visible", "hidden", 200);
      }
      addAnimation(oldTabElement, "height", "$value$px", openHeight, closeHeight, 200);
    }
    addAnimation(tabElement, "height", "$value$px", closeHeight, openHeight, 200);
    var tabContent = getVisibleChild(tabElement, 1);
    if(tabContent){
      addAnimation(tabContent, "visibility", "$value$", "hidden", "visible", 0);
    }
    currentAccordianTabs[masterTabId] = tabElement ;
  }
  executeAnimations();
}

// Returns a visible child
function getVisibleChild(element, index){
  element = element.firstChild;
  var i=-1;
  while(element){
    if(element.nodeType == 1){
      i++;
      if(i == index){
       return element;
      }
    }
    element = element.nextSibling;	      
  }
  return null;
}

// A cache of each tab's HTML content
var tabContentCache = new Object();
// The currently selected tab Id
var selectTabId = "contentMenuItem0";

function selectContentTab(tabElement, targetId){
  // Remember the current tab's content
  var contentElement = document.getElementById(targetId);
  tabContentCache[selectTabId] = contentElement.innerHTML;

  // Deselect the currently selected tab
  var selectedTabElement = document.getElementById(selectTabId);
  selectedTabElement.style.background = "";
  selectedTabElement.style.borderLeft = "";
  selectedTabElement.style.borderRight = "";
  
  // Select the given tab
  tabElement.style.background = "url(/images/nav/contentNavDown.jpg)";
  tabElement.style.borderLeft = "solid 1px #C0C0C0";
  tabElement.style.borderRight = "solid 1px #C0C0C0";
  
  // 
  var content = tabContentCache[tabElement.id];
  if(content){
    contentElement.innerHTML = content;
  }else{
    // Load content for the given tab
    loadContent(tabElement.href, targetId);
  }
  
  selectTabId = tabElement.id;

}

// Loads Html from the given URL into the given DOM node
function loadContent(sourceUrl, targetId){
  // Determine the Http Request object is used for this browser
  var xmlHttpRequest;
  if(window.XMLHttpRequest){
    // Mozilla and Safari
    xmlHttpRequest = new XMLHttpRequest();
  }else if(window.ActiveXObject){
    // Internet Explorer
    try {
      xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      try{
       xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){}
    }
	}
  // Define a results handler
  xmlHttpRequest.onreadystatechange = function(){
    if(xmlHttpRequest.readyState == 4 && (xmlHttpRequest.status == 200 || window.location.href.indexOf("http")==-1)){
      var tagetElement = document.getElementById(targetId);
      tagetElement.innerHTML = xmlHttpRequest.responseText
      tagetElement.focus();
    }
  }

  // Randomize the url to prevent caching
  var now = new Date();
  if(sourceUrl.indexOf("?") == -1){
    sourceUrl = sourceUrl + "?rnd=" + now.getTime();
  }else{
    sourceUrl = sourceUrl + "&rnd=" + now.getTime();
  }
  
  // Send the Http Request
  xmlHttpRequest.open('GET', sourceUrl, true)
  xmlHttpRequest.send(null)
}
