$(document).ready(function(){

	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
			$("div.jp-type-single .jp-play").bind('touchstart', function(){
				$(this).addClass("hovered");
			});
    		$(".menu li a").bind('touchend', function(){
        		$(this).removeClass("hovered");
    		});
    }else{
    $('div.jp-type-single .jp-pause, div.jp-type-single .jp-play').hover(
	  function () {
		$(this).addClass("hovered");
	  },
	  function () {
		$(this).removeClass("hovered");
	  }
	);
    }
	/* --- Video --- */
	$("#jquery_jplayer_1").jPlayer({
		ready: function (event) {
			
			$(this).jPlayer("setMedia", {
				poster: "http://www.der-w.de/j2ee/js/jPlayer/SW2_Tourteaser_Preview03b.png",
				m4v: "http://www.der-w.de/media/video/SW2_Tourteaser_metaltix_111017_640x360.m4v"
				//m4v: "http://www.der-w.de/media/video/SW2_Tourteaser_Test_4Sek_640x360.m4v",

				
			});
			
				$(this).jPlayer("play", 0);
		},
		play: function() { // To avoid both jPlayers playing together.
			//$(this).jPlayer("pauseOthers");
			$('#jp_poster_0').css('display','none');
			$('#jp_video_0, #jp_flash_0').width(470).height(265);
			
			
		},
		canplay: function(){
			$(this).jPlayer("play", 0);
			$('#jp_container_1').fadeIn(200,function(){
				
			});
			
		},
		repeat: function(event) { // Override the default jPlayer repeat event handler
			if(event.jPlayer.options.loop) {
				$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
				$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function() {
					$(this).jPlayer("play");
				});
			} else {
				$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
				$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerNext", function() {
					$("#jquery_jplayer_2").jPlayer("play", 0);
				});
			}
		},
		flashreset:  function() {
			alert('flash');		
		},
		ended:  function(event) {
			$('#jp_poster_0').css('display','inline');
			$('#jp_video_0, #jp_flash_0').width(0).height(0);
			$('.jp-video-play').css('display','block');
			console.log('zu ende');		
		},
		swfPath: 'js/jPlayer',
 		solution: 'html, flash',
 		supplied: 'm4v',
 		preload: 'auto',
 		size: {
			width: "470px",
			height: "265px",cssClass: "jp-video-360p"
		},
 		volume: 0.8,
		muted: false
	});

	/* --- Audio --- */
	/*$("#jquery_jplayer_2").jPlayer({
        ready: function () {
          $(this).jPlayer("setMedia", {
            m4a: "http://www.jplayer.org/audio/m4a/Miaow-07-Bubble.m4a",
            oga: "http://www.jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"
          });
        },
        play: function() { // To avoid both jPlayers playing together.
			$(this).jPlayer("pauseOthers");
		},
		repeat: function(event) { // Override the default jPlayer repeat event handler
			if(event.jPlayer.options.loop) {
				$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
				$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function() {
					$(this).jPlayer("play");
				});
			} else {
				$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
				$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerNext", function() {
					$("#jquery_jplayer_1").jPlayer("play", 0);
				});
			}
		},
        swfPath: 'js/jPlayer',
 		solution: 'html, flash',
        supplied: "m4a, oga",
        cssSelectorAncestor: "#jp_container_2"
      });*/
});
