$(document).ready(function () {
	// 1. create scroll effect
	// 2. handle the selection of the navigation
	// 3. prev + next image buttons ?
	// 4. support vertical and horizontal 
	
	
	var horizontal = true;
	//var $panels = $('#slider .panel');
	var $panels = $('#slider .scrollContainer > div');
	//var $container = $('#slider .scrollContainer');
	var $container = $('#slider .scrollContainer');
	var $scroll = $('#slider .scroll').css('overflow', 'hidden');
	
	

	
	$scroll
		.before('<img src="images/arrow_back.png" class="scrollButtons previousbutton" />')
		.after('<img src="images/arrow_next.png" class="scrollButtons nextbutton" />');
		
	var $previous = $('.previousbutton');
	var $next = $('.nextbutton');
	
	
	if (horizontal) {
		$panels.css ({
			'float' : 'left',
			'position' : 'relative'
		});
		
		$container.css('width', $panels[0].offsetWidth * $panels.length);
	}
	
	
	
	function selectNav() {
		$('#topmenu').find('a').removeClass('selected');
		$(this).addClass('selected');		
	}
	
	$('#topmenu a').click(selectNav);
		
	
	var scrollOptions = {
		target: $scroll, 
		items: $panels,
		navigation: '#topmenu a',
		// selectors are NOT relative to document, i.e. make sure they're unique
  		prev: 'img.previousbutton', 
  		next: 'img.nextbutton',
		axis: 'x',		
		duration: 500,
		easing: 'swing',
		onAfter: trigger
	};
	
	function trigger(data) {
		//alert(data.id);
		var el = $('#topmenu').find('a[href$="' + data.id + '"]').get(0);			
		selectNav.call(el);
	}
	
	if (window.location.hash) {
		trigger({ id: window.location.hash.substr(1) });
	} else {
		$('#topmenu a:first').click();
		//$('#slider .navigation a:first').click();
	}
	
	// apply serialScroll to the slider - we chose this plugin because it 
	// supports// the indexed next and previous scroll along with hooking 
	// in to our navigation.
	$('#slider').serialScroll(scrollOptions);

	// now apply localScroll to hook any other arbitrary links to trigger 
	// the effect
	$.localScroll(scrollOptions);

	// finally, if the URL has a hash, move the slider in to position, 
	// setting the duration to 1 because I don't want it to scroll in the
	// very first page load.  We don't always need this, but it ensures
	// the positioning is absolutely spot on when the pages loads.
	scrollOptions.duration = 1;
	$.localScroll.hash(scrollOptions);
	});
