$(document).ready(function(){	
		
	$('body').addClass('has_JS');
	var $scrollbox = $('#scrollbox');

	$('body #nav > ul > li').each(function(){
		var $this=$(this);
		$this.hover(function(){
			$this.addClass('open');
		},function(){
			$this.removeClass('open');
		});
	});
	
	$('.minimise').each(function(){
		var $this = $(this);
		var $hd = $('h1', $this);
		var $bd = $('.bd', $this);
		var $bt = $('<a class="opener_a" style="border:none;" href="#">&nbsp;</a>');
		
		$hd.click(function(){
			var $container = $('.jScrollPaneContainer').offset().top;
			if ($this.hasClass('opener')) {
				$bd.slideUp(function(){ $scrollbox.jScrollPane(); });
				//$bd.slideUp(function(){ $scrollbox.jScrollPane(); $scrollbox.scrollTo(($('.opener .bd').offset().top + $('.opener .bd').height()) + $container); });
			} else {
				$('.minimise.opener .bd').slideUp();
				$('.minimise.opener').removeClass('opener');
				$bd.slideDown(function(){ $scrollbox.jScrollPane(); });
				//$bd.slideDown(function(){ $scrollbox.jScrollPane(); $scrollbox.scrollTo(($('.opener .bd').offset().top + $('.opener .bd').height()) + $container); });
			}
			$this.toggleClass('opener');
			
			return false;
			
		});
		$bt.prependTo($hd);
		$bd.hide();
	});
	
	// Initialise the Scroll Pane
	$scrollbox.jScrollPane();
	
	// Copy Address Button
	$('#copybutton button').click(function(){
		
		// select the shipping title
		$('#shipping select[@name="ship-title"]').val($('#invoice select[@name="inv-title"] option:selected').val());
		
		// copy the invoice field values over to the shipping fields
		$('#invoice input[@name^="inv-"]').each(function(){
			var $val = $(this).val();
			var $name = $(this).attr('name').replace(/^inv/,"ship");
			$('#shipping input[@name="'+$name+'"]').val($val);
		});
		return false;
	});
	
	// Yobbo Flash Box
	var t = $.timer(2000, function(timer) {
		$('.yobbo_flash').fadeOut(1000);
	});

});