/*******************************************************************************

CSS on Sails Framework
Title: Chaco Research Archive
Author: XHTMLized (http://www.xhtmlized.com/)
Date: May 2010

*******************************************************************************/
(function($){


	$(document).ready(function() {
		$('.txt-resources').hover(
			function(){ $(this).addClass('txt-resources-hover'); },
			function(){ $(this).removeClass('txt-resources-hover'); }			
		);
		$('.featured a').hover(
			function(){ $(this).parents('.featured').addClass('featured-hover');},
			function(){ $(this).parents('.featured').removeClass('featured-hover');}
		);
		$('.txt-architectural a').hover(
			function(){ $('.featured-architectural').addClass('featured-hover');},
			function(){ $('.featured-architectural').removeClass('featured-hover');}
		);
		$('.txt-sites a').hover(
			function(){ $('.featured-sites').addClass('featured-hover');},
			function(){ $('.featured-sites').removeClass('featured-hover');}
		);
		$('.txt-query a').hover(
			function(){ $('.featured-query').addClass('featured-hover');},
			function(){ $('.featured-query').removeClass('featured-hover');}
		);
		$('.txt-gallery a').hover(
			function(){ $('.btn-enter-gallery').addClass('featured-hover');},
			function(){ $('.btn-enter-gallery').removeClass('featured-hover');}
		);
		$('.txt-explore a').hover(
			function(){ $('.btn-explore').addClass('featured-hover');},
			function(){ $('.btn-explore').removeClass('featured-hover');}
		);

		$('.btn-how-it-works,.btn-how-close').click(function(){
			var span = $('.btn-how-it-works').find('span');
			if(span.hasClass('active')){
				$('.map-how').fadeOut(function(){
					span.removeClass('active');
				});
			}else{
				$('.map-how').fadeIn(function(){
					span.addClass('active');
				});
			}
			return false;
		});
		// Cufon.replace('.whats-new .title, .featured h3, .sidebar h3');



		// Tooltips

		function tooltip(){	

			/* CONFIG */		

			var xOffset = 10;

			var yOffset = 10;		

			// these 2 variable determine popup's distance from the cursor

			// you might want to adjust to get the right result		

			/* END CONFIG */		



			var $areaTooltip = $('area.tooltip');
			
			$areaTooltip.each(function(){
				$this = $(this);
				var tooltipText =  this.title;
				$this.data('tooltip',tooltipText);
				$this.removeAttr('title');
			});
			
			$areaTooltip.mouseenter(function(e){											  
				
				e.preventDefault();
				$this = $(this);
				
				$("body").append("<p id='tooltip'>"+ $this.data('tooltip') +"</p>");

				$("#tooltip")
				.css('position','absolute')
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
				
				

			});
			
			$areaTooltip.mouseleave(function(){
				$("#tooltip").remove();
			});
			
			$areaTooltip.mousemove(function(e){

				$("#tooltip")

				.css("top",(e.pageY - xOffset) + "px")

				.css("left",(e.pageX + yOffset) + "px");
				
				e.preventDefault();

			});			

		};

		tooltip();
	});


	/* wide layout fix */
	if($('.page-id-44').length > 0){
		var curWidth = $('#wrapper').width();
		var width = 0;
		var contentWidth = 846;
		$('.content table').each(function(){
			var tableWidth = $(this).width();
			width = (tableWidth > width) ? tableWidth : width;
		});
		if(width > contentWidth){
			if(width + 159 < curWidth){
				var mainContent = $('.main-content').width();
				var diff = width - mainContent;
				$('.main-content').width(mainContent+diff);
				$('.container').each(function(){
					$(this).width($(this).width() + diff);
				});
			}else{
				$('#wrapper').addClass('layout-wide');
				$('.main-content').width(width);
				width = width + 159 + 20;
				$('.content').width(width);
				$('#wrapper,#content,#header').width(width + 20);
				$('#footer')
					.width(curWidth)
					.css({'padding-right': (width - curWidth + 20)+'px'});
			}
		}
	}

	}(jQuery));


