var thinkPlace = {
	bodyClass: 			'',
	isParentSelected: 	function(element)
	{
		/* use this method if html content is static and has no nav_items with a .selected class
			var parentClassName	= $(element)[0].parentNode.className;

			// If the body contains the same class as our list item
			if (thinkPlace.bodyClass.indexOf( parentClassName ) > -1 ){
				return true;
			}
		*/
		
		if( $(element).parents('li.current_page_ancestor').length > 0 ){
			return true;
		}
		
		return false;
	},
	navHoverIn: 		function(element)
	{
		// don't do the hover thing if the element is selected
		if( $(element).parents('li.current_page_ancestor').length > 0 ){
			return true;
		}
		if( $(element).parents('li.current_page_parent').length > 0 ){
			return true;
		}
		
		if( $(element).parents('li.current_page_item').length > 0 ){
			return true;
		}
		
		// set default css settings, because firefox 2.0 sucks arse.
		$(element).css( {color: "rgb(115,115,119)", backgroundPosition: "0 -496px"} );
		
		// The stop() stops any existing animations
		$(element).stop().animate({ 
				color: "rgb(255,255,255)",
				backgroundPosition: "(0 0)"
		      }, 250 );
	},
	navHoverOut: 		function(element)
	{
		// don't do the hover thing if the element is selected
		if( $(element).parents('li.current_page_ancestor').length > 0 ){
			return true;
		}
		
		if( $(element).parents('li.current_page_parent').length > 0 ){
			return true;
		}
		
		if( $(element).parents('li.current_page_item').length > 0 ){
			return true;
		}
		
		// The stop() stops any existing animations
		$(element).stop().animate({ 
				color: "rgb(115,115,119)",
				backgroundPosition: "(0 -496px)"
		      }, 250 );
	},
	subNavHoverIn: 		function(element)
	{
		// don't do the hover thing if the element is selected
		if( $(element).hasClass('current_page_item') ){
			return true;
		}
		
		// The stop() stops any existing animations
		$(element).find("span").stop().fadeTo(250, 1.0);
	},
	subNavHoverOut: 	function(element)
	{
		// don't do the hover thing if the element is selected
		if( $(element).hasClass('current_page_item') ){
			return true;
		}
		
		// The stop() stops any existing animations
		$(element).find("span").stop().fadeTo(250, 0.6);
	},
	showViewerContent: 	function(element)
	{
		$("#content dl.viewer > dd.selected").each( function(){  var thisParentNode =  this.parentNode; $(thisParentNode).find('dt').click() ; } );
		
		thisParentNode	= $(element)[0].parentNode;
		
		$(thisParentNode).addClass('selected');
		thinkPlace.viewHoverIn(element);
		
		$(thisParentNode).find("dd").fadeIn(250).addClass('selected');
	},
	hideViewerContent: 	function(element)
	{
		thisParentNode	= $(element)[0].parentNode;
		
		$(thisParentNode).removeClass('selected');
		thinkPlace.viewHoverOut(element);
		
		$(thisParentNode).find("dd.selected").fadeOut(250).removeClass('selected');
	},
	
	initNav: 			function()
	{
		thinkPlace.bodyClass	= $('body')[0].className;

		$("#header .navigation > ul > li > a")
		.hover(
			function () {
				thinkPlace.navHoverIn(this);
			},
			function () {
				thinkPlace.navHoverOut(this);
			}
		);
	},
	viewHoverIn: 		function(element)
	{
		// don't do the hover thing if the element is selected
		if (thinkPlace.isParentSelected(element)){
			return true;
		}
		$(element).stop().fadeTo(250, 1.0);
	},
	viewHoverOut: 		function(element)
	{
		// don't do the hover thing if the element is selected
		if (thinkPlace.isParentSelected(element)){
			return true;
		}
		$(element).stop().fadeTo(250, 0.5);
	},
	initSubNav: 		function()
	{
		$("#header .navigation > ul > li li")
		.hover(
			function () {
				thinkPlace.subNavHoverIn(this);
			},
			function () {
				thinkPlace.subNavHoverOut(this);
			}
		);

	},
	initViewer: 		function()
	{
		$("#content dl.viewer > dt")
		.hover(
			function () {
				thinkPlace.viewHoverIn(this);
			},
			function () {
				thinkPlace.viewHoverOut(this);
			}
		)
		.toggle(
			function () {
				thinkPlace.showViewerContent(this);
			},
			function () {
				thinkPlace.hideViewerContent(this);
			}
		);
	},
	init: 				function()
	{
		thinkPlace.initNav();
		thinkPlace.initSubNav();
		thinkPlace.initViewer();
	}
}

$(document).ready(function(){
  thinkPlace.init();
});