function init(){
	if($(".scroller").length){
		initScroller();
	}
	if($('.collection').length){
		initAccordion();
	}
	
	$(window).scroll(recalcNav);
	$(window).resize(recalcNav);
}
function initAccordion(){
	$(".collection:not(.selection)").accordion({
		autoHeight:false,
		active:false,
		collapsible:true,
		event:'click',
		header:'.separator'
	});
	setTimeout("$('.collection:not(.selection)').accordion('activate',0)",1500);
}
function initScroller(){
	$('.collection:not(.selection)').addClass('scrollable');
	$('.set_show').addClass('scrollable');
	$(".scrollable .scroller").scrollable({
		loop: true,  
		size: 1,
		items: '.sets',
		hoverClass: 'hover',
		navi:".nav",
		activeClass:'active',
		onBeforeSeek: function(){
			//this.getItems().fadeTo(300, 0.2);         
		}, 
		onSeek: function() { 
			//this.getItems().fadeTo(300, 1); 
		}
	});
}
function recalcNav(){
	var decalage = 30;
	var ot = $(window).scrollTop();
	var off = Math.max(ot-decalage,0);
	$("#nav").css('top',Math.max(0,off-32))
	$("#details").css('top',off)
}
function toggleDetails(e){
	var pt = $(this).next('.details');
	pt.slideToggle(100);
	return false;
}
var sets_per_line = 0
var margin=0;

function recalcGrid(){
	var scw = $(".grid").width();
	var itw = $('.grid .set').innerWidth();
	sets_per_line = Math.floor(scw/itw);
	var total_margin = (scw%itw);
	var margin = Math.floor(total_margin/(sets_per_line-1));
	$(".grid .set").each(function(i){
		if ((i+1)%(sets_per_line)==0){
			$(this).css('margin-right',0);
		} else {
			$(this).css('margin-right',margin);
		}
	});
}

$(document).ready(init);
Cufon.replace('h2',{ 'fontFamily': 'ITC Avant Garde Gothic Std Extra Light' });
Cufon.replace('h3',{ 'hover':true, 'fontFamily': 'ITC Avant Garde Gothic Std Extra Light' });
Cufon.replace('h4',{ 'color': '-linear-gradient(#000, 0.5:#333, #999)', 'hover':true, 'fontFamily': 'ITC Avant Garde Gothic Std Bold' });
Cufon.replace('h5',{ 'color': '-linear-gradient(#000, 0.5:#333, #999)', 'hover':true, 'fontFamily': 'ITC Avant Garde Gothic Std Bold' });
Cufon.replace('h6',{ 'hover':true, 'fontFamily': 'ITC Avant Garde Gothic Std Extra Light' });
//Cufon.replace('#navigation li',{ 'hover':true, 'fontFamily': 'ITC Avant Garde Gothic Std Bold' });
