// JavaScript Document
// Depends on jQuery JavaScript Library v1.3.2

function km_myclass_import(jsFile) {
	var scriptElt = document.createElement('script');
	scriptElt.type = 'text/javascript';
	scriptElt.src = jsFile;
	document.getElementsByTagName('head')[0].appendChild(scriptElt);
}

/**
 *	only affects 'wide' dropdowns.  This function applies one of two classes to each li element within the wide ul's.  The left 
 * 		column li's get a right side border styling class applied and the right side li's get a left side border class.
**/
function format_nav_borders(containerID) {
	var container = document.getElementById(containerID);
	
	var uls = container.getElementsByTagName("ul");
	var j = 0;
	
	var newUls = new Array();
	
	//restrict array to wide dropdown menu's only
	for(var g=0; g<uls.length; g++) {
		if(uls.item(g).id == "wide")
			newUls[j++] =	uls.item(g);
	}
	
	for(var i=0; i<newUls.length; i++) {								// iterate wide dropdown menus...
		var candidates = newUls[i].getElementsByTagName("li");
		var counter = 0;
		for(var h=0; h < candidates.length; h++){
			if(candidates.item(h).className.match(/empty/)) {
				counter = 0; //reset counter after every class="empty" li tag
			} else if(counter % 2 == 0 && !(candidates.item(h).className.match(/first/))) {
				candidates.item(h).className = 	candidates.item(h).className + "rightBorder";
				counter++;
			} else if(!(candidates.item(h).className.match(/first/))) {
				candidates.item(h).className = candidates.item(h).className + "leftBorder";	
				counter++;
			}
		}
	}
}

/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Version 2.1
 * 
 * Thanks to 
 * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 * Tom Leonard for some improvements
 * 
 */
jQuery.fn.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* To get the document params:
* @example value = $(document).getUrlParam("paramName");
* 
* To get the params of a html-attribut (uses src attribute)
* @example value = $('#imgLink').getUrlParam("paramName");
*/ 
 getUrlParam: function(strParamName){
	  strParamName = escape(unescape(strParamName));
	  
	  var returnVal = new Array();
	  var qString = null;
	  
	  if (jQuery(this).attr("nodeName")=="#document") {
	  	//document-handler
		
		if (window.location.search.search(strParamName) > -1 ){
			
			qString = window.location.search.substr(1,window.location.search.length).split("&");
		}
			
	  } else if (jQuery(this).attr("src")!="undefined") {
	  	
	  	var strHref = jQuery(this).attr("src")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else if (jQuery(this).attr("href")!="undefined") {
	  	
	  	var strHref = jQuery(this).attr("href")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else {
	  	return null;
	  }
	  	
	  
	  if (qString==null) return null;
	  
	  
	  for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split("=")[0])) == strParamName){
				returnVal.push(qString[i].split("=")[1]);
			}
			
	  }
	  
	  
	  if (returnVal.length==0) return null;
	  else if (returnVal.length==1) return returnVal[0];
	  else return returnVal;
	}
});

/********* fading functions **********/

//toggles visibility of element for which this function is invoked with a fade transition effect
//Only works with jQuery(...) (aka '$(...)') objects
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 

/**
 *	Description: This function is used to fade out a current psuedo-page's content (a div or other container type) and fade in the 
 *	new psuedo-page's content (a container with previous display css attribute set to 'none').  
 *	idToLoad: id of Div to fade in
 *	thisLink (optional): handle for links to be formated as 'in focus' (i.e. for which links should underlining be removed when  
 *																		idToLoad is shown)
 *
 *	
 *	Details: Each psuedo-page should be contained in a div, initialized with the css attribute 'display: none' and a unique id which 
 * 		must be passed to idToLoad. 
 *	thisLink is used to determine which links to display as 'in focus', and must be a handle representing the links associated with 
 * 		the currently active section.  When called from an onclick event the 'this' keyword works.  When loadNewSection() is called 
 *		at page initialization a class name uniquely identifying the links which are desired to be designated 'in focus' works.
 *	When a section fades in it's assigned .currentSubSection, and when an element needs to be faded out before fading another element
 * 		in, the element to fade out is identified by the .currentSubSection class.
 */
function loadNewSection(idToLoad,thisLink) {
	$('.currentSubSection').fadeToggle();
	$('.currentSubSection').removeClass("currentSubSection");
	$('.focusedSection').removeClass('focusedSection');
	if(thisLink) {
		var pageClass = thisLink.className.match(/page.Link/);
		$('.'+pageClass).addClass('focusedSection');
	}
	
	setTimeout(function() { //The timeout is necessary to give the old active section time to fade out before the new one fads in.
		$("#"+idToLoad).fadeIn();  
		setTimeout(function() {
			reAdjustHeights(); 
		},350);
		$("#"+idToLoad).addClass("currentSubSection");
	},350);
}

/************ lightbox and init functions ***************/

//replaces the src of the function's $(this) object with the absolute path specified as a string in the function's argument.
jQuery.fn.fadeReplace = function(newImgSrc) {
	var oldImg = $(this);
	oldImg.fadeOut();
	setTimeout(function() {
		oldImg.attr('src',newImgSrc);
		oldImg.fadeIn();
	},350);
}

function initMenu() {
	
	var imgTag = $('#leftLinks ul').prev().children('span').children('img');
	tempImg = $(imgTag[0]);
	tempImg.parent().parent().hasClass("subHighlight")
	
}


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};