/**
 * @author Jon
 */

var HomePage = function () {
	var config = {
		IDs: {
			newsTabs: '#news',
			informationTabs: '#information',
			photoVideoArea: '#photo-video-extras',
			otherExtras: '#other-extras',
			searchBox: '#search-box',
			newsLetterLink: '#newsletter-link'
		},
		selectors: {
			notices: '.notice'
		},
		values: {
			searchText: 'Search AA',
			noticeTimeout: 3000
		}
	};
	var controls = {};
	
	function evenFeatures () {
		var leadFeature = $('#lead-features');
		var secondaryFeatures = $('#secondary-features');
		
		if (secondaryFeatures.height() > leadFeature.height()) {
			leadFeature.height(secondaryFeatures.height() - 12);
		} else if (secondaryFeatures.height() < leadFeature.height()) {
			var children = secondaryFeatures.find('ul').children('.panel');
			
			var margins = 5 * (children.length - 1);
			var newHeight = ((leadFeature.height() - (margins)) / children.length);
			var total = (children.length * newHeight) + margins + (children.length) + 1;
						
			children.height(newHeight);
			leadFeature.height(total);
		}
	}
	
	function evenAreas(selectorOne, selectorTwo) {
		var heightOne = $(selectorOne).height();
		var heightTwo = $(selectorTwo).height();
		var paddingOne = parseInt($(selectorOne).css('paddingBottom'));
		var paddingTwo = parseInt($(selectorTwo).css('paddingBottom'));
		
		if ((heightOne + paddingOne) > (heightTwo + paddingTwo)) {
			$(selectorTwo).height(heightOne + paddingOne - paddingTwo);
		} else {
			$(selectorOne).height(heightTwo + paddingTwo - paddingOne);
		}
	}
	
	return {
		init: function () {
			controls.newsTabs = $(config.IDs.newsTabs).tabs();
			
			/*controls.photoVideoAccordian = $(config.IDs.photoVideoArea).accordion({
				event: 'mouseover',
				autoHeight: false
			});
			controls.otherExtraTabs = $(config.IDs.otherExtras).tabs();*/
			$(config.IDs.searchBox).focus(function () {
				var $this = $(this)
				if ( $this.attr('value') == config.values.searchText ) {
					$this.attr('value', '')
				}
			});
			$(config.IDs.searchBox).blur(function () {
				var $this = $(this)
				if ( $this.attr('value') == '' ) {
					$this.attr('value', config.values.searchText)
				}
			});
			
			//evenFeatures();
			$(config.IDs.newsLetterLink).bind('click', function(e) {
				$('#newsletter-panel').effect('highlight', {duration: 'slow'});
			});
			
			if(window.location.hash == '#newsletter') {
				$('#newsletter-panel').effect('highlight', {speed: 'slow'});
			}
			
			setTimeout(function(){ $(config.selectors.notices).slideUp() }, config.values.noticeTimeout);
		},
		evenAreas: evenAreas
	};
}();

$(document).ready(HomePage.init);
