function init() {
	document.body.className += " loading hasJS";
}

$(function() {
	Sitemap.init();
	Background.init();
	Heading.init();
	Newsletter.init();
	Cufon.replace('h1, .h1, h2, .h2, h3, .h3, #Heading p', { fontFamily: 'Soho Pro' });
	Setup.init();
});

var Setup = {	
	Body: null,
	init: function() {
		var cc = this;
		cc.Body = $(document.body);
		cc.Body.addClass('domReady');
		EqualHeight.init();
		if(cc.Body.hasClass('fresh-green')==false) {
			cc.Body.removeClass('loading');
		}	
	}	
};

var Newsletter = {
	SubscribeForm: null,
	ContactAddress0: null,
	ContactAddress1: null,
	init: function() {
		var cc = this;	
		cc.SubscribeForm = $('#NewsletterAddForm');
		
		cc.events();
		cc.validation();
		cc.render();
	},
	events: function() {
		var cc = this;	
	},	
	render: function(url) {
		var cc = this;
	
	},
	validation: function() {
		$('#NewsletterAddForm').validate();
	}
}

var Sitemap = { 
	Content: null,
	Trigger: null,	
	init: function() {
		var cc = this;
		cc.Content = $('#Sitemap div.content');
		cc.Trigger = $('#ToggleSiteMap');
		cc.events();
	},
	events: function() {
		var cc = this;
		cc.Trigger.click(function(){
			cc.Content.slideToggle();
			return false;
		});
	}
};

var EqualHeight = { 
	Rows: null,
	init: function() {
		var cc = this;
		cc.Rows = $('div.eqH');
		cc.render();
	},
	render: function() {
		var cc = this;
		cc.Rows.each(function() {
			var cols = $(this).find('div.wpr');
			cols.css('height','auto');
			var tallest = 0; 
			cols.each(function() {
				colHeight = $(this).height();
				if(colHeight > tallest) {
					tallest = colHeight;
				}
			});
			$(cols).height(tallest); 
		});
	}
};

var Background = { 
	Body: null,
	Container: null,
	Show: null,
	Hide: null,
	init: function() {
		var cc = this;
		cc.Body = $(document.body);
		cc.Container = $('#Container');
		cc.Show = $('#ShowBackground');
		cc.Hide = $('#HideBackground');
		cc.events();
		cc.render();
	},
	events: function() {
		var cc = this;
		cc.Hide.click(function(){
			cc.Body.removeClass('background');
			cc.Show.removeClass('selected');
			cc.Hide.addClass('selected');
			$.ajax({
				type: "GET",
				url: "/preferences/background/false"
			});
		});
		cc.Show.click(function(){
			
			cc.Body.addClass('background');
			cc.Show.addClass('selected');
			cc.Hide.removeClass('selected');
			$.ajax({
				type: "GET",
				url: "/preferences/background/true"
			});
		});
	},	
	render: function() {
		var cc = this;	
		if(cc.Body.hasClass('background')) {
			cc.Show.addClass('selected');
		}
		else {
			cc.Hide.addClass('selected');
		}
	}	
};

var Heading = {
	Content: null,
	Trigger: null,
	init: function() {
		var cc = this;
		cc.Content = $('#Heading div.content');
		cc.Trigger = $('#Heading a.toggle');
		cc.events();
		cc.render();
	},
	events: function() {
		var cc = this;
		cc.Trigger.click(function() {	
			
			if(cc.Trigger.hasClass('disabled')) {
				Cufon.refresh();
				cc.Content.slideDown();
				cc.Trigger.removeClass('disabled');
				$.ajax({
					type: "GET",
					url: "/preferences/heading/true"
				});	
			} else {
				cc.Content.slideUp();
				cc.Trigger.addClass('disabled');
				$.ajax({
					type: "GET",
					url: "/preferences/heading/false"
				});	
			}
			return false;
		});
	},
	render: function() {
		var cc = this;
		if(cc.Content.css("display")=='none') {
			cc.Trigger.addClass('disabled');
		}
	}
}