(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length) ? $(this).html($.shuffle(items)) : this;
    });
  }
 
  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);


jQuery(document).ready(function() {
	
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	Shadowbox.init();
	
	$(".more-panel").hide();
	$(".information").hide();
	$(".more").click(function() {
		var div = $(this).parent().parent().parent();
		$(div).find(".more-panel").show();
	});
	
	$(".less").click(function() {
		$(this).parent().hide();
	});
    	
	$("#panel").hide();
	$(".slide").click(function() {
		$(this).next("#panel").slideToggle(600);
	});
	
	$('#sp_refs_carousel').shuffle();
	
	$('#sp_refs_carousel').jcarousel({
		auto:		3,
		buttonPrevHTML:	null,
		buttonNextHTML:	null,
		start: 		1,
		scroll:		1,
		easing: 	"swing",
		wrap: 		"both",
        itemFirstInCallback: {
		  onBeforeAnimation: cb_Before,
		  onAfterAnimation: cb_After
		},
		initCallback: InitCarousel
    });

});

function cb_Before(carousel, li, index, state) {	
	//alert("cb_Before");
}

function cb_After(carousel, li, index, state) {	
	//alert("cb_After");
}

function InitCarousel (carousel, state) {
	//alert("InitCarousel");
	carousel.startAuto();
}
