$("document").ready(function() {

		// if modal dialog plugin is present
	if($.jqm) {
		var dialogReposition = function() {
			var dialog = $("div#modalDialog");
			var innerHeight = $(window).height();
			if(window.innerHeight) {
				innerHeight = window.innerHeight;
			}
			else if(document.documentElement.clientHeight) {
				innerHeight = document.documentElement.clientHeight;
			}
			if(innerHeight < 730) {
				var top = innerHeight - 570;
				if(top < 10) {
					top = 10;
				}
				if($.browser.msie && $.browser.version === "6.0") {
					top = top + document.documentElement.scrollTop;
				}
				dialog.css("top", top);
			}
		};

		var index = 0;
		$("div.fhr-profile").each(function(){
			$(this).addClass("fhr-profile" + index);
			index++;
		}).hide();

		$("body").prepend('<div id="modalDialog"></div>');

		/*
	    * w: (jQuery object) The dialog element
	    * c: (object) The config object (dialog's parameters)
	    * o: (jQuery object) The overlay
	    * t: (DOM object) The triggering element
	  */
		$("div#modalDialog").jqm({
	  	modal: true,
	  	overlay: 60,
	  	toTop: true,
	  	trigger: "ul.links li a, a.dialog",
			onShow: function(dialog) {
				dialog.w.append('<div id="close"></div>');
				if($.browser.msie && $.browser.version === "6.0") {
					dialog.w.append('<div class="ie6fix"></div>');
				}
				dialog.w.find("div#close").click(function(){
					dialog.w.jqmHide();
				});
				dialog.w.append($("div.fhr-profile" + $("ul.links li a, a.dialog").index(dialog.t)).show());
				dialogReposition();
	    	dialog.w.show();
	    },
			onHide: function(dialog) {
				if(dialog.o) {
					dialog.o.remove();
				}
				$("body").append($("div.fhr-profile", dialog.w).hide());
				$("*", dialog.w).remove();
				dialog.w.hide();
			}
	  });
	}

	// initialize class clearField for clear/set defaultValue in input text in the searchbox
	$('.clearField').clearField();
	
	// Make sitemap content equal height
	$.fn.equalHeights = function(px) {
		$(this).each(function(){
			var currentTallest = 0;
			$(this).children().each(function(i){
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			});
			if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
			// for ie6, set height since min-height isn't supported
			if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
			$(this).children().css({'min-height': currentTallest}); 
		});
		return this;
	};
	
	$(function(){ $('ul.sitemap-level-1').equalHeights(); });
});




/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};



