$(document).ready(function() {
        
        if(typeof slideshow_handler == 'object') {
            slideshow_handler.setup();
        }   
});


var slideshow_handler = {
    container: null,
    total_items: 4,
    last_item: null,
    delay: 6000,
    
    setup: function()  {
	setTimeout(function(){ slideshow_handler.changePic(); }, slideshow_handler.delay);
	last_item = 0;
    },
    
    changePic: function() {
	var last_pic = $('#home-slideshow .active');
	var next_index = this.last_item + 1;
	if(next_index == this.total_items) {
	    next_index = 0;
	}
	
	var last_pic = $('#home-slideshow .active');
	$(last_pic).animate({
	    opacity: 0
	  }, 1000, function() {
	    // Animation complete.
	});
	setTimeout(function(){$(last_pic).removeClass('active')}, slideshow_handler.delay);

	var next_pic = $('#home-slideshow li')[next_index];
	$(next_pic).css({'opacity':'0'});
	$(next_pic).addClass('active');
	$(next_pic).animate({
	    opacity: 1
	  }, 1000, function() {
	    // Animation complete.
	});
	
	this.last_item = next_index;
	setTimeout(function(){ slideshow_handler.changePic(); }, slideshow_handler.delay);
    }
}
