$(document).ready(function () {
	jQuery('ul.sf-menu').superfish();
	$('div#sub-content ul.nav').accordion({
		change: function(event, ui) {
			Cufon.replace('#sub-content .nav a');
		}
	});
	$("body.products-group .group div.slider").slider({
	    animate: true,
	    change: handleSliderChange,
	    slide: handleSliderSlide
	  });	
	Cufon.replace('h1, #main-content h2, #home-feature h3, #sub-content .nav li a');
	$('ul.nav li a.register').click(function(e){
		window.open($(this).attr('href'),'registration','width=940, height=603');
		return false;
	});
	$('body.recipes ul.nav.buttons li#printer a').click(function(e){
		window.open($(this).attr('href'),'registration','width=647, height=500, scrollbars=yes, resizable=yes');
		return false;
	});
	$("div.scrollable").scrollable({
		clickable: false
		});
	$("body.products-group div#content div.item-list div.innerWrapper ul li div.tooltip").tooltip({
		offset: [20, 4],
		effect: 'toggle'
	});
});

function handleSliderChange(e, ui) {
  var maxScroll = $(e.target).parent().find('div.innerWrapper').attr("scrollWidth") - $(e.target).parent().find('div.innerWrapper').width();
  $(e.target).parent().animate({scrollLeft: ui.value * (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui) {
  var maxScroll = $(e.target).parent().find('div.innerWrapper').attr("scrollWidth") - $(e.target).parent().find('div.innerWrapper').width();
  $(e.target).parent().find('div.innerWrapper').attr({scrollLeft: ui.value * (maxScroll / 100) });
}

