
var $play_status = "play";
var $global_swfPath = "/js";
var $global_audioPath = "/audio";


$(document).ready(function()
{
	feenstaub_init();
	
	$("p#audio_startseite_aus_an").click(function(event){
		audio_startseite_toggle();
	}).css({'cursor': 'pointer'});
	
	
	$("#audio_startseite").jPlayer({
		
		ready: function () {
			this.element.jPlayer("setFile", $global_audioPath+"/"+"_startseite.mp3");
			this.element.jPlayer("play");
			$("p#audio_startseite_aus_an").css({'background-position': 'left -150px'});
		},
		swfPath: $global_swfPath,
	});
	
	
	
	$temp_count = 1;
	$("div.audio").each(function()
	{
		var $status_play = "stop";
		var $audio = $(this);
		var $name_file = $audio.children('p.name_file').text();
		
		$(this).html("");
		
		$(this).append('<div class="jPlayer" id="jPlayer_'+$temp_count+'"></div>');
		$(this).append('<div class="audioplayer_button_start"></div>');
		$(this).append('<div class="audioplayer_button_stop"></div>');
		
		$(this).append('<div class="fortschritt" id="fortschritt_'+$temp_count+'"><div class="fortschritt_laden"></div><div class="fortschritt_anzeige" id="fortschritt_anzeige_'+$temp_count+'"></div></div>');
		
		$("div.audioplayer_button_start").click(function()
		{
			if ($status_play == "play")
			{
				$(this).parent().children("div.jPlayer").jPlayer("pause");
				$(this).attr("class", "audioplayer_button_start");
				
				$status_play = "pause";
			}
			else
			{
				$(this).parent().children("div.jPlayer").jPlayer("play");
				$(this).attr("class", "audioplayer_button_pause");
				
				$status_play = "play";
			}
			$(this).parent().children("div.status").text($status_play);
		});
		
		$("div.audioplayer_button_stop").click(function()
		{
			$(this).parent().children("div.jPlayer").jPlayer("stop");
			$(this).parent().children("div.audioplayer_button_pause").attr("class", "audioplayer_button_start");
			
			$status_play = "stop";
			$(this).parent().children("div.status").text($status_play);
		});
		
		
		$(this).children("div.jPlayer").jPlayer({
			ready: function () {
				this.element.jPlayer("setFile", $global_audioPath+"/"+$name_file);
			},
			swfPath: $global_swfPath,
		})
		.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			if (totalTime > 0)
			{
				this.element.parent().children("div.fortschritt").children("div.fortschritt_laden").css({"width": Math.round(loadPercent)+"%"});
				this.element.parent().children("div.fortschritt").children("div.fortschritt_anzeige").css({"left": Math.round(0.8 * playedPercentAbsolute)+"%"});
			}
		});
		
		
		$temp_count++;
	});
	
	
	// scrollboxen initialisieren
	$("div.scrollbox").prepend('<a class="prevPage browse left"></a>');
	$("div.scrollbox").prepend('<a class="nextPage browse right"></a>');
	
	$("div.scrollbox_container").scrollable({
		items: "scrollbox_content",
		size: 2,
		
	});
 });

function audio_startseite_toggle()
{
	if ($play_status == "play")
	{
		$("p#audio_startseite_aus_an").css({'background-position': 'left top'});
		$play_status = "pause";
		$("#audio_startseite").jPlayer("pause");
		//alert(".. did pause");
	}
	else
	{
		$("p#audio_startseite_aus_an").css({'background-position': 'left -150px'});
		$play_status = "play";
		$("#audio_startseite").jPlayer("play");
		//alert(".. did play");
	}
}


