



$(document).ready(function(){

	// Local copy of jQuery selectors, for performance.
	var	my_jPlayer = $("#jquery_jplayer"),
		my_trackName = $("#text .title"),
		my_playState = $("#controls .playState"),
		my_extraPlayInfo = $("#controls .extra-play-info"),
		soundPlaying = 0;

	// Some options
	var	opt_play_first = false, // If true, will attempt to auto-play the default track on page loads. No effect on mobile devices, like iOS.
		opt_auto_play = true, // If true, when a track is selected, it will auto-play.
		opt_text_playing = "", // Text when playing
		opt_text_selected = ""; // Text when not playing

	// A flag to capture the first track
	var first_track = true;

	// Change the time format
	$.jPlayer.timeFormat.padMin = false;
	$.jPlayer.timeFormat.padSec = false;
	$.jPlayer.timeFormat.sepMin = " min ";
	$.jPlayer.timeFormat.sepSec = " sec";

	// Initialize the play state text
	my_playState.text(opt_text_selected);

	// Instance jPlayer
	my_jPlayer.jPlayer({
		ready: function () {
			$("#track-04").click();
			my_trackName.text("");
			$('.standard').text("Skru op for lyden og klik på en kassette eller ghettoblasteren");
			$('.standard').fadeIn();
		},
		timeupdate: function(event) {
			my_extraPlayInfo.text(parseInt(event.jPlayer.status.currentPercentAbsolute, 10) + "%");
		},
		play: function(event) {
			$('#controls').show();
			$('.standard').text("");
			$('.standard').hide();
			soundPlaying == 1;
		},
		stop: function(event) {
			$('#controls').hide();
			$('.standard').text("Skru op for lyden og klik på en kassette eller ghettoblasteren");
			$('.standard').fadeIn();
			soundPlaying == 0;
		},
		pause: function(event) {
			$('#controls').hide();
			$('.standard').text("Skru op for lyden og klik på en kassette eller ghettoblasteren");
			$('.standard').fadeIn();
			soundPlaying == 0;
		},
		ended: function(event) {
			$('#controls').hide();
			$('.standard').text("Skru op for lyden og klik på en kassette eller ghettoblasteren");
			$('.standard').fadeIn();
			_gaq.push(['_trackEvent', 'Sounds', 'Ended', 'Listened full lenght']);
			soundPlaying == 0;
		},
		swfPath: "js",
		cssSelectorAncestor: "#controls",
		supplied: "mp3",
		wmode: "window"
	});

	// Create click handlers for the different tracks
	$("#track-04").click(function(e) {
		my_trackName.text("om frygt");
		my_jPlayer.jPlayer("setMedia", {
			mp3: $(this).attr("href")
		});
		if((opt_play_first && first_track) || (opt_auto_play && !first_track)) {
			my_jPlayer.jPlayer("play");
		}
		first_track = false;
		$(this).blur();
		return false;
	});
	
	$("#track-03").click(function(e) {
		my_trackName.text("om viden");
		my_jPlayer.jPlayer("setMedia", {
			mp3: $(this).attr("href")
		});
		if((opt_play_first && first_track) || (opt_auto_play && !first_track)) {
			my_jPlayer.jPlayer("play");
		}
		first_track = false;
		$(this).blur();
		return false;
	});
	
	$("#track-02").click(function(e) {
		my_trackName.text("om plejer");
		my_jPlayer.jPlayer("setMedia", {
			mp3: $(this).attr("href")
		});
		if((opt_play_first && first_track) || (opt_auto_play && !first_track)) {
			my_jPlayer.jPlayer("play");
		}
		first_track = false;
		$(this).blur();
		return false;
	});
	
	$("#track-01").click(function(e) {
		my_trackName.text("om størrelse");
		my_jPlayer.jPlayer("setMedia", {
			mp3: $(this).attr("href")
		});
		if((opt_play_first && first_track) || (opt_auto_play && !first_track)) {
			my_jPlayer.jPlayer("play");
		}
		first_track = false;
		$(this).blur();
		return false;
	});
	
	
	$('#mikkelBody').hoverIntent(function () {$('#mikkelInfo').fadeIn();},function () {$('#mikkelInfo').fadeOut();});
	$('#nicolaiBody').hoverIntent(function () {$('#nicolaiInfo').fadeIn();},function () {$('#nicolaiInfo').fadeOut();});
	$('#kirstenBody').hoverIntent(function () {$('#kirstenInfo').fadeIn();},function () {$('#kirstenInfo').fadeOut();});
	$('#christianBody').hoverIntent(function () {$('#christianInfo').fadeIn();},function () {$('#christianInfo').fadeOut();});

	
	$('#mikkelGhetto').hover(function () {$('.standard').hide();my_trackName.text("om frygt");$('.title').fadeIn();},function () {$('.title').hide();$('.standard').show();});
	$('#kirstenTape').hover(function () {$('.standard').hide();my_trackName.text("om størrelse");$('.title').fadeIn();},function () {$('.title').hide();$('.standard').show();});
	$('#nicolaiTape').hover(function () {$('.standard').hide();my_trackName.text("om plejer");$('.title').fadeIn();},function () {$('.title').hide();$('.standard').show();});
	$('#christianTape').hover(function () {$('.standard').hide();my_trackName.text("om viden");$('.title').fadeIn();},function () {$('.title').hide();$('.standard').show();});

	
	
});

