 function resizeFooter() {
 	//var windowWidth = $(window).width();
	//var footerWidth = windowWidth - 40 - 130 - 100;
	//$('footer.home').css('width', footerWidth);
 }
 
function resizeHomeContent() {
	var windowWidth = $(window).width();
	var contentWidth = windowWidth - 40 - 100; //WindowWidth minus 40 padding-left and 100px for the outpanel
	var numCols = Math.floor(contentWidth / 150); //Work out the number of colums that can fit into the windowWith
	var hrWidth = numCols * 150 - 10; //Each column is 160px w a 20px margin-right. For the end column take off the margin amount.
	var footerWidth = hrWidth - 130; //Foot is the same as hrWidth - width of the affiliate box.
	$('#content.home').css('width', contentWidth);
	$('#content-hr').css('width', hrWidth);
	$('footer.home').css('width', footerWidth);
}

function resizeOutpanel() {
	var htmlHeight = $(window).height();
 	$('#outpanel').css('height', htmlHeight);
}

function setNewsExcerpts() {
	$('.news').each(function(index) {
		var excerptHeight = $('.excerpt', this).height();
		if( excerptHeight > 73 ) {
			$(this).addClass('extended');
		} 
		$('.excerpt p', this).css('display', 'none');
		$('.excerpt p:first', this).append('...');
	});
}

function newsOver() {
	var excerpt = $('.excerpt p', this);
	$('.headline', this).hide('fast', function(){
		excerpt.show('fast');
	});
	$(this).animate({ backgroundColor: "#edf4e9" }, 300);
}

function newsOut() {
	var headline = $('.headline', this);
	$('.excerpt p', this).hide('fast', function() {
		headline.show('fast');
	});
	$(this).animate({ backgroundColor: "#bee0a9" }, 300);
}

function aboutOver() {
	$('h2', this).animate({
		marginTop: '10px',
		height: '228px'	
	}, 500);
	$('#about div').delay('500').fadeTo('fast', 1);
}

function aboutOut() {
	$('div', this).fadeTo('fast', 0);
	$('#about h2').delay('200').animate({
		marginTop: '146px',
		height: '30px'	
	}, 500);
}

function contactOver() {
	$('h2', this).animate({
		marginTop: '10px',
		height: '228px'	
	}, 500);
	$('#contact div').delay('500').fadeTo('fast', 1);
}

function contactOut() {
	$('div', this).fadeTo('fast', 0);
	$('#contact h2').delay('200').animate({
		marginTop: '146px',
		height: '30px'	
	}, 500);
}

 
$(document).ready(function() {
 	
 	//Initialize the site
 	resizeFooter();
 	resizeHomeContent();
 	resizeOutpanel();
 	setNewsExcerpts();

 	//Isotope 
 	$('#content.home').isotope({
  		masonry: {
    		columnWidth: 150
  		}
  	});
 	$('#sort-by-item a, #sort-by-type a').click(function(){
 		$('#sort-by-item a, #sort-by-type a').removeClass('selected');
 		$(this).addClass('selected');
  		var selector = $(this).attr('data-filter');
  		$('#content.home').isotope({ filter: selector, animationEngine: 'best-available' });
  		return false;
	});
	
	//Hide the links on the Client Archives
	$(".client p.details a").attr("href", "")
 	
 	//Post Item hover states
 	$(".item").hover(
	  function () {
	  	 $('img', this).fadeTo('fast', 0.5);
	  	 $('.info', this).fadeTo('fast', 1);
	  },
	  function () {
	  	 $('img', this).fadeTo('fast', 1);
	  	 $('.info', this).fadeTo('fast', 0);
	  }
	);

 	//News hover states
 	$(".news").hoverIntent( newsOver, newsOut );

 	//Outpanel hover states
	/*$("#outpanel").hover(function() {
		$(this).animate({ width: "100px" }, 300);
	},function() {
		$(this).animate({ width: "30px" }, 300);
	});*/
	$(".lng-productions").hover(function() {
		$(this).css('color', '#fff');
		$(this).css('background-position', '0 -13px');
		$('#outpanel').css('background-color', '#7aa7b5');
		Cufon.refresh();
	},function() {
		$(this).css('color', '#7aa7b5');
		$(this).css('background-position', '0 0');
		$('#outpanel').css('background-color', '#E6EDE2');
		Cufon.refresh();
	});
	$(".lng-comingsoon").hover(function() {
		$(this).css('color', '#fff');
		$(this).css('background-position', '0 -13px');
		$('#outpanel').css('background-color', '#d17385');
		Cufon.refresh();
	},function() {
		$(this).css('color', '#d17385');
		$(this).css('background-position', '0 0');
		$('#outpanel').css('background-color', '#E6EDE2');
		Cufon.refresh();
	});
	
 	//Header About Us and Contact hover states
 	$("#about").hoverIntent( aboutOver, aboutOut );
 	$("#contact").hoverIntent( contactOver, contactOut );
	
	if ( $.browser.version <= 8 ) {
  		//alert( $.browser.version );
	} else {
		//Make the footer list look nice
		$(function(){
			var $bigList = $('footer ul'), group;
			while((group = $bigList.find('li:lt(10)').remove()).length){
				$('<ul/>').append(group).appendTo('footer');
			}
		});
	 	$('footer ul:eq(0)').addClass('hidden');
	}
		
	//Resize the footer when the browser changes
	$(window).resize(function() {
  		resizeFooter();
  		resizeHomeContent();
  		resizeOutpanel();
	});
 });
