function loadpage(ev,page){
	if(ev) ev.stop();
	if(page == 'slideshow'){
		var myHTMLRequest = new Request.HTML({update:'content',onComplete:function(){
			initialise_slideshow();
		}}).get(<hashes/$xh>+'site/php/views/slideshow.php');
	}else{
		var myHTMLRequest = new Request.HTML({update:'content'}).get(<hashes/$xh>+'site/php/views/'+page+'.php');
		if(ss){
			mySlideShow.pause();
			ss = false;
		}
	}
	window.location.hash = page;
}

var ss = false;
function initialise_slideshow(){
	var ss = true;
	
	mySlideShow = new SlideShow('slide_container',{
	    delay: 5000,
	    transition: 'blindRightFade',
	    duration: 500,
	    autoplay: false
	});
	
	var navs = $$('.ssa');

	// create navigation controls
	// var navs = $$('li');
	navs.each(function(element, index){
	    element.addEvents({
	        click: function(ev){
	            // index of list items match index of slides
				ev.stop();
	            mySlideShow.show(index, {transition: 'fadeThroughBackground', duration: 1000});
			return false;
	        }
	    });
	});
	
	
	var manualPaused = false;
	// var hoverEvents = {
	//     mouseenter: function(){ mySlideShow.pause(); },
	//     mouseleave: function(){
	//         if (!manualPaused) mySlideShow.play();
	//     }
	// };
	// 
	// mySlideShow.element.addEvents($merge(hoverEvents,{
	//     // can send transition and duration information to show methods
	//     click: function() { mySlideShow.showNext() }
	// }));
	// 

	mySlideShow.addEvent('show', function(slideData){
	    // args of the show event are the previous/next slides and their index
	    // again, nav index matches slide index so this is cake
	    navs[slideData.previous.index].removeClass('current');
	    navs[slideData.next.index].addClass('current');
	});
	
	mySlideShow.play();
	
}


var mySlideShow = null;
window.addEvent('load',function(){
	
	if(window.location.hash != ''){
		loadpage(null,window.location.hash.replace('#',''));
	}
	
	$('slideshow').addEvent('click',function(ev){
		loadpage(ev,'slideshow');
		});
		
	$('get-started').addEvent('click',function(ev){
		loadpage(ev,'get-started');
	});
	
	$('home').addEvent('click',function(ev){
		loadpage(ev,'home');
	});
	
	$('api-key').value = 'api-key...';
	$('api-key').addEvent('focus',function(ev){
		if(this.value == 'api-key...'){
			this.value ="";
		}
	})
	
	
})
