
	var navOpen = false;
	var whichNav = '';

	$(document).click(function(e) {

		if( navOpen ) {
			if( !$(e.target).closest("#nav").length || $(e.target).parent('li').hasClass('xout') ) {
				navOpen = false;
				$('ul.opened').slideUp('slow');
			}
		}
	});


	$(document).ready(function() {

		if( IE6 ) {
			$('html').css('overflow-y', 'hidden');
			$('#bg').css('position', 'absolute');
			$('#container').css({
				position: 'absolute',
				height: '100%',
				overflow: 'auto',
				zIndex: 2
			});

			setTimeout( 'setHeaderIE6()', 100 );

		}

		// fix the page anchors
		$("a[name]").each( function() {
			var name = $(this).attr('name');
			$(this).parent().attr('id', name);
		});

		$("a[href*='#']").click(function() {
			linkpage = this.href.substring(0,this.href.indexOf('#'));
			lochref = location.href.substring(0,this.href.indexOf('#'));
			if( lochref == linkpage ) {
				var hash = $(this).attr('href');
				hash = hash.substring(hash.indexOf('#'));

				if(IE6) {
					$('#container').scrollTo( hash, 800, {
						offset: {top:-100,left:0}
					});
				} else {
					$('body').scrollTo( hash, 800, {
						offset: {top:-100,left:0}
					});
				}
				return false;
			}

		});


		if( location.hash.length ) {
			$(window).load(function(){
				$('body').scrollTo( location.hash, 300, {
					offset: {top:-100,left:0}
				});
			});
		}


/** NAV, SUBNAV, TABS **/

		$('ul#nav>li').children('ul').addClass('opened');
		$('ul#nav>li>a').attr('href', 'javascript:;').live('click', function() {
			if( navOpen ) {
				if(whichNav == $(this).attr('id')) {
					navOpen = false;
					$('ul.opened').slideUp('slow');
				} else {
					$('ul.opened').hide();
					$(this).siblings('ul').show();
					whichNav = $(this).attr('id');
				}
			} else {
				$(this).siblings('ul').slideDown('slow');
				navOpen = true;
				whichNav = $(this).attr('id');
			}
			return false;
		}).mouseover( function() {
			/*
			if( navOpen ) {
				$('ul.opened').hide();
				$(this).siblings('ul').show();
			}
			*/
		});

		$('ul.subnav').not('.calendar_subnav').children('li').mouseover( function() {
			if( $(this).children('a[href]').length )
				$(this).addClass('on');
		}).mouseout( function() {
			$(this).removeClass('on');
		});

		$('ul.subnav li.active').closest('li.here').removeClass('here').unbind('mouseover');

		$('ul.tab').find('a').live('click', function() {
			var $li = $(this).parent();
			var index = $li.parent().children('li').index($li);
			$content = $li.parent().next('ul.tab-content');
			$content.children('li').hide();
			$content.children('li').eq(index).show();
			$li.parent().children('li').removeClass('on').children('a').removeClass('on');
			$li.addClass('on').children('a').addClass('on');
			return false;
		});


	});

	function fixWindow() {

		var win = dynamItWindowSize();
		var scrollBarWidth = parseInt($('#container').width(), 10) - parseInt($('#inside').width(), 10);


		if( $("#main").height() + 122 > $("#container").height()) {

			var offsetLeft = ($("#container").width() - scrollBarWidth - 1000) / 2;
			$("#header").css('left', offsetLeft + 'px');
		}

	}

	function backgroundDetails(p) {

		if( $('#carousel .photo').length ) {
			$('#carousel').slideDown('slow');
		} else {

			$('#carousel').html('')
				.append( '<img src="/bgthumb.php?p=' + p + '" alt="" class="photo" />' )
				.append( '<p class="caption">' + $('#bg p').html() + '</p>' )
				.append( '<div id="close"><a href="javascript:closeCarousel();"><img src="/img/btn-closeimg.png" alt="close" /></a></div>' )
				.slideDown('slow');
		}
	}


	//
	// closeCarousel
	//
	// slide up the carousel
	//
	function closeCarousel() {
		$('#carousel').slideUp('slow');
	}


	function setHeaderIE6() {
		var offset_x = ($('#inside').width() - 1000) / 2;
		$('#header').remove().insertAfter('#container').css({
			position: 'absolute',
			top: '0px',
			left: offset_x + 'px',
			zIndex: 3
		});
	}

	function openWindow(dest, width, height) {

		if(!width) var width = 575;
		if(!height) var height = 425;

		var extra = 'width=' + width + ', height= ' + height;

  		window.open(dest, 'myWindow', extra);

	}


	//
	// Donation Form Effects
	//
	
	$(document).ready(function() {
	
		if(IE6) {
			$('input[type="text"]').addClass("txt");
		}
		
		$("input#general").click(function(){
			$("div#scholarshiphide:visible").slideUp();
			$("div#endowmenthide:visible").slideUp();
			$("div#creativehide:visible").slideUp();
			$("div#generalhide").slideDown();
		});
		$("input#scholarship").click(function(){
			$("div#generalhide:visible").slideUp();
			$("div#endowmenthide:visible").slideUp();
			$("div#creativehide:visible").slideUp();
			$("div#scholarshiphide").slideDown();
		});
		$("input#endowment").click(function(){
			$("div#generalhide:visible").slideUp();
			$("div#scholarshiphide:visible").slideUp();
			$("div#creativehide:visible").slideUp();
			$("div#endowmenthide").slideDown();
		});
		$("input#creative").click(function(){
			$("div#generalhide:visible").slideUp();
			$("div#scholarshiphide:visible").slideUp();
			$("div#endowmenthide:visible").slideUp();
			$("div#creativehide").slideDown();
		});
		
		$("input#neither").click(function(){
			$("span#honhide:visible").fadeOut("fast");
			$("span#memhide:visible").fadeOut("fast");
		});
		$("input#honorary").click(function(){
			$("span#memhide:visible").fadeOut("fast");
			$("input#memoryof").val("");
			$("span#honhide:hidden").fadeIn("fast");
		});
		$("input#memorial").click(function(){
			$("span#honhide:visible").fadeOut("fast");
			$("input#honorof").val("");
			$("span#memhide:hidden").fadeIn("fast");
		});
		
		if($('input#x_phone').val() == '000-000-0000') $('input#x_phone').css('color', '#999999');
		if($('input#wphone').val() == '000-000-0000') $('input#wphone').css('color', '#999999');
		
		$('input#x_phone').focus(function() {
			if($(this).val() == '000-000-0000') $(this).val('');
			$(this).css('color', '#333333');
		});
		$('input#wphone').focus(function() {
			if($(this).val() == '000-000-0000') $(this).val('');
			$(this).css('color', '#333333');
		});
		
		$("input#corpmatch").click(function(){
			if (this.checked) {
				$("input#corpname").attr("verify", "nonempty");
				$("input#corpname").attr("error", "Please enter your company name.");
				$("div#corphide").show("fast");
			} else {
				$("input#corpname").removeAttr("verify");
				$("input#corpname").removeAttr("error");
				$("div#corphide").hide("fast");
				$("input#corpname").val("");
			}
		});
	
	});