// JavaScript Document
$(document).ready(function() {
	
	// The below uses JQuryTools UI Library - for documentation and support, see: http://flowplayer.org/tools/index.html	
	
	
	// OVERLAYS  ///////////////////////////
	
    //activate zoom overlay on clicking each link with 'rel' attribute
    $(".mainbub a[rel]").overlay({

			mask: '#000', 
			effect: 'apple', 
			top: 'center'

	});
	
	$(".fellow a[rel]").overlay({
		
		mask: '#000', 
		fixed: 'false', 
		top: 'center', 
		effect:'default'
		
	});	
	
	// stop all video players from playing when the overlay close button is clicked
	$(".overlay .close").click( function(){
				
		player = document.getElementById('ytplayer');

    	function stop(){
	        player.stopVideo();
    	    return false;
	    }
		stop();
	
	});
	
	
	// SCROLLABLES  ///////////////////////////
	
	// initialize vertical scrollable
	$(".vscrollablewrapper .scrollable").scrollable({ vertical: true, mousewheel: false }).navigator();

	// initialize horizontal scrollable
	$(".hscrollablewrapper .scrollable").scrollable({ vertical: false, mousewheel: false, circular: true}).navigator().autoscroll({ autoplay: true, interval: 5000 });	


	// INITIALISE HOMEPAGE FELLOWS SCROLLER
	
	// hide all fellow items on start
	$("#scrollablefellow .items").fadeTo(0,0);
	
	// set flag for randomising first transistion
	var _firstTime =true;
	
	// initialise the scroller				
	var _fellowScroller = $("#scrollablefellow .scrollable").scrollable({ 
				
				// SET PARAMETERS
												
				// does this scrollable scroll vertically?			
				vertical: false, 
				
				// scroll through items using mousewheel?
				mousewheel: false, 
				
				// automatically return to start after last item in scrollable?
				circular: true,
				
				// speed of transitions?
				speed: 0,
								
				// fade out on start of transition
				onBeforeSeek: function() { 							
				
			    	    $("#scrollablefellow .items").fadeTo(350,0);
				
					},
					
				// fade in on end of transition
				onSeek: function() {
					
				    	$("#scrollablefellow .items").fadeTo(250,1);        												
						
					}
			
			}).autoscroll({ 
				
				autoplay: true, 
				interval: 12000
	
			}).data("scrollable");
			
	
	// Test if #scrollablefellow is on the page
	if ($("#scrollablefellow").length > 0){
	
		// on start, select a random fellow from the list		
		if(_firstTime){
				
			_fellowScroller.seekTo( Math.floor(Math.random() * _fellowScroller.getItems().length));			
			_firstTime=false;						
	
		}
	}
	
	
	// VERTICAL SCROLLABLE - EXPAND CONTENT BUTTON
		 
	$('.expand-button').live('click', function(){
		 		 
		if ($('.expand-button').hasClass('expanded')) {
	
			// Amend link text and retract content
			$('.expand-button').text("MORE");
			$('.vertical').stop().animate({ height:'342' }, 250);	
		
		}else{
			// Amend link text and expand content
			$('.expand-button').text("LESS");
			$('.vertical').stop().animate({ height:'1260' }, 250);			
		}
		
		$('.expand-button').toggleClass("expanded");	
	
		return false;		
	});

	$('#actions .next').live('click', function(){
		
		$("html, body").delay(100).animate({ scrollTop: 0 }, "slow");
		return false;
		
	});

						
																    
});


