$(document).ready(function() {

// $(".homeslide > img").hide();
// $(".homeslide > img").bind("load", function () { $(this).fadeIn(); });

// show first caption
$("#caption-1").delay(2000).fadeIn();

// count how many slides
var n = $(".homeslide").size();
var n = n - 1;

// run slider
var cfs = $("#homeslider").carouFredSel({
prev : {	
	button	: ".homeslider-prev"
},
next : { 
	button	: ".homeslider-next"
},
items: {
	minimum: 3,
	start: -1 // the first slide appears to the center
},
scroll: {
	items: 1,
	easing: "swing",
	duration: 1000,
	pauseOnHover: true,
	
	onBefore : function(oldItems) {
		oldItems.find("> div").fadeOut();
	},
	
	onAfter : function(newItems) { 
	var current = cfs.current_position();
	
	// even numbers
	if (current < n) {
		var realcurrent = current + 2;
	} else {
		var realcurrent = 1;	
	}
	// show caption
	$('#caption-' + realcurrent).delay(2000).fadeIn();
	}
},
auto: 10000
}).nap();

// center slider in window
var browser = $(window).width();
var slide = $('.homeslide').innerWidth();
var margin = ( ( browser - slide ) / 2 ) - slide;
$('#homeslider-container div.homeslider').css({'margin-left':  +margin+  'px'});


			
// center slider on window resize		
$(window).resize(function() {
	var browser = $(window).width();
	var slide = $('.homeslide').innerWidth();
	var margin = ( ( browser - slide ) / 2 ) - slide;
	$('#homeslider-container div.homeslider').css({'margin-left':  +margin+  'px'});
});


// sub content - caption

// hide captions on load
$('.sub-content-caption').hide();

$('.sub-content-box').hover(function() {         
	//Display the caption
	$(this).find('div.sub-content-caption').stop(false,true).fadeIn(200);
},
function() {
	//Hide the caption
	$(this).find('div.sub-content-caption').stop(false,true).fadeOut(200);
});

// make entire box clickable
$(".sub-content-box").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
});


});// end 
