function instanceInfo(myPlayer, myInfo) {
	var jPlayerInfo = "<p>This jPlayer instance is running in your browser using ";

	if(myPlayer.jPlayer("getData", "usingFlash")) {
		jPlayerInfo += "<strong>Flash</strong> with ";
	} else {
		jPlayerInfo += "<strong>HTML5</strong> with ";
	}

	if(myPlayer.jPlayer("getData", "usingMP3")) {
		jPlayerInfo += "<strong>MP3</strong>";
	} else {
		jPlayerInfo += "<strong>OGG</strong>";
	}


	jPlayerInfo += " files.<br />This instance is using the constructor options:<br /><code>$(\"#" + myPlayer.jPlayer("getData", "id") + "\").jPlayer({<br />";
	
	jPlayerInfo += "&nbsp;&nbsp;&nbsp;nativeSupport: " + myPlayer.jPlayer("getData", "nativeSupport");
	jPlayerInfo += ", oggSupport: " + myPlayer.jPlayer("getData", "oggSupport");
	jPlayerInfo += ", customCssIds: " + myPlayer.jPlayer("getData", "customCssIds");

	jPlayerInfo += "<br />});</code></p>";
	myInfo.html(jPlayerInfo);
}

function statusInfo(myPlayer, myInfo) {
	var jPlayerStatus = "<p>jPlayer is ";
	jPlayerStatus += (myPlayer.jPlayer("getData", "diag.isPlaying") ? "playing" : "stopped");
	jPlayerStatus += " at time: " + Math.floor(myPlayer.jPlayer("getData", "diag.playedTime")) + "ms.";
	jPlayerStatus += " (tt: " + Math.floor(myPlayer.jPlayer("getData", "diag.totalTime")) + "ms";
	jPlayerStatus += ", lp: " + Math.floor(myPlayer.jPlayer("getData", "diag.loadPercent")) + "%";
	jPlayerStatus += ", ppr: " + Math.floor(myPlayer.jPlayer("getData", "diag.playedPercentRelative")) + "%";
	jPlayerStatus += ", ppa: " + Math.floor(myPlayer.jPlayer("getData", "diag.playedPercentAbsolute")) + "%)</p>"
	myInfo.html(jPlayerStatus);
}
function capitaliseThis(val) {
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
        }
        return newVal;
}

$(document).ready(function() {

$('#js-news').ticker({
			speed: 0.10,
			fadeInSpeed: 600,
                        debugMode: false,
                        controls: false,
			titleText: ''
		});
$('a#hide-updates').click(function() {
    $('#ticker-wrapper, #ticker-header').toggle();
    if($('a#hide-updates').text()=="show updates") {
    $('a#hide-updates').text("hide updates");
    $("#latest-updates").css("border-bottom", "1px solid", "border-bottom-color", "#dddddd");
    } else if($('a#hide-updates').text()=="hide updates") {
    $('a#hide-updates').text("show updates");
    $("#latest-updates").css("border-bottom", "none");
    }
});
$('a#important-close').click(function() {
    $('#important-dates').hide();
    $("#header").css("margin", "50px 0 0 0");
    return false;
});

// hover menu madness; get it while it's hot, it's lovely
        $('#navigation a.droplink').hover(function() {
            $('#navigation .dropmenu').hide();
            var theID = $(this).attr("id");
            var parts = theID.split("nav-");
            var linkid = parts[1];
            $('#'+linkid+"-drop").show();
        });
        $('#container').hover(function() {
            $('#navigation .dropmenu').hide();
        });
// logo flash
var flashvars = {};
			var params = {};
			params.play = "true";
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("elements/logo.swf", "logo", "230", "100", "9.0.0", false, flashvars, params, attributes);
// callback ajax
$("#contact-submit").click(function(){
var thename = $("#name").text;
var theemail = $("#email").text;
var thetelephone = $("#telephone").text;
if(thename!="" && theemail!="" && thetelephone!="") {
var str = $("#enquiryform").serialize();
$.ajax({
type: "POST",
url:  "../ajax/form_september.php",
cache: false,
data: str,
success: function(msg){
$("#contact-message").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
var result = '<p><strong>Thank you.<br />Your interest has been registered.<br />You will receive a response from us shortly</strong></p>';
$("#enquiryform").hide();
//_gaq.push(['_trackPageview', '/contact-submitted']);
//$("#intro").hide();
} else if (msg == 'FAIL1') {
var result = '<div id="error"><p><strong>Please fill out all required fields</strong></p></div>';
} else if (msg == 'FAIL2') {
var result = '<p>We may not have received your request.<br>Please try again if we don\'t contact you within 48 hours.</p>';
} else {
var result = '<p>There was a problem with your request. We apologize.<br />Please try again later.</p>';
//$("#callback-form").hide();
}
$('#contact-message').show(300).html(result);
});
}
});
}
return false;
});

// work applciation register interest ajax
$("#interest-submit").click(function(){
var thename = $("#name").text;
var theemail = $("#email").text;
var thetelephone = $("#telephone").text;
var theyear = $("#year").text;
var theemployment = $("#employment").text;
if(thename!="" && theemail!="" && thetelephone!="" && theemployment!="") {
var str = $("#enquiryform").serialize();
$.ajax({
type: "POST",
url:  "../ajax/form_september.php",
cache: false,
data: str,
success: function(msg){
$("#contact-message").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
var result = '<p><strong>Thank you.<br />Your request has been sent.<br />You will receive a response from us shortly</strong></p>';
$("#enquiryform").hide();
//_gaq.push(['_trackPageview', '/contact-submitted']);
//$("#intro").hide();
} else if (msg == 'FAIL1') {
var result = '<div id="error"><p><strong>Please fill out all required fields</strong></p></div>';
} else if (msg == 'FAIL2') {
var result = '<p>We may not have received your request.<br>Please try again if we don\'t contact you within 48 hours.</p>';
} else {
var result = '<p>There was a problem with your request. We apologize.<br />Please try again later.</p>';
//$("#callback-form").hide();
}
$('#contact-message').show(300).html(result);
});
}
});
}
return false;
});

var pageName = $("body").attr("id");
if(pageName=="page-gallery" || pageName=="page-news-detail" || pageName=="page-blog-detail" || pageName=="page-brit-fm") {
$("a.galleryimg").colorbox();
if(pageName=="page-gallery") {
$(".scrollable").scrollable();
$('.prev, .next').click(function(){
return false;
});
}
if(pageName=="page-brit-fm") {
// jplayer - mp3 audio play
// jplayer functions
var playItem = 0;

	var myPlayList = [
		{name:"Natasha and Kalan on the event",mp3:"elements/audio/natasha_and_kalan_on_the_event.mp3"},
        {name:"Cheyne and Darren on Interactive Exhibits",mp3:"elements/audio/cheyne_and_darren_on_interactive_exhibits.mp3"},
        {name:"Cheyne and Darren on Brit Course",mp3:"elements/audio/cheyne_and_darren_on_brit_course.mp3"},
        {name:"Cheyne and Darren on Birmingham",mp3:"elements/audio/cheyne_darren_on_birmingham.mp3"},
        {name:"Full crew memories and saying goodbye",mp3:"elements/audio/full_crew_memories_and_saying_goodbye.mp3"}
	];

    var myPlayList2 = [
		{name:"Stu and Lydia",mp3:"elements/audio/stu_and_lydia.mp3"},
        {name:"Stu and Kiera",mp3:"elements/audio/stu_and_kiera.mp3"},
        {name:"Stu, Joe and Daisy",mp3:"elements/audio/stu_joe_and_daisy.mp3"},
        {name:"Stu, James and Georgina",mp3:"elements/audio/stu_james_and_georgina.mp3"},
        {name:"Stu, Izzy, William and Isaac",mp3:"elements/audio/stu_izzy_william_and_isaac.mp3"},
        {name:"Stu and George",mp3:"elements/audio/stu_and_george.mp3"}
	];

	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");
	var jpStatus = $("#status"); // For displaying information about jPlayer's status in the  page
    var jpPlayTime2 = $("#jplayer_play_time2");
	var jpTotalTime2 = $("#jplayer_total_time2");
	var jpStatus2 = $("#status2"); // For displaying information about jPlayer's status in the  page
    var jpPlayTime3 = $("#jplayer_play_time3");
	var jpTotalTime3 = $("#jplayer_total_time3");
	var jpStatus3 = $("#status3"); // For displaying information about jPlayer's status in the  page

	$("#audioplayer-staff").jPlayer({
		ready: function () {
			this.element.jPlayer();
			//instanceInfo(this.element, $("#player_info")); // This displays information about jPlayer's configuration in the  page
		},
                volume:45
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));

		statusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the page
	})
	.jPlayer("onSoundComplete", function() {
		//$("#jquery_jplayer2").jPlayer("playHead", 0); // Crossover the players here
                //alert("ende");
	});
        $("#audioplayer-crew").jPlayer({
		ready: function () {
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
			//instanceInfo(this.element, $("#player_info")); // This displays information about jPlayer's configuration in the  page
		},
                volume:45,
		customCssIds: true
	})
	.jPlayer("cssId", "pause", "jplayer_pause2")
	.jPlayer("cssId", "play", "jplayer_play2")
	.jPlayer("cssId", "stop", "jplayer_stop2")
	.jPlayer("cssId", "loadBar", "jplayer_load_bar2")
	.jPlayer("cssId", "playBar", "jplayer_play_bar2")
	.jPlayer("cssId", "volumeMin", "jplayer_volume_min2")
	.jPlayer("cssId", "volumeMax", "jplayer_volume_max2")
	.jPlayer("cssId", "volumeBar", "jplayer_volume_bar2")
	.jPlayer("cssId", "volumeBarValue", "jplayer_volume_bar_value2")
        .jPlayer("cssId", "playedTime", "jplayer_play_time2")
        .jPlayer("cssId", "totalTime", "jplayer_total_time2")

	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime2.text($.jPlayer.convertTime(playedTime));
		jpTotalTime2.text($.jPlayer.convertTime(totalTime));

		statusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the page
	})
	.jPlayer("onSoundComplete", function() {
        playListNext();
		//$("#jquery_jplayer2").jPlayer("playHead", 0); // Crossover the players here
                //alert("ende");
	});

    $("#jplayer_previous2").click( function() {
		playListPrev();
		$(this).blur();
		return false;
	});

	$("#jplayer_next2").click( function() {
		playListNext();
		$(this).blur();
		return false;
	});

	function displayPlayList() {
		$("#jplayer_playlist ul").empty();
		for (i=0; i < myPlayList.length; i++) {
			var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
			listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1' title='"+ myPlayList[i].name +"'>"+ myPlayList[i].name +"</a></li>";
			$("#jplayer_playlist ul").append(listItem);
			$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
				var index = $(this).data("index");
                                var title = $(this).attr("title");
                                $("#fileinfo-crew").html(title)
                                //alert(title);
				if (playItem != index) {
					playListChange( index );
				} else {
					$("#audioplayer-crew").jPlayer("play");
				}
				$(this).blur();
				return false;
			});
		}
	}

// brit-fm crew playlist player
	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
		playItem = index;
		$("#audioplayer-crew").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		$("#audioplayer-crew").jPlayer("play");
	}

	function playListNext() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange( index );
	}

	function playListPrev() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange( index );
	}

// students playlist player
    $("#audioplayer-students").jPlayer({
		ready: function () {
			displayPlayList2();
			playListInit2(false); // Parameter is a boolean for autoplay.
			//instanceInfo(this.element, $("#player_info")); // This displays information about jPlayer's configuration in the  page
		},
                volume:45,
		customCssIds: true
	})
	.jPlayer("cssId", "pause", "jplayer_pause3")
	.jPlayer("cssId", "play", "jplayer_play3")
	.jPlayer("cssId", "stop", "jplayer_stop3")
	.jPlayer("cssId", "loadBar", "jplayer_load_bar3")
	.jPlayer("cssId", "playBar", "jplayer_play_bar3")
	.jPlayer("cssId", "volumeMin", "jplayer_volume_min3")
	.jPlayer("cssId", "volumeMax", "jplayer_volume_max3")
	.jPlayer("cssId", "volumeBar", "jplayer_volume_bar3")
	.jPlayer("cssId", "volumeBarValue", "jplayer_volume_bar_value3")
        .jPlayer("cssId", "playedTime", "jplayer_play_time3")
        .jPlayer("cssId", "totalTime", "jplayer_total_time3")

	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime3.text($.jPlayer.convertTime(playedTime));
		jpTotalTime3.text($.jPlayer.convertTime(totalTime));

		statusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the page
	})
	.jPlayer("onSoundComplete", function() {
        playListNext2();
		//$("#jquery_jplayer2").jPlayer("playHead", 0); // Crossover the players here
                //alert("ende");
	});

    $("#jplayer_previous3").click( function() {
		playListPrev2();
		$(this).blur();
		return false;
	});

	$("#jplayer_next3").click( function() {
		playListNext2();
		$(this).blur();
		return false;
	});


function displayPlayList2() {
		$("#jplayer_playlist2 ul").empty();
		for (i=0; i < myPlayList2.length; i++) {
			var listItem = (i == myPlayList2.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
			listItem += "<a href='#' id='jplayer_playlist2_item_"+i+"' tabindex='1' title='"+ myPlayList2[i].name +"'>"+ myPlayList2[i].name +"</a></li>";
			$("#jplayer_playlist2 ul").append(listItem);
			$("#jplayer_playlist2_item_"+i).data( "index", i ).click( function() {
				var index = $(this).data("index");
                                var title = $(this).attr("title");
                                $("#fileinfo-students").html(title)
				if (playItem != index) {
					playListChange2( index );
				} else {
					$("#audioplayer-students").jPlayer("play");
				}
				$(this).blur();
				return false;
			});
		}
	}

function playListInit2(autoplay) {
		if(autoplay) {
			playListChange2( playItem );
		} else {
			playListConfig2( playItem );
		}
	}

	function playListConfig2( index ) {
		$("#jplayer_playlist2_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist2_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
		playItem = index;
		$("#audioplayer-students").jPlayer("setFile", myPlayList2[playItem].mp3, myPlayList2[playItem].ogg);
	}

	function playListChange2( index ) {
		playListConfig2( index );
		$("#audioplayer-students").jPlayer("play");
	}

	function playListNext2() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange2( index );
	}

	function playListPrev2() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange2( index );
	}

	// Add extra .click() event handlers to avoid both jPlayers playing together.

	/*$("#jplayer_play").click( pausePlayer2 );
	$("#jplayer_load_bar").click( pausePlayer2 );
	$("#jplayer_play_bar").click( pausePlayer2 );

	$("#jplayer_play2").click( pausePlayer1 );
	$("#jplayer_load_bar2").click( pausePlayer1 );
	$("#jplayer_play_bar2").click( pausePlayer1 );

	function pausePlayer1(e) {
		$("#audioplayer-crew").jPlayer("pause");
                //$("#audioplayer-students").jPlayer("pause");
	}
	function pausePlayer2(e) {
                $("#audioplayer-staff").jPlayer("pause");
		//$("#audioplayer-students").jPlayer("pause");
	}
        function pausePlayer3(e) {
                $("#audioplayer-staff").jPlayer("pause");
		$("#audioplayer-crew").jPlayer("pause");
	}*/
    $('a.britaudiolink').click(function(){
        var person = $(this).attr("id");
        $("#audioplayer-crew").jPlayer("stop");
        $("#fileinfo-crew").html("");
        $("#audioplayer-staff").jPlayer("playHead", 0);
        $("#audioplayer-staff").jPlayer("setFile", "elements/audio/"+person+".mp3").jPlayer("play");
        var newperson = person.replace("_", " ");
        var personDisplay = capitaliseThis(newperson);
        $("#fileinfo-staff").html("currently listening to "+personDisplay);
        return false;
    });

     /* $('a.crewaudiolink').click(function(){
        var person = $(this).attr("id");
        $("#audioplayer-staff").jPlayer("stop");
        $("#fileinfo-staff").html("");
        $("#audioplayer-crew").jPlayer("playHead", 0);
        $("#audioplayer-crew").jPlayer("setFile", "elements/audio/"+person+".mp3").jPlayer("play");
        var newperson = person.replace(/_/g, " ");
        var personDisplay = capitaliseThis(newperson);
        $("#fileinfo-crew").html("currently listening to "+personDisplay);
        return false;
    });*/
// ende jplayer

$(".scrollable, .scrollable2").scrollable();
$('.prev, .next').click(function(){
return false;
});

$('a.crewlink').click(function(){
var imagename = $(this).attr("id");
//alert(imagename);
$("#photo-gallery-crew #main-photo img").attr("src", "images/britfm/"+imagename+".jpg");
return false;
});
$('a.studentslink').click(function(){
var imagename = $(this).attr("id");
//alert(imagename);
$("#photo-gallery-students #main-photo img").attr("src", "images/britfm/"+imagename+".jpg");
return false;
});

}

}
// popup a box explaining what the pdf is for, and the address to send it to
$('.popup').fancybox({
		'width'				: 760,
		'height'			: 700,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'scrolling'			: 'no',
		'transitionOut'		: 'none',
		'hideOnOverlayClick': false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'
	});

if(pageName=="page-home") {
// 25-05-2011
	/*$.fancybox(
		'<a href="http://www.boa-academy.co.uk/documents/BOA_student_application_form.pdf" target="_blank"><img src="http://www.boa-academy.co.uk/images/boa-billboard.jpg" /></a>',
		{
        	'autoDimensions'	: true,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none',
			'centerOnScroll'    : 'true'
		}
	);*/

	$(document).ready(function() {
		//$('#javascriptDisabled').show();
	});
	
	$('.horizontal_scroller').SetScroller({	velocity: 60,
	direction: 	 'horizontal',
	startfrom: 	 'right',
	loop:		 'infinite',
	movetype: 	 'linear',
	onmouseover:     'pause',
	onmouseout:      'play',
	onstartup: 	 'play',
	cursor: 	 'pointer'
	});
}
// end document ready
});
