$(function() {      
	Home.init();	
	Text.init();
});

var Home = {

	/* jQuery Object References */
	jOEPreloader: null,
	jOESpinner: null,
	jOEMainWrapper: null,
	
	init : function() {
		var cc = this;
		// store references
		cc.jOEPreloader = $('#Preloader');
		cc.jOEMainWrapper = $('#MainWrapper');
		cc.jOESpinner = $('#Spinner');

		$(window).load(function(){
			cc.jOESpinner.show();
			cc.splash();
		})		
	},
	splash : function() {
		var cc = this;
		window.clearTimeout();
		$.ajax({
			url: '/homepages/splash',
			cache: false,
			success: function(html) {
				cc.jOESpinner.hide();
				cc.jOEPreloader.html(html);
	
				var mainImage = cc.jOEPreloader.find('img.main-image');
				mainImage.load(function(){
					cc.jOEMainWrapper.html(cc.jOEPreloader.html());
					var image = cc.jOEMainWrapper.find('img.main-image');
					var details = cc.jOEMainWrapper.find('div.details');
					Cufon.replace('#Main .details h2', { fontFamily: 'Helvetica Neue Light' });	
					Cufon.replace('#Main .details div.description p, #Main .details div.button a', { fontFamily: 'Helvetica Neue' });
					image.fadeIn(1000, function() {
						details.animate( { marginLeft: '30'}, { "duration": "slow", "easing": "easeInOutQuart" });
					})
					window.setTimeout(function() {
						cc.splash();
					}, 4000);
				});		
			}
		});	
	}
};


var Text = { 
	
	jOEMoreLink: null,
	jOEMore: null,
	
	init : function() {
		var cc = this;
		
		cc.jOEMoreLink = $('#TextMoreToggle');
		cc.jOEMore = $('#TextMore');
		cc.render();
		cc.events();
		
	},
	render : function() {
		var cc = this;
		cc.jOEMore.hide();
		Cufon.replace('#Text p', { fontFamily: 'Helvetica Neue' });	
	},
	events : function() {
		var cc = this;
		cc.jOEMoreLink.bind('click', function() {
			cc.jOEMore.show();
			cc.jOEMoreLink.hide();
			return false;
		})
	}	
};