//Time in Millisecond for jQuery Fade Effects
var jquery_FadeSpeed = 0;

$(document).ready(function() 
{
	mouseIsOver_overlayWidget = false;
	
	//Execute CUFON html -> canvas.
	Cufon.replace(['.helv_thin',  '.contentCopy h1'], {fontFamily: 'Helvetica_thin_bold', hover: true});
	Cufon.replace(['.helv_light', '.contentCopy h2'], {fontFamily: 'Helvetica_light_bold', hover: true});
	Cufon.replace(['.helv_light', '.contentCopy h3'], {fontFamily: 'Helvetica_light_bold', hover: true});


	/* ==================================================== */
	/* HOMEAPGE PAGE ONLOAD FUNCTIONS 						*/
	/* ==================================================== */

	if ($('.layout-homepage').length > 0)
	{
		//Resize all Banner Images using imgScale plugin.
		$('img.bannerImage').imgscale({ parent : '.imageResize', fade : 0 }); 
		
		//*** EVENTS ****
		$('.contentContainer').bind("mouseover", function() 
		{
			$('#bannerCarousel').cycle('pause'); 
			$(this).addClass("active"); 
			$('.primaryNavigationContainer #overlayWidget').html($(this).find('.widgetContent').html());		
			$('.footerInfo').fadeOut(jquery_FadeSpeed);
	
			$(this).find('.graphic').fadeOut(jquery_FadeSpeed, function() 
			{												
				//Callback function.
				$('.primaryNavigationContainer #overlayWidget').fadeIn(jquery_FadeSpeed);
			});
			
		});
	
		$('.bannerImage').bind("mouseover", function() { contentContainer_mouseoff(); });
			
		$('.primaryNavigation').bind("mouseover", function() 
		{		
			if (mouseIsOver_overlayWidget == false)
			{
				contentContainer_mouseoff();
			}
		});
		
		//Boolean 'mouse enter' event to check if we are over the 'overlayWidget' */
		$('#overlayWidget').mouseenter(function(){ mouseIsOver_overlayWidget = true; }).mouseleave(function(){ mouseIsOver_overlayWidget = false; });

	}



	/* ==================================================== */
	/* INTERNAL PAGE ONLOAD FUNCTIONS 						*/
	/* ==================================================== */
	
	if ($('.layout-internal').length > 0)
	{
		//Resize all Banner Images using imgScale plugin.
		//$('img.bannerImage').imgscale({ parent : '.imageResize', fade : 0 }); 
	}



	/* ==================================================== */
	/* GLOBAL ONLOAD FUNCTIONS 						*/
	/* ==================================================== */

	/* This event loops through each .registerToday div, and checks for a link.
	If no link is within the div, it displays the 'sold out' button automatically. */
	$('.registerToday').each(function() 
	{
		if ($(this).find('a').length == 0)
		{
			//No link show the 'sold out' background.	
			$(this).addClass('soldOut');
		}
	});
	
	$('.contentTitleWrapper').each(function()
	{
		if ($(this).find('p').length == 1)
		{
			//If 1 'Br' than we have 2 lines, and apply 'lines-2' class.
			$(this).addClass('lines-2');
		}
		else if ($(this).find('p').length == 2)
		{
			//If 2 'Br' than we have 2 lines, and apply 'lines-3' class.						
			$(this).addClass('lines-3');
		}
	});
		
	$('.sliderTab').click(function() 
	{
		$('.propertiesContent').slideToggle('slow', function() 
		{
			// Animation complete.
		});
	
	});
		


	/* ==================================================== */
	/* INTERNAL FOOTER LI / FIRST ITEM CLASS ADDITION 		*/
	/* ==================================================== */

	if ($('.footerContent .sitemap ul li').length > 0)
	{
		$('.footerContent .sitemap ul li:first').addClass('first');
	}

	if ($('.footerContent .copyright-right ul li').length > 0)
	{
		$('.footerContent .copyright-right ul li:first').addClass('first');
	}

	initializeWindow();
		
});




function initializeWindow()
{
	
	$('.carouselWrapper #bannerCarousel li').height($(window).height());
	$('.carouselWrapper #bannerCarousel li').width( $(window).width());
	
	$('.loadingGif').fadeOut(500, function() { $(".overlay").fadeOut(1000); });
	
	$('#bannerCarousel').cycle({ 
		fx:     'fade', 
		speed:  '1000',
		timeout: 8000, 
		next:   '#next2', 
		prev:   '#prev2',
		pager: '.carouselPagination'
	});	
}


/* Function executes on homepage when user goes off of the carousel banner */
function contentContainer_mouseoff()
{
	$('.primaryNavigationContainer #overlayWidget').fadeOut(jquery_FadeSpeed, function() 
	{												
		//Callback function.
		$('.contentContainer .graphic').fadeIn(jquery_FadeSpeed);
		$('.footerInfo').fadeIn(jquery_FadeSpeed);
	});
	
	$('.primaryNavigationContainer #overlayWidget').html("");
		
	$('.contentContainer').removeClass("active"); 

	$('#bannerCarousel').cycle('resume'); 
}


