﻿execOnLoad = function() {
 an_StartList(); 
}


// ------------------------------------------------------------------------- \\

function updateContentForNav() {
  if (document.getElementById("secondary_navigation")) {
    var cw = document.getElementById("content-wrapper");
	if(cw && cw.style) {
		cw.style.marginRight = "200px";
		if (!cw.attributes["id"].value) { cw.style.width = "100%"; } /* IE 5.5 needs this also */
	};
  }
}

function an_StartList() {
  if (document.all&&document.getElementById && !window.opera) {
    navRoot = document.getElementById("navi");
    if (navRoot) {
      for (i=0; i<navRoot.childNodes.length; i++) {
   	    node1 = navRoot.childNodes[i];
       	if (node1.nodeName=="UL") {
	      for (j=0; j<node1.childNodes.length; j++) {
    	    node2 = node1.childNodes[j];
        	if (node2.nodeName=="LI") {
	          node2.onmouseover=function() {
    	        this.className+=" over";
        	  }
	          node2.onmouseout=function() {
    	        this.className=this.className.replace(" over", "");
        	  }
    } } } } }
	navRoot = document.getElementById("sites");
    if (navRoot) {
      for (i=0; i<navRoot.childNodes.length; i++) {
        node = navRoot.childNodes[i];
		if (node.attributes["class"].value) { cls = node.attributes["class"].value; } /* IE 6 */
		else { cls = node.attributes["class"]+""; /* IE 5.5 */ }
		if (cls.indexOf("expand") >= 0) {
          if (node.nodeName=="LI") {
            node.onmouseover=function() {
              this.className+=" over";
            }
            node.onmouseout=function() {
              this.className=this.className.replace(" over", "");
            }
    } } } }
	cls = "";
    navRoot = document.getElementById("site-tools");
    if (navRoot) {
      for (i=0; i<navRoot.childNodes.length; i++) {
   	    node1 = navRoot.childNodes[i];
       	if (node1.nodeName=="UL") {
	      for (j=0; j<node1.childNodes.length; j++) {
    	    node2 = node1.childNodes[j];
			if (node2.attributes["class"].value) { cls = node2.attributes["class"].value; /* IE 6 */ }
			else { cls = node2.attributes["class"]+""; /* IE 5.5 */ }
			if (cls.indexOf("expand") >= 0) {
        	if (node2.nodeName=="LI") {
	          node2.onmouseover=function() {
    	        this.className+=" over";
        	  }
	          node2.onmouseout=function() {
    	        this.className=this.className.replace(" over", "");
        	  }
    } } } } } }
} }


function an_IE_GetAttribute(tag,attribute,removeOnlyIfTwo) {
  attribute = attribute.toLowerCase();
  
  var startOfClass = tag.toLowerCase().indexOf(attribute);
  if (startOfClass == -1) { return tag; }
  
  if (startOfClass != tag.toLowerCase().lastIndexOf(attribute) || !removeOnlyIfTwo) {
    
    var lengthOfClass = tag.substring(startOfClass).indexOf(" ");
   
    var classString = tag.substr(startOfClass,lengthOfClass)+" ";
    tag = an_StringReplace(tag,classString,"");
  }
  return tag;
}

var promotion_index = 0;
function an_Promotions(step) {
 var promotions = document.getElementById("promotions-content");
 if (promotions && promotions.childNodes) {

  var len = 0; 
  for (var i = 0; i < promotions.childNodes.length; i++) { if (promotions.childNodes[i].nodeName == "LI") len++; }
  if (len == 1) return;

  var new_index = promotion_index + step;
  if (new_index < 0) new_index = len-1;
  if (new_index >= len) new_index = 0;

  var c = 0;
  for (i = 0; i < promotions.childNodes.length; i++) {
   if(promotions.childNodes[i].nodeName == "LI") {
    if (promotion_index == c) { promotions.childNodes[i].style.display = "none"; }
    if (new_index == c) { promotions.childNodes[i].style.display = "block"; }
    c++;
   }
  }
  promotion_index = new_index;
 }
}

function an_StringReplace(str, match, replace) {
 
  str=str+""; 
  var a=str.indexOf(match);
  if (a >= 0) { str = str.substring(0,a) + replace + str.substring(a+match.length); }
  return str;
}

// -----------------------------------------------------------------------------

function an_SetNavAndCrumbs() {
  var crumb = document.getElementById("breadcrumbs");
  if (crumb) {
	
	if (crumb.getElementsByTagName('li').length == 0) {

		var breadcrumbs = ["Home", "/"];

		var loc = document.location+"";

		loc = loc.replace("://", "");
		loc = loc.substring(loc.indexOf("/"));

		var navroot = document.getElementById("navi");
		if (navroot) var c = an_GetChildrenOfType(navroot, "ul");

		if(c.defined) {
    	  c = an_GetChildrenOfType(c[0],"li");
	  	  for (var i = 0; i < c.length; i++) {
			
			var li = c[i];
			var a = an_GetChildrenOfType(li,"a")[0]; 
			
			var href = (a+"").replace("//","");
			href = href.substring(href.indexOf("/"));

			if (loc.indexOf(href) == 0) {
				// At this point, we've found the top-level section this page belongs to
				// Store the breadcrumb information:
				breadcrumbs[breadcrumbs.length] = a.firstChild.data;
				breadcrumbs[breadcrumbs.length] = href;

				// Set the proper section active:
				an_SetAttribute(li, "class", "active");

				// Now, we prepare to visit the second-level elements:
				var d = an_GetChildrenOfType(li, "div")[0];
				var ul = an_GetChildrenOfType(d, "ul")[0];
				c = an_GetChildrenOfType(ul,"li");


				for (var j = 0; j < c.length; j++) {
					var li = c[j];
					var a = an_GetChildrenOfType(li,"a")[0];
					var href = (a+"").replace("///","").replace("//","");

					href = href.substring(href.indexOf("/"));

					if (
					  (loc.indexOf(href) >= 0) &&                                // If href (URL from nav) matches document location
					  (href != breadcrumbs[breadcrumbs.length-1]) &&             // and href does not match previously breadcrumb URL 
					  !(                                                         // BUT NOT
					   (loc == href) ||                                          // if href and document location match
					   (loc.indexOf(href+'index.') >= 0) ||                      // or location refers to and href+index file
					   ((loc.lastIndexOf("/") == loc.length-1) && (loc == href)) // or href refers to a directory and loc == href (excludes subdirectories)
					  )
					) {
						// At this point, we've found the next level element
						// Store the breadcrumb information:
						breadcrumbs[breadcrumbs.length] = a.firstChild.data;
						breadcrumbs[breadcrumbs.length] = href;
						break;
					}
				}
				break;
			}
		  }
		}

//	  Remove any default breadcrumbs
//	  crumb.innerHTML = "";

	  // Loop through our breadcrumbs array
  	  for (var i = 0; i < breadcrumbs.length; i+=2) {
		// Create our text node
		var text = document.createTextNode(breadcrumbs[i]);

		// Create the anchor tag
		var a = document.createElement('a');
		an_SetAttribute(a, "href", breadcrumbs[i+1]);

		// Create the LI tag
		var li = document.createElement('li');

		// Finally, assemble everything and add it to the page.
		a.appendChild(text);
		li.appendChild(a);
		crumb.appendChild(li);
	  }

	  // If loc does not match the previously stored breadcrumb URL
	  if (loc != breadcrumbs[breadcrumbs.length-1]) {
	
		

	  }
	}
  }
}



