
jQuery(document).ready( function() {

	//functions for IE6 to trigger quicklinks from main menu
	jQuery('div#nav-wrapper div#nav ul li').mouseover(function() {														  	
															jQuery(this).children('ul').addClass('visibleSubNav'); 
															jQuery(this).children('ul').css('display','block');
															}); 
	jQuery('div#nav-wrapper div#nav ul li').mouseout(function() {
															jQuery(this).children('ul').removeClass('visibleSubNav');
															jQuery(this).children('ul').css('display','none');
															}); 
	



	//GENERAL DOCUMENT ENHANCEMENT
	jQuery("a.email").each( //Email address obfuscation
		function () {
			e = this.rel.replace("/","@");
			this.href = "mailto:"+e;
			jQuery(this).text(e);
		}
	);

	jQuery("a.external").click( //Open link in new window
		function() {
			window.open(this.href);
			return false;
		}
	);

	jQuery(".rollover").hover( //Rollover images
		function() {
			if(jQuery(this).attr("src").indexOf("-over")==-1) {
				var newSrc = jQuery(this).attr("src").replace(".gif","-over.gif");
				jQuery(this).attr("src",newSrc);
			}
		},
		function() {
			if(jQuery(this).attr("src").indexOf("-over") != -1) {
				var oldSrc = jQuery(this).attr("src").replace("-over.gif",".gif");
				jQuery(this).attr("src",oldSrc);
			}
		}
	);

	jQuery("input.input-text").each ( //Input field default text toggle
		function() {
			this.rel=this.value;
		}
	);

	jQuery("input.input-text").focus(function() {
		if (this.value==this.rel) {
			this.value='';
		}
	});

	jQuery("input.input-text").blur(function() {
		if (this.value=='') {
			this.value=this.rel;
		}
	});
	
	//Styling last Child Element in List
	jQuery("div#main-wrapper div#main div.white-lists div.column ul li:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });
	jQuery("div#main-wrapper div#left-col div#useful ul li:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });
	jQuery("div#main-wrapper div#main div#home-left-col div#news-carousel-middle ul li:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });
	jQuery("div#footer-wrapper div#footer ul li:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });
	jQuery("div.box-right table tr td:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });
	jQuery("div#whitebox table tr:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });
	jQuery("div.double:last-child").each(
		function(){																	
              jQuery(this).addClass("last");
            });

	
	//ACCORDION
	//jQuery("#accordion").each (
		//function() {
			//jQuery(this).accordion({ header: 'p.heading' }); //Initialise accordion
			
			/*var currentIndex=jQuery("#accordion h2").eq(0); //Set current active heading

			jQuery("#accordion h2").click ( //Active heading click event
				function() {
					currentIndex.removeClass();
					jQuery(this).addClass("active");
					currentIndex=jQuery(this);
				}
			);*/
		//}
	//);
	
	
	//NEWS SCROLLING CAROUSEL
	jQuery("#news-carousel").each (
		function() {

			var scrollValue=jQuery("#news-carousel").css("width"); //Get incremental scroll value
			scrollValue=scrollValue.replace("px","");
			
			var numberOfItems=Math.ceil(jQuery("#news-carousel #scroller .news-item").length/2); //Get number of scroll increments

			var currentThumbnail=jQuery("#news-carousel-top ol li").eq(0); //Set current active thumbnail

			for (jQueryi=0; jQueryi<=jQuery("#news-carousel-top ol li").length; jQueryi++) { //Set thumbnail indices
				jQuery("#news-carousel-top ol li").eq(jQueryi).attr("rel",jQueryi);
			}

			jQuery("#news-carousel-top ol li").hover( //Thumbnail rollovers event
				function() {
					if(jQuery("img",this).attr("src").indexOf("-active")==-1) {
						var newSrc = jQuery("img",this).attr("src").replace(".gif","-active.gif");
						jQuery("img",this).attr("src",newSrc);
					}
				},
				function() {
					if(jQuery("img",this).attr("src").indexOf("-active")!=-1 && jQuery(this).attr("className")!="active") {
						var oldSrc = jQuery("img",this).attr("src").replace("-active.gif",".gif");
						jQuery("img",this).attr("src",oldSrc);
					}
				}
			);

			jQuery("#news-carousel-top ol li").click ( //Thumbnail click event
				function () {
					var jQueryindex=jQuery(this).attr("rel"); //Set new index

					jQuery("img",currentThumbnail).attr("src","/images/buttons/news-carousel.gif"); //Deactivate current thumbnail
					currentThumbnail.removeClass();

					jQuery("#scroller").animate({left: (scrollValue*(jQueryindex)*-1)}, {duration: 500, easeMethod: "easeInOut"}); //Scroll carousel
					
					currentThumbnail=jQuery("#news-carousel-top ol li").eq(jQueryindex); //Set current active thumbnail
					currentThumbnail.addClass("active");
					
					return false;
				}
			);

		}
	);
	
	//TABBED CONTENT (Contact forms)
	jQuery("#tabbed-content").each (
		function() {
			var numberOfTabs=jQuery("#tabbed-content ul#tab-list li").length; //Get number of tabs

			for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) { //Set tab indices and hide tabs
				jQuery("#tabbed-content ul#tab-list li").eq(jQueryi).attr("rel",jQueryi);
				jQuery("#tabbed-content .tab").eq(jQueryi).css("display","none");
			}
			jQuery("#tabbed-content .tab").eq(0).css("display","block");

			jQuery("#tabbed-content ul#tab-list li").click ( //Tab click event
				function() {
					showTab(jQuery(this).attr("rel"));
					return false;
				}
			);

			function showTab(jQueryindex) { //Show tab
				for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) {
					jQuery("#tabbed-content .tab").eq(jQueryi).hide();
					jQuery("#tabbed-content .tab").eq(jQueryindex).show();
					
					jQuery("#tabbed-content ul#tab-list li").removeClass();
					jQuery("#tabbed-content ul#tab-list li").eq(jQueryindex).addClass("active");
				}
			}
		}
	);

	//SOCIAL MEDIA TABS (Facebook, Twitter, DCU)
	jQuery("#tabbed-content").each (
		function() {
			var numberOfTabs=jQuery("#social-tabs ul#social-tab-list li").length;

			for (jQueryi=0; jQueryi<=numberOfTabs; jQueryi++) { //Set tab indices and hide tabs
				jQuery("#social-tabs ul#social-tab-list li").eq(jQueryi).attr("rel",jQueryi);
				jQuery("#social-tabs div.tab").eq(jQueryi).css("display","none");
			}
			jQuery("#social-tabs div.tab").eq(0).css("display","block");
			
			jQuery("#social-tabs ul#social-tab-list li").click ( //Tab click event
				function() {
					showTab(jQuery(this).attr("rel"));
					return false;
				}
			);
			
			function showTab(jQueryindex) {
				for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) {
					jQuery("#social-tabs .tab").eq(jQueryi).hide();
					jQuery("#social-tabs .tab").eq(jQueryindex).show();
				}
			}
		}
	);
	
	//SMALL TABBED CONTENT (Generic content, small tabs)
	jQuery("#small-tabbed-content").each (
		function() {
			var numberOfTabs=jQuery("#small-tabbed-content ul#small-tabs li").length; //Get number of tabs

			for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) { //Set tab indices and hide tabs
				jQuery("#small-tabbed-content ul#small-tabs li").eq(jQueryi).attr("rel",jQueryi);
				jQuery("#small-tabbed-content .tab").eq(jQueryi).css("display","none");
			}
			jQuery("#small-tabbed-content .tab").eq(0).css("display","block");

			jQuery("#small-tabbed-content ul#small-tabs li").click ( //Tab click event
				function() {
					showTab(jQuery(this).attr("rel"));
					return false;
				}
			);

			function showTab(jQueryindex) { //Show tab
				for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) {
					jQuery("#small-tabbed-content .tab").eq(jQueryi).hide();
					jQuery("#small-tabbed-content .tab").eq(jQueryindex).show();
					
					jQuery("#small-tabbed-content ul#small-tabs li").removeClass();
					jQuery("#small-tabbed-content ul#small-tabs li").eq(jQueryindex).addClass("active");
				}
			}
		}
	);
	
	
	
	//SIMPLE TABBED CONTENT (Generic content, small tabs)
	jQuery(".simple-tabbed-content").each (
		function() {
			var numberOfTabs=jQuery(".simple-tabbed-content ul#tab-list li").length; //Get number of tabs

			for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) { //Set tab indices and hide tabs
				jQuery(".simple-tabbed-content ul#tab-list li").eq(jQueryi).attr("rel",jQueryi);
				jQuery(".simple-tabbed-content .tab").eq(jQueryi).css("display","none");
			}
			jQuery(".simple-tabbed-content .tab").eq(0).css("display","block");

			jQuery(".simple-tabbed-content ul#tab-list li").click ( //Tab click event
				function() {
					showTab(jQuery(this).attr("rel"));
					return false;
				}
			);

			function showTab(jQueryindex) { //Show tab
				for (jQueryi=0; jQueryi<numberOfTabs; jQueryi++) {
					jQuery(".simple-tabbed-content .tab").eq(jQueryi).hide();
					jQuery(".simple-tabbed-content .tab").eq(jQueryindex).show();
					
					jQuery(".simple-tabbed-content ul#tab-list li a").removeClass("active");
					jQuery(".simple-tabbed-content ul#tab-list li a").eq(jQueryindex).addClass("active");
				}
			}
		}
	);
	
	
	
	jQuery("#social-media ul li img").each ( //Social media icon rollover fade effect
		function() {
			jQuery(this).css("opacity",0.8);
		}
	);
	
	jQuery("#social-media ul li img").hover (
		function() {
			jQuery(this).fadeTo("fast",1.0);
		},
		function() {
			jQuery(this).fadeTo("fast",0.8);
		}
	);
	
	//BREADCRUMBS

	//String.noLC = new Object ({the:1, a:1, an:1, and:1, or:1, but:1, aboard:1, about:1, above:1, across:1, after:1, against:1, along:1, amid:1, among:1, around:1, as:1, at:1, before:1, behind:1, below:1, beneath:1, beside:1, besides:1, between:1, beyond:1, but:1, by:1, 'for':1, from:1, 'in':1, inside:1, into:1, like:1, minus:1, near:1, of:1, off:1, on:1, onto:1, opposite:1, outside:1, over:1, past:1, per:1, plus:1, regarding:1, since:1, than:1, through:1, to:1, toward:1, towards:1, under:1, underneath:1, unlike:1, until:1, up:1, upon:1, versus:1, via:1, 'with':1, within:1, without:1});
	//String.prototype.titleCase = function () {var parts = this.split(' '); if ( parts.length == 0 ) return ''; var fixed = new Array(); for ( var i in parts ) {var fix = ''; if ( String.noLC[parts[i]] ) {fix = parts[i].toLowerCase();} else if ( parts[i].match(/^([A-Z]\.)+$/i) ) {fix = parts[i].toUpperCase();} else if ( parts[i].match(/^[^aeiouy]+$/i) ) {fix = parts[i].toUpperCase();} else {fix = parts[i].substr(0,1).toUpperCase() + parts[i].substr(1,parts[i].length);} fixed.push(fix); } fixed[0] = fixed[0].substr(0,1).toUpperCase() + fixed[0].substr(1,fixed[0].length); return fixed.join(' ');}
function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}
	if(jQuery('#breadcrumbs ol')) {
		var crumbs =window.location.pathname.split('/'), i, u ='/', p, currLink;
		for(i=0;i<crumbs.length -1;i++) if(crumbs[i].length) {
			u += crumbs[i] + '/';
			b = capitaliseFirstLetter(crumbs[i]);
			jQuery('#breadcrumbs ol').append('<li><a href="' +u+ '">' + b + '</a></li>');
		}
		p =crumbs.pop();
		jQuery('#breadcrumbs ol').append('<li>' + jQuery('title').text() + '</li>');
		//jQuery('#breadcrumbs ol').append('<li>' + p.replace(/\.[^.]+jQuery/, '').replace(/\-/g, ' ').titleCase() + '</li>');
	
	}


	if(jQuery('#accordion'))  {
		var lUrl, lAbs, lRel, foundLink;
		if(jQuery('#subnav').length>0) {
			lUrl =document.location.href;
			lAbs =window.location.pathname;
			lRel =window.location.pathname.substring(window.location.pathname.lastIndexOf('/')+1);
			for(i=0;i<jQuery('#subnav p').length; i++) if(jQuery('#subnav p:eq(' + i + ') a').attr('href')!='#') jQuery('#subnav p:eq(' + i + ')').addClass('link'); 
			var mainlinks =jQuery('#subnav p.link');
			for(i =0; i<mainlinks.length; i++) {
				currLink =jQuery('#subnav p.link:eq(' + i + ') a').attr('href');
				if(currLink===lRel || currLink===lAbs || currLink===lUrl) {
					jQuery('.ui-state-active').removeClass('ui-state-active');
					jQuery('#subnav p.link:eq(' + i + ')').addClass('link-active');
					foundLink =true;
					jQuery('#subnav').accordion({header: 'p:not(.link)', collapsible: true, active: false, changestart: function(event, ui) {jQuery('#subnav p.link-active').removeClass('link-active');}});				
					break;
				}
				
			}
			
			var parents =jQuery('#subnav p:not(.link)'), j, children, child, gchildren, path =window.location.pathname;
			if(!foundLink) for(i =0; i<parents.length; i++) {
				children =jQuery('#subnav ul:eq('+i+') li');
				//if(jQuery(children).length=='0' && jQuery('#subnav p:eq(' + i + ') a').attr('href')!='#') jQuery('#subnav p:eq(' + i + ')').addClass('link'); 
				for(j =0; j<jQuery(children).length; j++) {
					currLink =jQuery(children[j]).children('a').attr('href');
					if(currLink===lRel || currLink===lAbs || currLink===lUrl) {
						jQuery('#subnav').accordion({header: 'p:not(.link)', active: i });
						
						jQuery(children[j]).html(jQuery(children[j]).children('a').html());
						jQuery(children[j]).addClass('active');
						foundLink =true;
						break;
					}
				}
			}
		}
		if(!foundLink) {
			if (jQuery('#subnav').length) jQuery('#subnav').accordion({header: 'p:not(.link)', active: 100}); 
			//changed from 0(the first list menu) to 100 for sub navigation menu jquery.accordion effect 240810 by Yang
			
			else {
				jQuery('#accordion').accordion({header: 'p.heading:not(.link)', active: 0});
			}
		}
	}
	jQuery.fn.captioned =function() {
		var alt, src, w, h;
		this.each(function() {
			src =jQuery(this).attr('src');
			w =jQuery(this).width();
			h =jQuery(this).height();
			alt =jQuery(this).attr('alt');
			jQuery(this).replaceWith('<table style="width: '+w+'px; height: '+h+'px;" class="captionedImage" cellpadding="0" cellspacing="0" border="0"><tr><td valign="bottom" style="background: url('+src+'); width: '+w+'px; height: '+h+'px;"><div class="caption">'+alt+'</div></div>');
		});
		return(this);
		
	}
	jQuery('.captioned').captioned();
	
	
	
	if(jQuery('.smallbox-columns .smallbox').length>1) {
		for(var i=0; i<jQuery('.smallbox-columns .smallbox').length; i=i+2) if(i<jQuery('.smallbox-columns .smallbox').length) {
			var lB =jQuery('.smallbox-columns .smallbox:eq(' + i + ') a .rollover').offset().top;
			var rB =jQuery('.smallbox-columns .smallbox:eq(' + (i+1) + ') a .rollover').offset().top;
			if(lB>rB) {
				var t = jQuery('.smallbox-columns .smallbox:eq(' + i + ') a .rollover').css('marginTop').replace(/.*[\w]/, '') + (lB -rB) + 'px';
				jQuery('.smallbox-columns .smallbox:eq(' + (i+1) + ') a .rollover').css({marginTop: t});
			}else if(rB>lB) {
				var t = jQuery('.smallbox-columns .smallbox:eq(' + (i+1) + ') a .rollover').css('marginTop').replace(/.*[\w]/, '') + (rB -lB) + 'px';
				jQuery('.smallbox-columns .smallbox:eq(' + i + ') a .rollover').css({marginTop: t});
			}
		}
	}
	

//style search results
if(jQuery('.search-result ul').length>0) {
	var i, j, gc =jQuery('.search-result ul'), rc =0;
	for(i =0; i<gc.length; i++) {
		rc =jQuery('.search-result ul:eq(' + i + ') li');
		for(j =0; j<rc.length; j++) {
			if(j/2!=Math.round(j/2)) jQuery('.search-result ul:eq(' + i + ') li:eq(' + j + ')').addClass('alt');
		}
	}
	
		
}


	//For HR Training Categories Hide (Collapse) the toggle containers on load
	jQuery(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	jQuery("h2.trigger").click(function(){
		jQuery(this).toggleClass("active").next().slideToggle("slow");


});

		// For pop up window 
		var windowSizeArray = [ "width=956,height=712", "width=300,height=400,scrollbars=yes" ];
		
		
		jQuery('.newWindow').click(function (event){

			var url = jQuery(this).attr("href");

			var windowName = "popUp";//jQuery(this).attr("name");

			var windowSize = windowSizeArray[jQuery(this).attr("rel")];

			window.open(url, windowName, windowSize);

			event.preventDefault();

		});
		
		
		
		
		
		function initMenu() {
		  jQuery('#menu ul').hide();
		  jQuery('#menu li a').click(
			function() {
				jQuery(this).next().slideToggle('normal');	
				
			  }
			);
			
			var url = window.location.toString();
			
				jQuery('#menu li a').each(function(){
					  var myHref= jQuery(this).attr('href');
					  if( url.match(myHref)) {
						   jQuery(this).addClass('active')
							jQuery(this).closest('ul').show();
					  }
				});

			
		  }
	
	
		initMenu();		




	jQuery("#showHide #accordion div").hide();

	jQuery("#showHide #accordion h4").click(function(){
		jQuery(this).next("div").slideToggle("slow").siblings("div:visible").slideUp("slow");
		jQuery(this).toggleClass("active");
		jQuery(this).siblings("h4").removeClass("active");
		return false;
	});
	
	jQuery("#showHide #accordion .close").click(function(){
		jQuery(this).parent().slideUp("slow");
		jQuery(this).fadeOut('fast');	
		
		jQuery(window).scrollTop( jQuery("#accordion").offset().top, 1500);		
		
		return false;
	});
	
		
	




(function(jQuery) {
	jQuery.fn.listnav = function(options) {
		var opts = jQuery.extend({}, jQuery.fn.listnav.defaults, options);
		var letters = ['_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-'];
		var firstClick = false;
		opts.prefixes = jQuery.map(opts.prefixes, function(n) { return n.toLowerCase(); });

		return this.each(function() {
			var jQuerywrapper, list, jQuerylist, jQueryletters, jQueryletterCount, id;
			id = this.id;
			jQuerywrapper = jQuery('#' + id + '-nav'); // user must abide by the convention: <ul id="myList"> for list and <div id="myList-nav"> for nav wrapper
			jQuerylist = jQuery(this);

			var counts = {}, allCount = 0, isAll = true, numCount = 0, prevLetter = '';

			function init() {
				jQuerywrapper.append(createLettersHtml());

				jQueryletters = jQuery('.ln-letters', jQuerywrapper).slice(0, 1); // will always be a single item
				if (opts.showCounts) jQueryletterCount = jQuery('.ln-letter-count', jQuerywrapper).slice(0, 1); // will always be a single item

				addClasses();
				addNoMatchLI();
				if (opts.flagDisabled) addDisabledClass();
				bindHandlers();

				if (!opts.includeAll) jQuerylist.show(); // show the list in case the recommendation for includeAll=false was taken

				// remove nav items we don't need
				//
				if (!opts.includeAll) jQuery('.all', jQueryletters).remove();
				if (!opts.includeNums) jQuery('._', jQueryletters).remove();
				if (!opts.includeOther) jQuery('.-', jQueryletters).remove();

				jQuery(':last', jQueryletters).addClass('ln-last'); // allows for styling a case where last item needs right border set (because items before that only have top, left and bottom so that border between items isn't doubled)
				
				if (jQuery.cookie && (opts.cookieName != null)) {
					var cookieLetter = jQuery.cookie(opts.cookieName);
					if (cookieLetter != null) opts.initLetter = cookieLetter;
				}

				// decide what to show first
				//
				if (opts.initLetter != '') {
					firstClick = true;
					jQuery('.' + opts.initLetter.toLowerCase(), jQueryletters).slice(0, 1).click(); // click the initLetter if there was one
				}
				else {
					if (opts.includeAll) jQuery('.all', jQueryletters).addClass('ln-selected'); // showing all: we don't need to click this: the whole list is already loaded
					else { // ALL link is hidden, click the first letter that will display LI's
						for (var i = ((opts.includeNums) ? 0 : 1); i < letters.length; i++) {
							if (counts[letters[i]] > 0) {
								firstClick = true;
								jQuery('.' + letters[i], jQueryletters).slice(0, 1).click();
								break;
							}
						}
					}
				}
			}

			// positions the letter count div above the letter links (so we only have to do it once: after this we just change it's left position via mouseover)
			//
			function setLetterCountTop() {
				jQueryletterCount.css({ top: jQuery('.a', jQueryletters).slice(0, 1).offset({ margin: false, border: true }).top - jQueryletterCount.outerHeight({ margin: true }) }); // note: don't set top based on '.all': it might not be visible
			}

			// adds a class to each LI that has text content inside of it (ie, inside an <a>, a <div>, nested DOM nodes, etc)
			//
			function addClasses() {
				var str, firstChar, firstWord, spl, jQuerythis, hasPrefixes = (opts.prefixes.length > 0);
				jQuery(jQuerylist).children().each(function() {
					jQuerythis = jQuery(this), firstChar = '', str = jQuery.trim(jQuerythis.text()).toLowerCase();
					if (str != '') {
						if (hasPrefixes) {
							spl = str.split(' ');
							if ((spl.length > 1) && (jQuery.inArray(spl[0], opts.prefixes) > -1)) {
								firstChar = spl[1].charAt(0);
								addLetterClass(firstChar, jQuerythis, true);
							}
						}


						firstChar = str.charAt(0);
						addLetterClass(firstChar, jQuerythis);
					}
				});
			}

			function addLetterClass(firstChar, jQueryel, isPrefix) {
				if (/\W/.test(firstChar)) firstChar = '-'; // not A-Z, a-z or 0-9, so considered "other"
				if (!isNaN(firstChar)) firstChar = '_'; // use '_' if the first char is a number
				jQueryel.addClass('ln-' + firstChar);

				if (counts[firstChar] == undefined) counts[firstChar] = 0;
				counts[firstChar]++;
				if (!isPrefix) allCount++;
			}

			function addDisabledClass() {
				for (var i = 0; i < letters.length; i++) {
					if (counts[letters[i]] == undefined) jQuery('.' + letters[i], jQueryletters).addClass('ln-disabled');
				}
			}

			function addNoMatchLI() {
				jQuerylist.append('<li class="ln-no-match" style="display:none">' + opts.noMatchText + '</li>');
			}

			function getLetterCount(el) {
				if (jQuery(el).hasClass('all')) return allCount;
				else {
					var count = counts[jQuery(el).attr('class').split(' ')[0]];
					return (count != undefined) ? count : 0; // some letters may not have a count in the hash
				}
			}

			function bindHandlers() {

				// sets the top position of the count div in case something above it on the page has resized
				//
				if (opts.showCounts) {
					jQuerywrapper.mouseover(function() {
						setLetterCountTop();
					});
				}

				// mouseover for each letter: shows the count above the letter
				//
				if (opts.showCounts) {
					jQuery('a', jQueryletters).mouseover(function() {
						var left = jQuery(this).position().left;
						var width = (jQuery(this).outerWidth({ margin: true }) - 1) + 'px'; // the -1 is to tweak the width a bit due to a seeming inaccuracy in jquery ui/dimensions outerWidth (same result in FF2 and IE6/7)
						var count = getLetterCount(this);
						jQueryletterCount.css({ left: left, width: width }).text(count).show(); // set left position and width of letter count, set count text and show it
					});

					// mouseout for each letter: hide the count
					//
					jQuery('a', jQueryletters).mouseout(function() {
						jQueryletterCount.hide();
					});
				}

				// click handler for letters: shows/hides relevant LI's
				//
				jQuery('a', jQueryletters).click(function() {
					jQuery('a.ln-selected', jQueryletters).removeClass('ln-selected');

					var letter = jQuery(this).attr('class').split(' ')[0];

					if (letter == 'all') {
						jQuerylist.children().show();
						jQuerylist.children('.ln-no-match').hide();
						isAll = true;
					} else {
						if (isAll) {
							jQuerylist.children().hide();
							isAll = false;
						} else if (prevLetter != '') jQuerylist.children('.ln-' + prevLetter).hide();

						var count = getLetterCount(this);
						if (count > 0) {
							jQuerylist.children('.ln-no-match').hide(); // in case it's showing
							jQuerylist.children('.ln-' + letter).show();
						}
						else jQuerylist.children('.ln-no-match').show();

						prevLetter = letter;
					}

					if (jQuery.cookie && (opts.cookieName != null)) jQuery.cookie(opts.cookieName, letter);


					jQuery(this).addClass('ln-selected');
					jQuery(this).blur();
					if (!firstClick && (opts.onClick != null)) opts.onClick(letter);
					else firstClick = false;
					return false;
				});
			}

			// creates the HTML for the letter links
			//	
			function createLettersHtml() {
				var html = [];
				for (var i = 1; i < letters.length; i++) {
					if (html.length == 0) html.push('<a class="all" href="#">ALL</a>');
					html.push('<a class="' + letters[i] + '" href="#">' + ((letters[i] == '-') ? '...' : letters[i].toUpperCase()) + '</a>');
				}
				return '<div class="ln-letters">' + html.join('') + '</div>' + ((opts.showCounts) ? '<div class="ln-letter-count" style="display:none; position:absolute; top:0; left:0; width:20px;">0</div>' : ''); // the styling for ln-letter-count is to give us a starting point for the element, which will be repositioned when made visible (ie, should not need to be styled by the user)
			}

			init();
		});
	};

	jQuery.fn.listnav.defaults = {
		initLetter: '',
		includeAll: true,
		incudeOther: false,
		includeNums: true,
		flagDisabled: true,
		noMatchText: 'No matching entries',
		showCounts: true,
		cookieName: null,
		onClick: null,
		prefixes: []
	};
})(jQuery);

jQuery('#myList').listnav({
 	initLetter: 'a', 
    includeAll: true, 
    includeOther: false, 
    flagDisabled: true, 
	showCounts: true,
    noMatchText: 'No matching entries, please click another letter.', 
    cookieName: 'my-main-list'}
);

});
	


