﻿$(function() {
	//get rid of asp handler if we've got javascript
	var scrollapi;
	$('div.timeline a.next').attr('href', '#') //.bind('mouseenter', pause).bind('mouseleave', start);
	$('div.timeline a.prev').attr('href', '#') //.bind('mouseenter', pause).bind('mouseleave', start);
//	function pause() {
//		scrollapi.getConf().interval = 0;
//	}
//	function start() {
//		scrollapi.getConf().interval = 350;
//		scrollapi.getConf().easing = 'swing';
//		scrollapi.reload();
//	}
	//set up our handlers
	if ($('div.scrollable div.items a.selected').length) //if nothing is selected then auto scroll
	{
		scrollapi = $('div.scrollable').scrollable({
			size: 4,
			speed: 350,
			easing: 'swing',
			keyboard: false,
			api: true
		});
	} else {
		scrollapi = $('div.scrollable').scrollable({
			size: 4,
			speed: 350,
			easing: 'swing',
			interval: 1500,
			loop: true,
			keyboard: false,
			api: true
		});
	}
	// select items under the second scrollable and do something when they are clicked
	$("div.timeline div.scrollable div.items a").click(function(e) {
		e.preventDefault();
		e.stopPropagation();
		// perform the effect

		//change selection
		$("div.timeline div.scrollable div.items a.selected").removeClass('selected');
		$(this).addClass('selected');

		//get details
		window.location = "memory.aspx?MemoryId=" + $(this).attr('rel');
		return false;
	});
	$('div.timeline a.next').click(function(e) {
		if (scrollapi.getIndex() == scrollapi.getItems().length - scrollapi.getConf().size) {
			//last one so click it
			$('div.scrollable .items>a').eq(scrollapi.getIndex() + (scrollapi.getConf().size - 1)).click();
		} else {
			$('div.scrollable').scrollable().next();
			e.preventDefault();
		}
	});
	$('div.timeline a.prev').click(function(e) {
		if (scrollapi.getIndex() == 0) {
			//first one so click it
			$('div.scrollable .items>a').eq(0).click();
		} else {
			$('div.scrollable').scrollable().prev();
			e.preventDefault();
		}
	});

	$('div.scrollable').scrollable().seekTo($('div.scrollable div.items a').index($('a.selected')) - 1);
});