$(function() {

	$('.testimonial-content').masonry({
	    // options
	    itemSelector : '.item',
	    columnWidth : 350,
		gutterWidth : 40
	  });

	// the product container needs a class for different view types
	$('.SI-partial-target').bind('viewchange', function(event, viewType, oldViewType) {
		$(this)
			.removeClass(oldViewType + '-view')
			.addClass(viewType + '-view');
	});
	
	$('.slideshow').cycle({ speed: 2500 });
	
	// close wishlist context dialogs when a product gets added
	$(document).delegate('.si-wishlist-add-form', 'addtowishlist', function() {
		$(this).parents('.ui-context-dialog').contextDialog('close');
	});

	function init(target) {
		// initialize all input with hints
		$('input:text', target).hint();
		
		// initialize generic toggles
		$('a.toggle', target).toggler({
			activeClass	: 'active',
			closeClass	: 'close'
		});
		
		// initialize context dialogs
		$('.context-dialog', target).contextDialog();
		
		// initialize sliders
		$('.callout-products', target).itemSlider();
		
		// initialize zebra striping on tables and lists
		$('table tr:even', target).addClass('stripe');
	}
	
	// make sure ui widgets get initialized when elements get added to the dom
	$(document).bind('render', function(event) {
		init(event.target);
	});
	
	// initialize ui widgets on the initial page load
	init(document);
	
	// initialize menu dropdowns (this takes a long time, so do it after the rest of the JS has initialized)
	//$('#main-nav > ul').dropDown({ arrows:true });
});

