Chelsea.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 >= 1)
			{
				showSections();
			}
		}
		
		
		return false;
	}
	
	var hideSections = function()
	{
		$('#today_in_the_park').css({'visibility':'hidden'})
		$('#highlights').css({'visibility':'hidden'})
	}
	var showSections = function()
	{
		$('#today_in_the_park').css({'visibility':'visible'})
		$('#highlights').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('#highlights', 150);
		$('#highlights').mouseenter(
			function()
			{
				calculateHeight('#highlights', 400)
				calculateHeight('#today_in_the_park');
			});
	}
	
});

Chelsea.randomImage = new(function()
{
	var self = this;
	
	var imageSet = ['ChelseaPlaza-4.jpg',
	'CIC_streetview1.jpg',
	'CIC_tree1.jpg',
	'CIC_tree2.jpg',
	'CICo_bench_proto_07.jpg',
	'CIC-useofplaza1.jpg',
	'DSC_0319.jpg',
	'TreeGuards003.jpg'];
	
	var rndChoice = Math.floor(Math.random() * imageSet.length);
	
	self.init = function()
	{
		$('body').css({'background-image':'url(/static/images/homepage_backgrounds/'+imageSet[rndChoice]+')'});
	}
});

// Executes when DOM is ready to be manipulated.
$(document).ready( function() { Chelsea.randomImage.init(); Chelsea.hompage.init(); });
