$(document).ready(function(){
	/*Fancy Boxes*/
	$("area,a.newsletter").fancybox(); 
	$("area,a.impressum_frame").fancybox(); 
	$("area,a.presse_frame").fancybox(); 
	$("a.fancylink").fancybox();
	
	$("div.roundcorner").corner(); 
	$("p.roundcorner").corner(); 
	$("a.mailaddress").click(function(){
		var a= "blub";
		a = this.href;
		this.href = a.replace(/\[at\]/g,"@");
	});
	/*Tag Cloud*/

	$('div.content div#tagShpere').tagSphere({
		//height of sphere container
		height: 500,
		//width of sphere container
		width: 500,
		//radius of sphere
		radius: 200,
		//rotation speed
		speed: 1.5,
		//sphere rotations slower
		slower: 0.9,
		//delay between update position
		timer: 5,
		//dependence of a font size on axis Z
		fontMultiplier: 30,
		//tag css stylies on mouse over
		tagCSSOver: {
			border: 'none',
			color: 'blue',
			fontMultiplier: '45'
		},
		//tag css stylies on mouse out
		tagCSSOut: {
			border: '',
			color: ''
		}		
	});
	
	$('div.content div.dockmenu').jqDock({
			align: 'top',
			size: 100,
			distance: 48,
			coefficient: 1,
			labels: true,
			duration: 1000
	});


	$('a.cloudelem').click(function() {
		var obj = document.getElementById("tagShpere");
		if(obj != null) obj.style.visibility = 'hidden';
		return true;
	});

	$('a.cloudelem').fancybox({
		frameWidth: 400,
//		frameHeight: 400,
		callbackOnClose: function(){
			var obj = document.getElementById("tagShpere");
			if(obj != null) obj.style.visibility = '';
			return true;
		}
	});


	$('.ad-gallery').adGallery({
		display_back_and_forward: true,
		display_back_and_forward: true, // Are you allowed to scroll the thumb list?
		slideshow: {
		stop_on_scroll: true,
		enable: true,
		autostart: true,
		speed: 3000,
		start_label: 'Start',
		stop_label: 'Stop'
		}

	});
	//Tabs
	$('#container-1 div.dummy > ul').tabs();
	//Banner 
	$('.slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: 5000
	});
	$('div.linkslideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: 2000,
		next:   '#nextlink',
		prev:   '#prevlink'

	});

	//hover states on the static widgets
	$('div.ui-widget').hover(
/*		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }*/
	);
	
	
	
	
	/*Media Player*/
	
	var global_lp = 0;/*Global Load Percent*/
	var playItem = 0;

	var myPlayList = [
		{name:"Me and Mr. Black - live@Sonnenberg", mp3:"media/Sonnenberg/The Herd - Gig Sonnenberg Live - 7 - Me and Mr. Black.mp3", txt:"phpgeruest.php5?name=media/meandmrblack.html"},
		{name:"Baby Maybe - live@Sonnenberg", mp3:"media/Sonnenberg/The Herd - Gig Sonnenberg Live - 13 -Baby Maybe.mp3", txt:"phpgeruest.php5?name=media/babymaybe.html"},
		{name:"Radio Rheinwelle 2010 Teil 1", mp3:"media/Woody__Tommi-RadioBestOfSnippetsTeilI.mp3", txt:"phpgeruest.php5?name=media/Radio_Rheinwelle_2010_1.html"},
		{name:"Radio Rheinwelle 2010 Teil 2", mp3:"media/Woody__Tommi-RadioBestOfSnippetsTeilII.mp3", txt:"phpgeruest.php5?name=media/Radio_Rheinwelle_2010_1.html"},
		{name:"All In",mp3:"media/allin.mp3",txt:"phpgeruest.php5?name=media/allin.html"},
		{name:"Love Kills Brain Cells",mp3:"media/lovekillsbraincells.mp3",txt:"phpgeruest.php5?name=media/lovekillsbraincells.html"},
		{name:"Sideways",mp3:"media/sideways.mp3",txt:"phpgeruest.php5?name=media/sideways.html"},
		{name:"Someday",mp3:"media/someday.mp3",txt:"phpgeruest.php5?name=media/someday.html"},
		{name:"Sunset Road",mp3:"media/sunsetroad.mp3",txt:"phpgeruest.php5?name=media/sunsetroad.html"},
		{name:"When The Beat Begins",mp3:"media/whenthebeatbegins.mp3",txt:"phpgeruest.php5?name=media/whenthebeatbegins.html"},
		{name:"Radio Bob mit The Fake (Jan. 2010) ",mp3:"media/RadioBob_Herd_Fake_Talk.mp3",txt:"phpgeruest.php5?name=media/radio_bob_interview.html"},
		{name:"Radio Bob Lightning Crashes - unplugged (Jan. 2010)",mp3:"media/RadioBob_LightningCrashes.mp3",txt:"phpgeruest.php5?name=media/radio_bob_song.html"},
		{name:"Baby Maybe (akustisch)",mp3:"media/Sep09/BabyMaybe_Akustik-richtig.mp3",txt:"phpgeruest.php5?name=media/babymaybe.html"},
		{name:"All In (akustisch)",mp3:"media/Sep09/AllIn_Moll_Akustik-richtig.mp3",txt:"phpgeruest.php5?name=media/allin.html"}
		/*{name:"Radio Rheinwelle Teil 1",mp3:"media/Radio_Rheinwelle_1.mp3",txt:"phpgeruest.php5?name=media/RRW1.html"},
		{name:"Radio Rheinwelle Teil 2",mp3:"media/Radio_Rheinwelle_2.mp3",txt:"phpgeruest.php5?name=media/RRW1.html"},
		{name:"Radio Rheinwelle Teil 3",mp3:"media/Radio_Rheinwelle_3.mp3",txt:"phpgeruest.php5?name=media/RRW1.html"},
		{name:"Radio Rheinwelle Teil 4",mp3:"media/Radio_Rheinwelle_4.mp3",txt:"phpgeruest.php5?name=media/RRW1.html"},
		{name:"Radio Rheinwelle Teil 5",mp3:"media/Radio_Rheinwelle_5.mp3",txt:"phpgeruest.php5?name=media/RRW1.html"},
		{name:"Radio Rheinwelle Teil 6",mp3:"media/Radio_Rheinwelle_6.mp3",txt:"phpgeruest.php5?name=media/RRW1.html"}*/
	];
	
	if($("#jquery_jplayer").length) {
		$("#jquery_jplayer").jPlayer({
			swfPath: "lib/js/",
			ready: function ()
			{
				displayPlayList();
				playListInit(true); // Parameter is a boolean for autoplay.
				showPauseBtn();
				/*Erstelle für jedes Txt-File eine Fancybox mit eigener ID*/
				for (i=0; i < myPlayList.length; i++) {	$("area,a.lyrics"+i).fancybox({frameWidth: 600, frameHeight: 750}); }

			}
		})
		.jPlayerId("play", "player_play")
		.jPlayerId("pause", "player_pause")
		.jPlayerId("stop", "player_stop")
		.jPlayerId("loadBar", "player_progress_load_bar")
		.jPlayerId("playBar", "player_progress_play_bar")
		.jPlayerId("volumeMin", "player_volume_min")
		.jPlayerId("volumeMax", "player_volume_max")
		.jPlayerId("volumeBar", "player_volume_bar")
		.jPlayerId("volumeBarValue", "player_volume_bar_value")
		.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			var lpInt = parseInt(loadPercent);
			var ppaInt = parseInt(playedPercentAbsolute);
			global_lp = lpInt;

			$('#loaderBar').progressbar('option', 'value', lpInt);
			$('#sliderPlayback').slider('option', 'value', ppaInt);

			var myPlayedTime = new Date(playedTime);
			var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
			var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
			$("#play_time").text(ptMin+":"+ptSec);

			var myTotalTime = new Date(totalTime);
			var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
			var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
			$("#total_time").text(ttMin+":"+ttSec);
		})
		.onSoundComplete( function() {
			playListNext();
		});
	}

	$("#pause").hide();

	function showPauseBtn()
	{
		$("#play").fadeOut(function(){
			$("#pause").fadeIn();
		});
	}

	function showPlayBtn()
	{
		$("#pause").fadeOut(function(){
			$("#play").fadeIn();
		});
	}

	function playTrack(t,n)
	{
		$("#jquery_jplayer").setFile(t).play();

		showPauseBtn();

		return false;
	}

	
	/*Control Buttons*/
	$("#play").click(function() {
		$("#jquery_jplayer").play();
		showPauseBtn();
		return false;
	});

	$("#pause").click(function() {
		$("#jquery_jplayer").pause();
		showPlayBtn();
		return false;
	});

	$("#stop").click(function() {
		$("#jquery_jplayer").stop();
		showPlayBtn();
		return false;
	});
	
	$("#ctrl_prev").click( function() {
		playListPrev();
		return false;
	});

	$("#ctrl_next").click( function() {
		playListNext();
		return false;
	});


	$("#volume-min").click( function() {
		$('#jquery_jplayer').volume(0);
		$('#sliderVolume').slider('option', 'value', 0);
		return false;
	});

	$("#volume-max").click( function() {
		$('#jquery_jplayer').volume(100);
		$('#sliderVolume').slider('option', 'value', 100);
		return false;
	});

	/*Progress Bar*/
	$("#player_progress_ctrl_bar a").live( "click", function() {
		$("#jquery_jplayer").playHead(this.id.substring(3)*(100.0/global_lp));
		return false;
	});

	// Slider
	$('#sliderPlayback').slider({
		max: 100,
		range: 'min',
		animate: true,

		slide: function(event, ui)
   	{
   		$("#jquery_jplayer").playHead(ui.value*(100.0/global_lp));
   	}
	});

	$('#sliderVolume').slider({
		value : 50,
		max: 100,
		range: 'min',
		animate: true,

		slide: function(event, ui)
   	{
   		$("#jquery_jplayer").volume(ui.value);
   	}
	});

	$('#loaderBar').progressbar();


	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

	/*Playlist*/
	/*
	function displayPlayList() {
		for (i=0; i < myPlayList.length; i++) {
			$("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
			$("#playlist_item_"+i).data( "index", i ).hover(
				function() {
					if (playItem != $(this).data("index")) {
						$(this).addClass("playlist_hover");
					}
				},
				function() {
					$(this).removeClass("playlist_hover");
				}
			).click( function() {
				var index = $(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					$("#jquery_jplayer").play();
				}
			});
		}
	}
*/
	function displayPlayList() {
		$("#playlist_list ul").append("<li id='playlist_item_head' />");
		for (i=0; i < myPlayList.length; i++) {
			$currline="<li id='playlist_item_"+i+"'>"+ myPlayList[i].name;
			$currline+="<a class='iframe lyrics"+i+"' href='"+ myPlayList[i].txt +"' > txt </a>";
			$currline+="</li>";
			$("#playlist_list ul").append($currline);
			$("#playlist_item_"+i).data( "index", i ).hover(
				function() {
					if (playItem != $(this).data("index")) {
						$(this).addClass("playlist_hover");
					}
				},
				function() {
					$(this).removeClass("playlist_hover");
				}
			).click( function() {
				var index = $(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					$("#jquery_jplayer").play();
				}
			});
		}
		$("#playlist_list ul").append("<li id='playlist_item_tail' />");

	}
	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		$("#playlist_item_"+playItem).removeClass("playlist_current");
		$("#playlist_item_"+index).addClass("playlist_current");
		playItem = index;
		$("#jquery_jplayer").setFile(myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		$("#jquery_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 );
	}




});


