(function($){
	/**
	 * Resize left sidebar on lowres screens
	 */
	$.ebbaContainer = {
		containerWidth: 0,
		leftWidth: 0,
		init: function(containerWidth, leftWidth) {
			this.containerWidth = parseInt(containerWidth);
			this.leftWidth = parseInt(leftWidth);
			$(window).bind('resize', function(){ $.ebbaContainer.resize() });
			this.resize();
		},
		resize: function() {
			var diff = $(window).width() - this.containerWidth;
			if (diff < 0) {
				diff = Math.max(diff, -127);
				$('#container').css('width', (this.containerWidth + diff) + 'px');
				$('#container #left').css('width', (this.leftWidth + diff)+'px');
				$('#container #right').css('width', parseInt($('#container').width()) - parseInt($('#container #left').width()) - 18);
			} else {
				$('#container').css('width', this.containerWidth);
				$('#container #left').css('width', this.leftWidth);
				$('#container #right').css('width', parseInt($('#container').width()) - parseInt($('#container #left').width()) - 18);
			}
			if ($(window).height() < 700) {
				$('body').addClass('fix-height');
			} else {
				$('body').removeClass('fix-height');
			}
			if ($(window).width() > 1280) {
				$('#footer').css('width', '1280px');
			} else {
				$('#footer').css('width', '100%');
			}
			/* Resize left container height to right container or window height */
			var maxHeight = Math.max($('#container #right').height(), $(window).height() - $('#footer').height());
			if (maxHeight > $('#container #left').height()) {
				$('#container #left').css('height', maxHeight);
			}
		}
	};
	/**
	 * Add hover classes
	 */
	$.fn.hoverClass = function() {
		$(this).bind('mouseenter', function(evt) {
			$(this).addClass('hover');
		}).bind('mouseleave', function(evt) {
			$(this).removeClass('hover');
		});
	}
	$(document).ready(function() {
		if ($('object#flashContent').length == 0) {
			Cufon.replace('h1,h2,h3,a.officialWebsite,.news-single-item h4');
			/* Open links in new window */
			$('a[href^="http://"]').attr('rel', 'external');
			$('a[rel="external"]').attr('target', '_blank');
		}
		
		/* Resize container */
		$.ebbaContainer.init($('#container').css('width'), $('#container #left').css('width'));
		$('.winners a.winner, .button,.submitButton').hoverClass();
	});
})(jQuery);