// JavaScript Document

$.fn.image = function(src, f){
    return this.each(function(){
      $("<img />").appendTo(this).each(function(){
         this.src = src;
         this.onload = f;
      });
    });
}

$(document).ready(function(){
	$(".printlink").click(function(){
		var target = $(this).attr("href");
		var myWindow = window.open(target, "Druckversion", "width=600, height=400, scrollbars=yes");
			
		return false;							   
	});
	
	
	/* Player */
	var playerWindow = false;	
	
	function open_mp3_player() {
		if (!playerWindow){
			playerWindow = window.open("", "Player", "width=418, height=100,scrollbars=no");
			
			if (playerWindow.closed || (!playerWindow.document.URL) || (playerWindow.document.URL.indexOf("about") == 0)){
				playerWindow.location = "/fileadmin/template/jplayer.html";	
			}
			
			playerWindow.moveTo(0, 0);
			playerWindow.blur();
			playerWindow.minimize();
			if(playerWindow.focus){
				window.focus();	
			}
		}
	}
	
	//$("#player-controls").html('<div id="player-open"><span>&Ouml;ffnen</span></div><div id="player-pause"><span>Pause</span></div><div id="player-play"><span>Play</span></div><div id="player-stop"><span>Stop</span></div><div id="player-unmute"><span>Sound an</span></div><div id="player-mute"><span>Sound aus</span></div><div id="player-close"><span>Schlie&szlig;en</span></div><a href="#" style="display:none;" id="player-open-link">Open</a><div class="clear-left"></div>');
	
	function fireEvent(obj,evt){
		var fireOnThis = obj;
		if( document.createEvent ) {
			var evObj = document.createEvent('MouseEvents');
			evObj.initEvent( evt, true, false );
			fireOnThis.dispatchEvent(evObj);
		} else if( document.createEventObject ) {
			fireOnThis.fireEvent('on'+evt);
		}
	}
	
	/* Open Player */
	$("#player-open-link").click(function(){
		open_mp3_player();
		
		return false;
	});
	
	//document.getElementById("player-open-link").click();
    /*if ($.browser.safari || $.browser.opera)
    {
        playerWindow = window.open("/fileadmin/template/jplayer.html", "Player", "width=418, height=100,scrollbars=no");  
	} else {
        fireEvent(document.getElementById("player-open-link"),'click');
	}*/
    $("#player-open").hide();
	$("#player-open").click(function(){
		open_mp3_player();
	});
	$("#player-close").hide();
	$("#player-close").click(function(){
		$("#player-pause").hide();
		$("#player-play").show();
		playerWindow.close();
		playerWindow = '';
	});
	/* Pause / Play */
	$("#player-pause").click(function(){
		if (playerWindow) {
			playerWindow.external_pause();
		}
		$(this).hide();
		$("#player-play").show();
	});
	$("#player-play").hide();
	$("#player-play").click(function(){
		if (playerWindow) {
			playerWindow.external_play();
		}
		$(this).hide();
		$("#player-pause").show();
	});
	/* Stop */
	$("#player-stop").hide();
	$("#player-stop").click(function(){
		if (playerWindow) {
			playerWindow.external_stop();
		}
	});
	/* Sound on / off */
	$("#player-unmute").hide();
	$("#player-unmute").click(function(){
		if (playerWindow) {
			playerWindow.external_unmute();	
		}
		$(this).hide();
		$("#player-mute").show();
	});
	$("#player-mute").hide();
	$("#player-mute").click(function(){
		if (playerWindow) {
			playerWindow.external_mute();
		}
		$(this).hide();
		$("#player-unmute").show();
	});
});