function mainmenu () {
	$("#mainmenu li").  each(function() {
		$(this).hover(function() {
			$(this).find('ul').stop(true,true).css('display','none');
			$(this).find('ul').fadeIn (100);
			},function(){
			$(this).find('ul').stop(true,true).fadeOut(200, function() {
				$(this).css('display','none');
			});
		})
	})
}

//Function to convert hex format to a rgb color  
function rgb2hex(rgb) {
	
	//see if already returned rgb color - probably not bulletproof here
	if (rgb.substr(0,1) == "#") {
		return rgb.substr(1);
	} else {
		rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);  
		function hex(x) {  
			hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");  
	 		return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];  
		}
		return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
	}
}  

//replace headings
function replaceHeadingGuts (theobject, fontsize, theheight, thewidth, fontLetterSpacing, fontOffsetX, fontOffsetY) {
	
	//set defaults
	if (!fontLetterSpacing) { fontLetterSpacing = 0; }
	if (!fontOffsetX) { fontOffsetX = -3; }
	if (!fontOffsetY) { fontOffsetY = 0; }
	
	$(theobject).each(function (){
		content = $(this).text();
		$(this).css('height', theheight+"px");

		//in the fck, if an internal link is added, the text is wrapped with a <a name="x">content</a>
		//this line pulls the name into the heading itself so internal anchors/links still work
		if($(this).find('a').attr('name')) $(this).attr('id', $(this).find('a').attr('name'));
		
		//element size
		$(this).css('height', theheight+"px");
		$(this).css('width', thewidth+"px");
		
		$(this).flashembed({
			//flashembed vars
			src: "/assets/flash/heading.swf",
			version: [9, 0], //required to prevent replacement on mobiles
			wmode: "transparent",
			width: "100%",
			height: "100%",
			scale: "noscale",
			salign: "lt" }, {
			//vars to flash file
			headingText: encodeURIComponent(content),
			headingColor: "0x" + rgb2hex ($(this).css('color')),
			headingSize: fontsize,
			headingLetterSpacing: fontLetterSpacing,
			headingOffsetX: fontOffsetX,
			headingOffsetY: fontOffsetY });
	});
}

function dummyTextSearchBox() {
	var searchDefaultText = 'Site Search';
	$("#queryStringBox").focus(function () {
		if($(this).val() == searchDefaultText) {
			$(this).val('');
		}
	});
	$("#queryStringBox").blur(function () {
		if($(this).val() == '') {
			$(this).val(searchDefaultText);
		}
	});
}


function replaceHeading(){
	replaceHeadingWidth = $('#bodAt_events').length > 0 ? "620" : "700";
	replaceHeadingGuts("#copyCopy h1", "25", "40", replaceHeadingWidth);
	replaceHeadingGuts("#copyCopy h2", "25", "40", replaceHeadingWidth);
	replaceHeadingGuts("#copyCopy h3:not(.calendarH3)", "25", "40", replaceHeadingWidth);
	if($('#searchPage').length != 1) replaceHeadingGuts("#copyCopy h4:not(.calendarH4)", "22", "35", replaceHeadingWidth);
	replaceHeadingGuts("#footer h5", "20", "35", "220", "1");
}



$(document).ready(function() { 
	if( $('#feature').length > 0 ) $('#feature').cycle({ fx: 'fade', speed: 500, timeout: 5000});
	mainmenu ();
	dummyTextSearchBox();
	//turn off these two for ie6 to speed things up
	if (!($.browser.msie && $.browser.version=="6.0")) {
		replaceHeading ();
	}
	
});
