(function($){
	
	$.jQueryUI = function(el){
		if (!el) el = 'body:first';
		var $cont = $(el);
		
		$cont.find('.zebra').zebra();
		
		$cont.find('.nocopy').nocopyField();
		
		$cont.find('.first-case').firstCase();

		$cont.find('.province-case').firstCase({
			behavior : function(str){
				if (str.length>2) return this.firstCase(str);
				return str.toUpperCase();
			}
		});
		$cont.find('.digits-only').firstCase({
			behavior : function(str){
				return str.replace(/[^\d]/g, '');
			}
		});
		$cont.find('.zip-code').firstCase({
			behavior : function(str){
				return str.toUpperCase();
			}
		});

		$cont.find('.ui-hint-input').jHintInput();
		
		$cont.find('form.js-required').ketchup({
			validateHidden : false,
			validationAttribute : 'rel'
		});
	}

	$(document).ready(function(){
		$.jQueryUI();
		
		if (typeof $.fn.jBoxTape == 'function')
			$('.js-box-tape').jBoxTape({easing:'linear'});
		
		if (typeof $.jShoppingCart == 'object') $.jShoppingCart.init($('#shopping-cart'));
			
		$('ul.accordion').accordion({
			autoHeight : false
		});
		$('ul.accordion').each(function(){
			var $this = $(this);
			$this.find('a.selected').each(function(){
				if ($(this).parents('ul').size()>1){
					$(this).parents('li:eq(1)').find('> a:first').addClass('selected');
				}
			});
			$this.find('> li > a.selected').click();

			$this.find('> li > a').click(function(){
				var $ul = $(this).parent().find('ul');
				if (!$ul.size()) {
					redirect($(this).attr('href'));
					return false;
				}
			});

			var $div = $(this).parent();
			$div.find('a.selected:last').each(function(){
				$div.scrollTo(this);
			});
		});
	});
	
})(jQuery)

