var Site = {
	
	start: function(){
		// Curve corners!
		//Site.curvedCorners();
		
		// Adjust the height of the content area to match height of the navigation area
		Site.autoContentHeight();
		
		//Site.navigationSlider();

		// Internet Explorer 6 global PNG fix
		Site.ie6PNGfix();

		// Preload mouseover states for bottom navigation
		Site.preloadNavigationImages();
		
		// Initiate the events for the bottom navigation drop down menus
		Site.prepareDropdowns();

		// Set smooth scrolling for anchor tag links
		Site.scrollAnchors();
	},
	
	ie6PNGfix: function() {
		if (is_ie6) {
			if (document.all && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) {
				document.styleSheets[0].addRule('*', 'behavior: url(/css/iepngfix.htc)');
			}	
		}
	},
	
	curvedCorners: function() {
		$('.mainbody').corner({
		tl: { radius: 20 },
		tr: false,
		bl: false,
		br: false,
		antiAlias: true,
		autoPad: true})
	},
	
	autoContentHeight: function() {
		heightNav = $('.navigation').height();

		heightContent = $('#contentBlock').height();
		if(heightNav > (heightContent+140)) { $('#contentBlock').height( heightNav-140 ); }
	},
	
	navigationSlider: function() {
		$(".secondLevel").find("li").each(function(i) {
			$(this).click(function() { 
				//alert('clicked!');
				//return false;
			});
		});
	},
	
	preloadNavigationImages: function() {
		image1 = new Image();
		image2 = new Image();
		image3 = new Image();
		image4 = new Image();
		image5 = new Image();
		image6 = new Image();
		image7 = new Image();
		image8 = new Image();
		
		image1.src = "/images/nav.bottom.whatisit.over.gif";
		image2.src = "/images/nav.bottom.thebenefits.over.gif";
		image3.src = "/images/nav.bottom.planningforit.over.gif";
		image4.src = "/images/nav.bottom.doingit.over.gif";
		image5.src = "/images/nav.bottom.faqs.over.gif";
		image6.src = "/images/nav.bottom.glossary.over.gif";
		image7.src = "/images/nav.bottom.toolkit.over.gif";
		image8.src = "/images/nav.bottom.directory.over.gif";
	},
	
	prepareDropdowns: function() {
		$("li.whatisit").mouseover(function() {
			if($("ul#dropdown_whatisit").is(":hidden")) {
				Site.hideOpenMenus();
				$("ul#dropdown_whatisit").show("slow");
			}
		});
		$("li.thebenefits").mouseover(function() {
			if($("ul#dropdown_thebenefits").is(":hidden")) {
				Site.hideOpenMenus();
				$("ul#dropdown_thebenefits").show("slow");
			}
		});
		$("li.planningforit").mouseover(function() {
			if($("ul#dropdown_planningforit").is(":hidden")) {
				Site.hideOpenMenus();
				$("ul#dropdown_planningforit").show("slow");
			}
		});
		$("li.doingit").mouseover(function() {
			if($("ul#dropdown_doingit").is(":hidden")) {
				Site.hideOpenMenus();
				$("ul#dropdown_doingit").show("slow");
			}
		});
		$("li.faqs").mouseover(function() {
			Site.hideOpenMenus();
		});
		$("li.glossary").mouseover(function() {
			Site.hideOpenMenus();
		});
		$("li.toolkitdownload").mouseover(function() {
			Site.hideOpenMenus();
		});
		$("li.flexdirectory").mouseover(function() {
			Site.hideOpenMenus();
		});
	},
	
	hideOpenMenus: function() {
		$("ul.dropdown").each(function(){
		  if ( !$(this).is(":hidden") ) {
			  $(this).hide("slow");
		  }
		});
	},
	
	scrollAnchors: function() {
		$('a[href*=#]').click(function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
				var $target = $(this.hash);
				$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
				if ($target.length) {
					var targetOffset = $target.offset().top;
					$('html,body').animate({scrollTop: targetOffset}, 1000, 'easeinout');
					return false;
				}
			}
		});
	}
};

$(document).ready(Site.start);
