jQuery(function()
{
	var myurl = document.URL;
	
	initAjax();
	init();
	init_klein();

	
});

function initAjax()
{
	$('a:not(.gallerie)').filter(function()
	{
		return this.hostname && this.hostname === location.hostname;
	}).click(function()
	{
		$(this).attr('href',$(this).attr('href').replace("http://" + this.hostname,""));
		$('a:not(.gallerie)').filter(function() {
			return this.hostname && this.hostname === location.hostname;
		}).removeClass('aktiv');
		$(this).addClass('aktiv');	
		
		

		return false;
	}).each(function(){
		$(this).address();
	});
}

$.address.change(function(event){
	//$.address.value( $(this).attr('href') );
	$('a:not(.gallerie)').filter(function() {
		return this.hostname && this.hostname === location.hostname;
	}).removeClass('aktiv');

	$.ajax({
		type: "POST",
		url: event.value + '?tpl=ajax',
		success: function(msg)
		{
			$('#ajax_replace').html(msg);
			initAjax();
			init();
			init_klein();
			initProgramm();
			
			$('.pp_overlay').remove();
			$('.pp_pic_holder').remove();
			$('.ppt').remove();
			
			
			if( $("#jpId").length > 0)
			{
				var jpPlayTime = $("#jplayer_play_time");
				var jpTotalTime = $("#jplayer_total_time");
				var jpStatus = $("#demo_status"); // For displaying information about jPlayer's status in the demo page

				$("#jpId").jPlayer({
					ready: function () {
						this.element.jPlayer("setFile", "/mahout_cms/project/themes/default/ext/jQuery.jPlayer.1.2.0/LeClub_Feierabend_Clubbing.mp3");
						this.play();
					},
					swfPath: "/mahout_cms/project/themes/default/ext/jQuery.jPlayer.1.2.0",
					nativeSupport: true,
					oggSupport: false,
					preload: 'none'

				}).jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			 		jpPlayTime.text($.jPlayer.convertTime(playedTime));
					jpTotalTime.text($.jPlayer.convertTime(totalTime));
			
					demoStatusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the demo page

				});
				
				$("#pause").hide();

				function showPauseBtn()
				{
					$("#play").fadeOut(function(){
						$("#pause").fadeIn();
					});
				}
			
				function showPlayBtn()
				{
					$("#pause").fadeOut(function(){
						$("#play").fadeIn();
					});
				}
			
				function playTrack(t,n)
				{
					$("#jquery_jplayer").jPlayer("setFile", t).jPlayer("play");
			
					showPauseBtn();
			
					return false;
				}
			
				$("#play").click(function() {
					$("#jquery_jplayer").jPlayer("play");
					showPauseBtn();
					return false;
				});
			
				$("#pause").click(function() {
					$("#jquery_jplayer").jPlayer("pause");
					showPlayBtn();
					return false;
				});
			
				$("#stop").click(function() {
					$("#jquery_jplayer").jPlayer("stop");
					showPlayBtn();
					return false;
				});
			
			
				$("#volume-min").click( function() {
					$('#jquery_jplayer').jPlayer("volume", 0);
					$('#sliderVolume').slider('option', 'value', 0);
					return false;
				});
			
				$("#volume-max").click( function() {
					$('#jquery_jplayer').jPlayer("volume", 100);
					$('#sliderVolume').slider('option', 'value', 100);
					return false;
				});
			
				$("#player_progress_ctrl_bar a").live( "click", function() {
					$("#jquery_jplayer").jPlayer("playHead", this.id.substring(3)*(100.0/global_lp));
					return false;
				});
			
				
			
			
				//hover states on the static widgets
				$('#dialog_link, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); },
					function() { $(this).removeClass('ui-state-hover'); }
				);


			}
			
			$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
		}
	});
});
