//Change video function
function change_video( video ){
	var the_video	=	"#" + video;
	$( the_video ).siblings().hide();
	$( the_video ).fadeIn(2000);
	//Pause the Media Player
	pause_player();
}
//Pause player function
function pause_player(){
    YAHOO.MediaPlayer.pause();
}

var app = $.sammy(function() { with(this) {
	//Bind functions
	
	//Change_view function
	//We randomly pick either a fade or a slide
	bind('change_view', function(e, data) { with(this) {
		//Get choice										 
		var choice	=	rand(2) ;

		var the_element	=	"#"	+ data['view'];
		
		//Fade
		if ( choice == 3 ){
			$( the_element ).siblings().fadeOut(1000);
			$( the_element ).fadeIn(2000);
		}
		//Slide
		else{
			$( the_element ).siblings().slideUp(1000, function(){
			$( the_element ).slideDown(1000);
															   });
		}
	}});

	//Routes
	get('#/', function() { with(this) {
    	trigger('change_view', { view: "home" } );
  	}});
	get('#/:path', function() { with(this) {
    	trigger('change_view', { view: params['path'] } );
  	}});
}});

//Document load listener
$(function() {
	//Hash watcher	   
	if ( window.location.hash == "" || window.location.hash == "#" )
		window.location.hash		=	"#/";
  app.run();
  
  	//Slide show control
	$('#container').panelGallery({
		sections:				4,
		imageTransitionDelay:	2000,
		startDelay:				3000
	});
});


function rand ( n ){
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}
