$(function() {

	Cufon.replace('.fut', { fontFamily: 'Fut', hover: true });
	var cuPG = [ '.loginLink', '.registerLink', '.cartLink', '.accountLink', '.signoutLink', '.welcomeMessage', '.pg' ];
	Cufon.replace(cuPG, { fontFamily: 'PG', hover: true });
	Cufon.now();
	
	// 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');
	});
	
	// close wishlist context dialogs when a product gets added
	$(document).delegate('.si-wishlist-add-form', 'addtowishlist', function() {
		$(this).parents('.ui-context-dialog').contextDialog('close');
	});

	//animate si-partial captions
	$('.si-partial').live({
		'mouseenter': function(e) {
			$(this).find('div.caption').stop().animate({'top':92}, 'fast');
		},
		'mouseleave': function(e) {
			$(this).find('div.caption').stop().animate({'top':150}, 'fast');
		}
	});

	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 });
});
