Bryantpark.hompage = new (function()
{
	var self = this;
	var maxHeight = 400;
	var iniCount = 0;
	
	var calculateHeight = function(who, specficHeight)
	{
		if(!who) return false;
		
		var entries = $(who +' .mod-entry');
		var totalEntryHeight = 0;
		var minHeight = (specficHeight) ? specficHeight : 100; 
		var overflow = (specficHeight > 295) ? 'auto' : 'hidden';
		
		$(who+' h2').removeClass('expanded');
		$(who+' h2').removeClass('collapsed');
		
		if(overflow == 'hidden')
		{
			$(who+' h2').addClass('collapsed');
		}
		else
		{
			$(who+' h2').addClass('expanded');
		}
		
		for(var i = 0, l = entries.length; i < l; i++)
		{
			totalEntryHeight += $(entries[i]).height();
			totalEntryHeight = (totalEntryHeight > minHeight) ? totalEntryHeight - $(entries[i]).height() : totalEntryHeight;
		}
		$(who + ' .module-container').animate( { 'height':totalEntryHeight } , 300, setOverflow );
		
		function setOverflow()
		{
			$(who +' .module-container').css({'overflow-y':overflow});

			// show modules after initial load in.
			iniCount++
			if(iniCount >= 3)
			{
				showSections();
			}
		}
		
		
		return false;
	}
	
	var hideSections = function()
	{
		$('#today_in_the_park').css({'visibility':'hidden'})
		$('#highlights').css({'visibility':'hidden'})
		$('#blog').css({'visibility':'hidden'})
	}
	var showSections = function()
	{
		$('#today_in_the_park').css({'visibility':'visible'})
		$('#highlights').css({'visibility':'visible'})
		$('#blog').css({'visibility':'visible'})
	}
	
	self.init = function()
	{	
		hideSections();
		calculateHeight('#today_in_the_park', 300)
		$('#today_in_the_park').mouseenter(
			function()
			{
				calculateHeight('#today_in_the_park', 300);
				calculateHeight('#highlights');
				calculateHeight('#blog');
			});
			
		calculateHeight('#highlights');
		$('#highlights').mouseenter(
			function()
			{
				calculateHeight('#highlights', 300)
				calculateHeight('#today_in_the_park');
				calculateHeight('#blog');
			});
			
		calculateHeight('#blog');
		$('#blog').mouseenter(
			function()
			{
				calculateHeight('#blog', 300);
				calculateHeight('#today_in_the_park');
				calculateHeight('#highlights');
			});
	}
	
});

Bryantpark.randomImage = new(function()
{
	var self = this;
	
/*	var imageSet = ['building_view.jpg',
	'carousel.jpg',
	'carousel2.jpg',
	'chair.jpg',
	'chair2.jpg',
	'chairs.jpg',
	'flower.jpg',
	'fountain.jpg',
	'night.jpg',
	'summer_aerial_view.jpg',
	'tables.jpg',
	'tent.jpg'];
*/	
	var imageSet = ['fountain-shops1.jpg',
	'nightpond1.jpg',
	'pond1.jpg',
	'pond2.jpg',
	'pond3.jpg',
	'roberta_klein_bryant_park.jpg',
	'shops1.jpg',
	'snowchairs.jpg',
	'snowday1.jpg',
	'snowday2.jpg'];

	var rndChoice = Math.floor(Math.random() * imageSet.length);
	
	self.init = function()
	{
//		$('body').css({'background-image':'url(/static/images/homepage_backgrounds/'+imageSet[rndChoice]+')'});
		$('body').css({'background-image':'url(/static/images/homepage_backgrounds_winter/'+imageSet[rndChoice]+')'});
	}
});

// Executes when DOM is ready to be manipulated.
$(document).ready( function() { Bryantpark.randomImage.init(); Bryantpark.hompage.init(); });
