$(function() {

	var windowHeight = $(window).height();
	
	if (windowHeight > 600) {
		$('body').addClass('noscroll');
	}
	
	$('body.home div.post').hover(function(){
		if ($(this).hasClass('active')) { } 
		else {	
			selectFeatured($(this));
		}
		window.clearInterval(slideFeaturedID);
			
	}, function() {
		startSliding(slideFeaturedID);
	}).click(function(){
		var link = $(this).find('a').attr('href');
		window.location = link;
	});
	
	
	function slideFeatured() {
		var posts = $('body.home div.post');
		var postActive = $('div.active');
		var postNext = postActive.nextAll('div.post').slice(0,1);		
		
		if (postNext.length == 0) {
			postNext = $('div.post:first');
		}
		
		selectFeatured(postNext);
		
		return false;
	}
	
	function selectFeatured(item) {
		var bgImage = item.prev();
		
		if(typeof bgImage != 'undefined'){
			bgImage.fadeIn();
			
			$('img.visible').css('display', 'none').removeClass('visible');
			
			bgImage.addClass('visible');
			
			$('div.post').removeClass('active');
			item.addClass('active');
		}
	}
	
	function startSliding() {
		slideFeaturedID = window.setInterval(slideFeatured, 9000);
	}
	
	if ($('body').hasClass('home')) {	
		startSliding();	
	}


});
