var current_profile = '';

function coverflowSelect(person) {
	var link = 'our-people/' + person + '/';
	$('div.content-section').hide();
	$('div#content-area').slideDown("normal");	
//	var link = $(this).children('div.name').children('a').attr('href');
	$('div#section-' + link.replace(/\//g, '-')).fadeIn();
	// hide thumbnails
	$('div#coverflow-flash').hide();
	// show the video player
	$('div#video-player').css('visibility', 'visible');
	// also change the video file to
	api.playClip({url: '/videos/' + link + 'intro.flv'});
	current_profile = link;
	$('div#toggler > a').toggleClass("open");
	$('div#subnav > ul > li').removeClass('on'); // remove nav star and add the correct one
	if (link == 'our-people/hussein-osman/') {
		$('div#subnav > ul > li:eq(1)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/carly-holt/') {
		$('div#subnav > ul > li:eq(2)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/anthony-fairweather/') {
		$('div#subnav > ul > li:eq(3)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/david-maddock/') {
		$('div#subnav > ul > li:eq(4)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/felicity-lowless/') {
		$('div#subnav > ul > li:eq(5)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/graham-mcintyre/') {
		$('div#subnav > ul > li:eq(6)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/nicola-lee/') {
		$('div#subnav > ul > li:eq(7)').addClass('on'); // remove nav star and add the correct one			
	}
	if (link == 'our-people/thomas-chiffers/') {
		$('div#subnav > ul > li:eq(8)').addClass('on'); // remove nav star and add the correct one			
	}
}


$(document).ready(function(){

	//var current_profile = 'our-people/hussein-osman/'; // TEMP

	// customise homepage toggler
	$("div#toggler > a").click(function() {
		$(this).toggleClass("open");
		if ($('div#content-area').css('display') == 'block') {
			$('div#content-area').slideUp("normal");
			$(this).attr('title', 'Tell me more');				
		} else {
			$('div#content-area').slideDown("normal");	
			$(this).attr('title', 'Hide content');				
		}
	});

	$("div.tab-nav a").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.content-section').hide();
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		return false;
	});

	$("body#body-our-people div#subnav a").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one and start the new video
		$('div.content-section').hide();
		$('div#subnav > ul > li').removeClass('on');
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		$(this).parent().addClass('on');
		// show the video player
		$('div#video-player').css('visibility', 'visible');
		// hide thumbnails
		$('div#coverflow-flash').hide();
		// also change the video file to the person's intro	
		api.playClip({url: '/videos/' + link + 'intro.flv'});
		current_profile = link;
		return false;
	});

/*
	$("div#thumbnails div.thumbnail").click(function() {
		// thumbnail has been clicked on - hide all .content-section divs and show the correct one and start the new video
		$('div.content-section').hide();
		$('div#content-area').slideDown("normal");	
		var link = $(this).children('div.name').children('a').attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		// hide thumbnails
		$('div#thumbnails').hide();
		// show the video player
		$('div#video-player').css('visibility', 'visible');
		// also change the video file to
		api.playClip({url: '/videos/' + link + 'intro.flv'});
		current_profile = link;
		$('div#toggler > a').toggleClass("open");
		$('div#subnav > ul > li').removeClass('on'); // remove nav star and add the correct one
		if (link == 'our-people/nic-hart/') {
			$('div#subnav > ul > li:eq(1)').addClass('on'); // remove nav star and add the correct one			
		}
		if (link == 'our-people/hussein-osman/') {
			$('div#subnav > ul > li:eq(2)').addClass('on'); // remove nav star and add the correct one			
		}
		if (link == 'our-people/carly-holt/') {
			$('div#subnav > ul > li:eq(3)').addClass('on'); // remove nav star and add the correct one			
		}
		return false;
	});
*/

	$("div#subnav a").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.content-section').hide();
		$('div#subnav > ul > li').removeClass('on');
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		$(this).parent().addClass('on');
		return false;
	});

	$("a.contentlink").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.content-section').hide();
		$('div#subnav > ul > li').removeClass('on');
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		return false;
	});

	$("div.video-profile a").click(function() {
		$('div.video-profile a').removeClass('selected');
		// show the correct question video
		api.playClip({url: '/videos/' + current_profile + $(this).attr('class') + '.flv'});
		$(this).addClass('selected');
		return false;
	});
	
	$("div#locations a").mouseover(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.location-details').hide();
		var link = $(this).attr('href');
		$('div#location-' + link.replace(/\//g, '-')).fadeIn();
	});
	
	$("div#locations a").click(function() {
		return false;
	});
		
	$("div.show-transcription").click(function() {
		if ($("div.transcript").css('display') == 'block') {
			$("div.transcript").slideUp('normal');
			$(this).text('Show transcription');
		} else {
			$("div.transcript").slideDown('normal');			
			$(this).text('Hide transcription');
		}
		$(this).toggleClass("hide-transcription");
	});

});
