
$(document).ready(function(){

	mainNavigation();
	contentAdjustments();
	footerLogos();
	
	$('a[rel=external]').click(function(){window.open(this.href); return false;});
	
	// sidebar
	$('#sidebar ul li:last-child').addClass('no-bg');

});


// animate the hover background into view
function mainNavigation()
{
	
	Cufon.replace('#menu-main-navigation li a', {
		fontFamily: 'New Athena Unicode',
		fontSize: '14px',
		hover: {
			color: '#bc9b6a'
		}
	});
	
	$('#menu-main-navigation li').append('<span class="main-hover"></span>')
	
	$('#menu-main-navigation li').hover(
		function()
		{
			
			if ( $(this).hasClass('current-menu-item') || $(this).hasClass('current-page-parent') )
			{
				// do nothing
			}
			else
			{
				$(this).find('.main-hover').css({opacity: 0}).show().animate(
					{opacity: 1},
					{
						queue: false,
						duration: 150,
						easing: 'easeInSine'
					}
				);
			}
		},
		function()
		{
			if ( $(this).hasClass('current-menu-item') || $(this).hasClass('current-page-parent') )
			{
				// do nothing
			}
			else
			{
				$(this).find('.main-hover').animate(
					{opacity: 0},
					{
						queue: false,
						duration: 150,
						easing: 'easeInSine',
						complete: function()
						{
							$(this).find('.main-hover').hide();
						}
					}
				);
			}
		}
	);
}


/* content adjustments */
function contentAdjustments()
{
	Cufon.replace('.more-link', { fontFamily: 'New Athena Unicode', hover: { color: '#3399cc' } });
	Cufon.replace('.page-services #section-header h1, h2.page-title, #sidebar h3, .focus-text', { fontFamily: 'New Athena Unicode' });
	
	// if a content list does not have a class, add class="content-list"
	var content_lists = $('#content ul').length;
	if ( content_lists > 0 )
	{
		for ( i = 0; i < content_lists; i++ )
		{
			var this_list = $('#content ul:eq(' + i + ')');
			if ( $(this_list).hasClass('') )
			{
				$(this_list).addClass('content-list');
			}
		}
	}
	
	// add class="dotted-list" to callout box lists
	var content_callouts = $('.callout-box').length;
	var callout_paragraphs = $('.callout-box p').length;
	if ( content_callouts > 0 )
	{
		// check to see if there are any empty paragraphs taking up space in the callout box
		for ( p = 0; p < callout_paragraphs; p++  )
		{
			var check_text = $('.callout-box p:eq(' + p + ')').text();
			if ( check_text == '' ){ $('.callout-box p:eq(' + p + ')').hide(); }
		}
		// also check for the rogue break tag before the callout box header or first paragraph
		$('.callout-box h6').prev('br').hide();
		$('.callout-box p:first-child').prev('br').hide();
		$('.callout-box ul:first-child').prev('br').hide();
		$('.callout-box br:last-child').hide();
		
	}
	
	var callout_lists = $('.callout-box ul').length;
	if ( callout_lists > 0 )
	{
		for ( i = 0; i < content_callouts; i++ )
		{
			$('.callout-box ul:eq(' + i + ')').addClass('dotted-list');
		}
	}
		
	// remove the dots from the last dotted-list item
	var total_dotted_lists = $('ul.dotted-list li').length;
	if ( total_dotted_lists > 0 )
	{
		$('ul.dotted-list li').wrapInner('<div />');
		$('ul.dotted-list li:last-child').addClass('no-bg');
	}
	
	// remove bg from first question on faqs page
	var faqs_list = $('.question').length;
	if ( faqs_list > 0 )
	{
		$('.question:first').addClass('no-bg');
	}
	
	// remove margin on floated image parent <p>'s, but not when they are in a callout box
	$('img.alignleft', 'img.alignright').parent('p').addClass('no-margin');
		
	// callout box paragraphs with images inside them should get the margin
	$('.callout-box img.alignleft', '.callout-box img.alignright').parent('p').removeClass('no-margin');

}


/* photo gallery */
function photoSlideShow()
{
	// set opacity of each featured property element to zero
	$('#photos li').css({opacity: 0});
		
	// fade in the first property detail
	$('#photos li:eq(0)').show().animate({opacity: 1},{queue: false,duration: 1000,easing: 'easeInSine'});
	current_slide = 0;
	
	// seutp slideshow navigation
	sliderNavigation();
}


function sliderNavigation()
{
	
	// grab total number of slides
	TOTAL_SLIDES = $('#photos li').length - 1;

	$('#photos li').click(function(){
		if ( current_slide == TOTAL_SLIDES )
		{
			current_slide = 0;
			showSlide();
			return false;
		}
		else
		{
			current_slide++;
			showSlide();
			return false;
		}
	});
	
	// previous/next arrows
	$('#arrow-next').click(function(){
		if ( current_slide == TOTAL_SLIDES )
		{
			current_slide = 0;
			showSlide();
			return false;
		}
		else
		{
			current_slide++;
			showSlide();
			return false;
		}		
	});
	
	$('#arrow-previous').click(function(){
		if ( current_slide == 0 )
		{
			current_slide = TOTAL_SLIDES;
			showSlide();
			return false;
		}
		else
		{
			current_slide--;
			showSlide();
			return false;
		}
	});
}


function showSlide()
{
	$('#photos li').hide().css({opacity: 0});
	$('#photos li:eq(' + current_slide + ')').show().animate({opacity: 1},{queue: false,duration: 500,easing: 'easeInSine'});
}


/* home page */
function homePageAdjustments()
{
	
	Cufon.replace('#content-area h1, #content-area h2, #content-area h3', { fontFamily: 'New Athena Unicode' });
	adjustHomePageFocusLists();
	equalizeHpColumns();
	
}

function adjustHomePageFocusLists()
{
	$('#hp-three-col-focus li').find('ul').addClass('dotted-arrow-list');
	$('#hp-three-col-focus li ul.dotted-arrow-list li:last-child').addClass('no-bg');
}


function equalizeHpColumns()
{
	
	item_height = $('.equalize').height();
	
	$('.equalize').each(
		function(){
			item_height = Math.max( item_height, $(this).height() );
		}
	).height(item_height);
	
	// equalize main content column and weather widget column
	var hpww_height = 300;
	var hp_content_height = $('#hp-content').height();
	var tallest_column = Math.max(hpww_height, hp_content_height);
	$('#hp-content').height(tallest_column);
	$('#hp-weather-widget').height(tallest_column);
	
}


function footerLogos()
{
	$('.footer-logos li a').css({opacity: .5});
	$('.footer-logos li a').hover(
		function(){
			$(this).animate(
				{ opacity: 1 },
				{
					queue: false,
					duration: 150,
					easing: 'easeInSine'
				}
			);		
		},
		function(){
			$(this).animate(
				{ opacity: .5 },
				{
					queue: false,
					duration: 150,
					easing: 'easeInSine'
				}
			);		
		}
	);
}
