execOnLoad = function() {
 updateContentForNav();
 an_StartList();

 an_SetNavAndCrumbs();

 //preloadImages();
 //initPopups();
}

execNow = function() {
 updateContentForNav();
}

window.onload=execOnLoad;

// ------------------------------------------------------------------------- \\

function updateContentForNav() {
  if (document.getElementById("second_nawigacja")) {
    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("nawigator");
    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();
  // Find the first instance of the attribute.
  var startOfClass = tag.toLowerCase().indexOf(attribute);
  if (startOfClass == -1) { return tag; /* probably need some kind of timeout event or something because IE sucks */ }
  // Make sure there is another class assigned
  if (startOfClass != tag.toLowerCase().lastIndexOf(attribute) || !removeOnlyIfTwo) {
    // Find the first space after the first class
    var lengthOfClass = tag.substring(startOfClass).indexOf(" ");
    // The string to remove is from 'class' up to the next space
    var classString = tag.substr(startOfClass,lengthOfClass)+" ";
    tag = an_StringReplace(tag,classString,"");
  }
  return tag;
}



// -----------------------------------------------------------------------------
// The following function cycles through the main nav HTML and highlights the
// appropriate top-level section.
// It also assembles and generates the page breadcrumbs based on values in the
// main nav.
function an_SetNavAndCrumbs() {
  var crumb = document.getElementById("breadcrumbs");
  if (crumb) {
	// If there are no list-item descendants, continue...
	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("nawigator");
		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++) {
			// For every <li> child, we must test it's the href value of it's <a> child:
			var li = c[i];
			var a = an_GetChildrenOfType(li,"a")[0]; // first anchor child of current LI

			// NOTE: 'href' Refers to the href values taken from the primary nav, while 'loc' refers to the document location.
			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]) {
	    // Set breadcrumb overrides for specific sections, and any exceptions
		// The format is an array of overides.
		// The overides consist of either:
		//  - a single directory sting, or
		//  - an array consisting a directory string and any exceptions within that directory.
		// Exceptions consist of either:
		//  - a string or regular expression pattern
		//  - an array of strings or regular expressions.

		// var breadcrumbOverride = new Array(
		//	new Array("/news/press/", "/index.html"),
		//	new Array("/news/releases/", new Array("/index.html", /\/\d\d\d\d\.html/i))
		// );
		// This will override using the <title> tag breadcrumb for files in /news/press/ with the exception of the index.html
		// It will also override using the <title> tag breadcrumb for files in /news/releases/ except index.html and files matching ####.html (for example: 2004.html, 2005.html)
		var breadcrumbOverride = new Array(
			new Array("/news/press/", new Array("/index.html", /\/\d\d\d\d\.html/i)),
			new Array("/news/releases/", new Array("/index.html", /\/\d\d\d\d\.html/i))
		);

		// Assign 'Type' properties to Array and String objects
		Array.prototype.Type="Array";
		String.prototype.Type="String";


		var proceed = true;
		for (var i = 0; i < breadcrumbOverride.length; i++) {
			// In case of a non-array element, we convert it to a 1-dimensional array
			if (breadcrumbOverride[i].Type != "Array") { breadcrumbOverride[i] = new Array(breadcrumbOverride[i]); }

			if (loc.match(breadcrumbOverride[i][0])) {
				// We're in an override section, so we set 'proceed' to false.
				proceed = false;

				// However, it is now necessary to check for exceptions to the override
				if (breadcrumbOverride[i][1]) {
					for (var j = 0; j < breadcrumbOverride[i][1].length; j++) {
						// In case of a non-array element, we convert it to a 1-dimensional array
						if (breadcrumbOverride[i][1].Type != "Array") { breadcrumbOverride[i][1] = new Array(breadcrumbOverride[i][1]); }

						// In the case of an index file, we also add a condition to match on an ending slash, not just 'index.html'
						if ((breadcrumbOverride[i][1][j]+"").match(/index\./)) { breadcrumbOverride[i][1][breadcrumbOverride[i][1].length] = /\/$/; }

						// Check for an exception case and update 'proceed' if found
						if (loc.match(breadcrumbOverride[i][1][j])) { proceed = true; break; }
					}
				}
			}
		}


	  	if (proceed) {
			// For the final crumb, we get the value from the <title> tag.
			var text_content = document.getElementsByTagName('title')[0].innerHTML;
			// Create the final LI node, and add it to the document.
			var text = document.createTextNode(text_content);
			var li = document.createElement('li');
			li.appendChild(text);
			crumb.appendChild(li);
		}
	  }
	}
  }
}


