
var ytcontrolstate=0; // State of the Player control: 0: invisible; 1:Play; 2:Pause
var ytplayer;
var firstid;
var params = { allowScriptAccess:'always', wmode:'transparent', bgcolor:'000000' };
var atts = { id: 'myytplayer' };
//swfobject.embedSWF('http://www.youtube.com/apiplayerbeta?enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3', 
//        'ytapiplayer', '425', '319', '8', null, null, params, atts);
//swfobject.embedSWF('http://www.youtube.com/apiplayer?enablejsapi=1&amp;playerapiid=ytplayer', 
//'ytapiplayer', '425', '319', '8', null, null, params, atts);
///
// 04.02.2012 - voller youtube player
//swfobject.embedSWF("http://www.youtube.com/v/kE6oO9dWyZM?enablejsapi=1&playerapiid=ytplayer&version=3",
//                       "ytapiplayer", "425", "319", "8", null, null, params, atts);
// 04.02.2012 - test mit beta und laden eines liedes
//swfobject.embedSWF('http://www.youtube.com/apiplayerbeta&v=kE6oO9dWyZM&enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3', 
//        'ytapiplayer', '425', '319', '8', null, null, params, atts);
// 04.02.2012 - chromless player
//http://www.youtube.com/apiplayer?enablejsapi=1&version=3
swfobject.embedSWF('http://www.youtube.com/apiplayer?enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3', 
        'ytapiplayer', '425', '319', '8', null, null, params, atts);


// Loads the selected video into the player.
function loadVideo(videoID) {  
  if(ytplayer) {
	  // load video
	  ytplayer.loadVideoById(videoID);
  }
}

// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
  alert("An error occured of type:" + errorCode);
}

// This function is automatically called by the player once it loads
function onYouTubePlayerReady(playerId) {
    // Get player instance
    ytplayer = document.getElementById("myytplayer");
    ytplayer.addEventListener("onError", "onPlayerError");
    ytplayer.addEventListener( "onStateChange", "onYtStateChanged" );
    // Load first with the id which was determined before with jquery in jsfils.js
    var vol=ytplayer.getVolume();
    //ytplayer.setVolume(0);
    ytplayer.cueVideoById(firstid);
    //ytplayer.pauseVideo();
    //ytplayer.setVolume(vol);
}

/**
* Reagiert auf das Event, dass sich der Status �ndert.
* �ndert die Anzeige des Play/Pause-Buttons.
* Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5)
*/
function onYtStateChanged( newState ) {
	//alert(newState);    
	switch( newState ) {
		case -1:
			break;
		case 1: // Video Playing
			$("#ytcontrol").css("background-image","url(./themes/mysite/images/negative_small/pausedown.png)");
			$("#ytcontrol").css("display","block");
			ytcontrolstate=0;
			break;
		case 0: // Video ended
			$("#ytcontrol").css("background-image","url(./themes/mysite/images/negative_small/playdown.png)");
			$("#ytcontrol").css("display","block");
			ytcontrolstate=1;
			break;
		case 2: // Video paused
        	$("#ytcontrol").css("background-image","url(./themes/mysite/images/negative_small/playdown.png)");
			$("#ytcontrol").css("display","block");
			//$("#ytcontrol").click( function( e ) {
//				ytplayer.playVideo();
//			} );
	       break;
		case 3: // Video buffering
			$("#ytcontrol").css("display","none");
			ytcontrolstate=0;
	       break;
	    default:
	       //$( "#ytplay" ).attr( "value", "Play" );
	}
}

function controlPlayer(){
	//alert("hier");
	if (ytcontrolstate==0){
		ytcontrolstate=1;
		ytplayer.pauseVideo();
	}else{
		ytcontrolstate=0;
		ytplayer.playVideo();
	}
}

// The "main method" of this sample. Called when someone clicks "Run".
//function loadPlayer() {
//  // The video to load
//  var videoID = "ylLzyHk54Z0"
//  // Lets Flash from another domain call JavaScript
//  var params = { allowScriptAccess: "always" };
//  // The element id of the Flash embed
//  var atts = { id: "ytPlayer" };
//  // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
//  swfobject.embedSWF("http://www.youtube.com/v/" + videoID +
//                     "&enablejsapi=1&playerapiid=player1",
//                     "videoDiv", "480", "295", "8", null, null, params, atts);
//}




