// fonction to animate scroll to box from menu item
var scrollToBox = function(e) {
	var box_id = '#' + e.currentTarget.href.split('#')[1];
	var link = e.currentTarget.href.split('#')[0];
	
	e.preventDefault();
	
	if ( window.location.href.split('#')[0] == link) {	
		var left = 208 - $(box_id).position().left;
		if (box_id != '#box1'){
			left = left + 3;
		}
		
		$('#boxes').animate({left: left});
		boxresize(left);
	} else {
		window.location = link;
	}
}

// fonction resize 
var boxresize = function(boxes_left) {
  if (!boxes_left) {
	 boxes_left = $('#boxes').position().left;
  }
  
  var boxes_size = $('#boxend').position().left + $('#boxend').width() + 30;
  var content_size = boxes_size + boxes_left; // boxes_left is negative when boxes moves
  
  $('#content').animate({width: content_size});
}

//fonction to toggle "more" link in boxes
var toggleMoreInfo = function(e) {
	e.preventDefault();
	$(e.currentTarget).parent().next("div.cachee").toggle("slow", boxresize);
}
// init
$(document).ready(function() {
	// init slideshow					   	
    $('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	// hide more info boxe and enable more info link
    $("div.cachee").hide();
	$("a.suite").bind("click", toggleMoreInfo);
	
	// menu
	$("#switch a").bind("click", scrollToBox);
	$("#switch > li > ul").hide();
	$("#switch > li > ul").slideDown("slow");
	
	// resize content related to boxes size
	boxresize();
});

