		var obj_controllerTimer = {
					timer: -1,
					delay: 1000,
					visible: true,
					selector: '#ytControl',
					fadeSpeed: 500,
					allowHide: true
				};
		
 // -------------------------------------------------------------------------------------------------------------------
 // URL-Konfiguration
 // -------------------------------------------------------------------------------------------------------------------
       
    var _yt_id =            getParameters("id");   // Zuerst geladene ID
    var _yt_id =            getParameters("hash"); // Zuletzt geladene ID überschreibt
    var _yt_seekto =        getParameters("seekto");
    var _yt_host =          getParameters("host");
    var _yt_titel =         getParameters("title");
    var _yt_width =         getParameters("width");
    var _yt_height =        getParameters("height");
    var _yt_color =         getParameters("color");
    var _yt_disclaimer =    getParameters("disclaimer");
    var _yt_playlist =      getParameters("playlist");
    var _yt_favorites =     getParameters("favorites");
    var _yt_uploads =       getParameters("uploads");
    var _yt_autoplay =      getParameters("autoplay");
    var _yt_fullscreen =    getParameters("fullscreen");
    var _yt_fullscreenOn =  getParameters("fullscreenOn");
    var _yt_state =         getParameters("state");
    var _yt_response =      getParameters("response");
    var _yt_promo =         getParameters("promo");
    var _yt_promo_url =     getParameters("url");
    var _yt_promo_embed =   getParameters("embed");
    var _yt_promo_perma =   getParameters("permalink");
    var _yt_promo_channel = getParameters("channel");
    var _yt_theme =         getParameters("theme");
    var _yt_slider =        getParameters("slider");
    var _yt_hide_controlls = getParameters("hide");
    
 // -------------------------------------------------------------------------------------------------------------------
 // Ableitungen
 // -------------------------------------------------------------------------------------------------------------------
    
    if (_yt_width  == "fullsize") { var _yt_width  = $(window).width();  }
    if (_yt_height == "fullsize") { var _yt_height = $(window).height(); }
    
    var _yt_titel = _yt_titel.replace(/%20/g," ");
    var _yt_titel = _yt_titel.replace(/%3C/g,"<");
    var _yt_titel = _yt_titel.replace(/%3E/g,">");
          
    var _yt_host  = _yt_host.replace(/%20/g," ");
    var _yt_host  = _yt_host.replace(/%3C/g,"<");
    var _yt_host  = _yt_host.replace(/%3E/g,">");
       
 // -------------------------------------------------------------------------------------------------------------------
 // Document Ready
 // -------------------------------------------------------------------------------------------------------------------
    $(document).ready(function()
    {
    	if (parseInt(getParameters("hide")) === 1) {
	    	$('#ytPlayer').bind('mousemove', function() {
	    		var obj_controllbar = $(obj_controllerTimer.selector);
	    		
	    		if (! obj_controllerTimer.visible) {
	    			if (obj_controllerTimer.timer !== -1) {
	    				window.clearTimeout(obj_controllerTimer.timer);
	    			}
	  				
	  				showController(function() {
	  					if (obj_controllerTimer.allowHide && obj_controllerTimer.timer === -1) {
		  					obj_controllerTimer.timer = window.setTimeout(function() {
				      		hideController();
				      	}, obj_controllerTimer.delay);
			      	}
	  				});
	    		}
	    		else if (obj_controllerTimer.visible && obj_controllerTimer.allowHide) {
	    			if (obj_controllerTimer.timer !== -1) {
	    				window.clearTimeout(obj_controllerTimer.timer);
	    			}
	    			
	    			obj_controllerTimer.timer = window.setTimeout(function() {
		      		hideController();
		      	}, obj_controllerTimer.delay);
	    		}
	    	});
    	
    	
	    	$(obj_controllerTimer.selector)
		    	.bind('mouseenter', function() {
		    		obj_controllerTimer.allowHide = false;
		  		})
		  		.bind('mouseleave', function() {
		    		obj_controllerTimer.allowHide = true;
		  		});
  		}
    // -------------------------------------------------------------------------------------------------------------------
    // Konfiguration
    // -------------------------------------------------------------------------------------------------------------------
       
       var _mouseover_path = "Active";
       
    // -------------------------------------------------------------------------------------------------------------------
    // URL-Konfiguration
    // -------------------------------------------------------------------------------------------------------------------
       
       var _yt_id =            getParameters("hash"); // Zuletzt geladene ID überschreibt
       if ((!_yt_id) || (_yt_id == "")) { var _yt_id = getParameters("id"); }
       
       var _yt_host =          getParameters("host");
       var _yt_titel =         getParameters("title");
       var _yt_width =         getParameters("width");
       var _yt_height =        getParameters("height");
       var _yt_color =         getParameters("color");
       var _yt_disclaimer =    getParameters("disclaimer");
       var _yt_uploads =       getParameters("uploads");
       var _yt_favorites =     getParameters("favorites");
       var _yt_playlist =      getParameters("playlist");
       var _yt_autoplay =      getParameters("autoplay");
       var _yt_seekto =        getParameters("seekto");
       var _yt_fullscreen =    getParameters("fullscreen");
       var _yt_fullscreenOn =  getParameters("fullscreenOn");
       var _yt_state =         getParameters("state");
       var _yt_response =      getParameters("response");
       var _yt_promo =         getParameters("promo");
       var _yt_promo_url =     getParameters("url");
       var _yt_promo_embed =   getParameters("embed");
       var _yt_promo_perma =   getParameters("permalink");
       var _yt_promo_channel = getParameters("channel");
       var _yt_theme =         getParameters("theme");
       var _yt_slider =        getParameters("slider");

    // -------------------------------------------------------------------------------------------------------------------
    // Default-Konfiguration lesen
    // -------------------------------------------------------------------------------------------------------------------
       
       var _yt_div =    $("#ytLayer").attr("yt_div");
       var _yt_player = $("#ytLayer").attr("yt_player");
       var _yt_acht =   $("#ytLayer").attr("yt_acht");
       
       if ((!_yt_id)            || (_yt_id            == "")) { var _yt_id            = $("#ytLayer").attr("yt_id");            }
       if ((!_yt_seekto)        || (_yt_seekto        == "")) { var _yt_seekto        = $("#ytLayer").attr("yt_seekto");        }
       if ((!_yt_host)          || (_yt_host          == "")) { var _yt_host          = $("#ytLayer").attr("yt_host");          }
       if ((!_yt_titel)         || (_yt_titel         == "")) { var _yt_titel         = $("#ytLayer").attr("yt_titel");         }
       if ((!_yt_color)         || (_yt_color         == "")) { var _yt_color         = $("#ytLayer").attr("yt_color");         }
       if ((!_yt_width)         || (_yt_width         == "")) { var _yt_width         = $("#ytLayer").attr("yt_width");         }
       if ((!_yt_height)        || (_yt_height        == "")) { var _yt_height        = $("#ytLayer").attr("yt_height");        }
       if ((!_yt_disclaimer)    || (_yt_disclaimer    == "")) { var _yt_disclaimer    = $("#ytLayer").attr("yt_disclaimer");    }
       if ((!_yt_playlist)      || (_yt_playlist      == "")) { var _yt_playlist      = $("#ytLayer").attr("yt_playlist");      }
       if ((!_yt_favorites)     || (_yt_favorites     == "")) { var _yt_favorites     = $("#ytLayer").attr("yt_favorites");     }
       if ((!_yt_uploads)       || (_yt_uploads       == "")) { var _yt_uploads       = $("#ytLayer").attr("yt_uploads");       }
       if ((!_yt_autoplay)      || (_yt_autoplay      == "")) { var _yt_autoplay      = $("#ytLayer").attr("yt_autoplay");      }
       if ((!_yt_fullscreen)    || (_yt_fullscreen    == "")) { var _yt_fullscreen    = $("#ytLayer").attr("yt_fullscreen");    }
       if ((!_yt_fullscreenOn)  || (_yt_fullscreenOn  == "")) { var _yt_fullscreenOn  = $("#ytLayer").attr("yt_fullscreenOn");  }
       if ((!_yt_state)         || (_yt_state         == "")) { var _yt_state         = $("#ytLayer").attr("yt_state");         }
       if ((!_yt_response)      || (_yt_response      == "")) { var _yt_response      = $("#ytLayer").attr("yt_response");      }
       if ((!_yt_promo)         || (_yt_promo         == "")) { var _yt_promo         = $("#ytLayer").attr("yt_promo");         }
       if ((!_yt_promo_url)     || (_yt_promo_url     == "")) { var _yt_promo_url     = $("#ytLayer").attr("yt_promo_url");     }
       if ((!_yt_promo_embed)   || (_yt_promo_embed   == "")) { var _yt_promo_embed   = $("#ytLayer").attr("yt_promo_embed");   }
       if ((!_yt_promo_perma)   || (_yt_promo_perma   == "")) { var _yt_promo_perma   = $("#ytLayer").attr("yt_promo_perma");   }
       if ((!_yt_promo_channel) || (_yt_promo_channel == "")) { var _yt_promo_channel = $("#ytLayer").attr("yt_promo_channel"); }
       if ((!_yt_theme)         || (_yt_theme         == "")) { var _yt_theme         = $("#ytLayer").attr("yt_theme");         }
       if ((!_yt_slider)        || (_yt_slider        == "")) { var _yt_slider        = $("#ytLayer").attr("yt_slider");        }
        

    // -------------------------------------------------------------------------------------------------------------------
    // Browser-Konfiguration lesen
    // -------------------------------------------------------------------------------------------------------------------
       
       if (_yt_width  == "fullsize") { var _yt_width  = $(window).width();  }          
       if (_yt_height == "fullsize") { var _yt_height = $(window).height(); }
       
       
       
    // -------------------------------------------------------------------------------------------------------------------
    // URL Debugging
    // -------------------------------------------------------------------------------------------------------------------
       
       var debug =         "_yt_id:            "+_yt_id; 
       var debug = debug+"\n_yt_seekto:        "+_yt_seekto;
       var debug = debug+"\n_yt_host:          "+_yt_host;
       var debug = debug+"\n_yt_titel:         "+_yt_titel;
       var debug = debug+"\n_yt_width:         "+_yt_width;
       var debug = debug+"\n_yt_height:        "+_yt_height;
       var debug = debug+"\n_yt_color:         "+_yt_color;
       var debug = debug+"\n_yt_div:           "+_yt_div;
       var debug = debug+"\n_yt_player:        "+_yt_player;
       var debug = debug+"\n_yt_acht:          "+_yt_acht;
       var debug = debug+"\n_yt_disclaimer:    "+_yt_disclaimer;
       var debug = debug+"\n_yt_fullscreen:    "+_yt_fullscreen;
       var debug = debug+"\n_yt_fullscreenOn:  "+_yt_fullscreenOn;
       var debug = debug+"\n_yt_playlist:      "+_yt_playlist;
       var debug = debug+"\n_yt_favorites:     "+_yt_favorites;
       var debug = debug+"\n_yt_uploads:       "+_yt_uploads;
       var debug = debug+"\n_yt_autoplay:      "+_yt_autoplay;
       var debug = debug+"\n_yt_state:         "+_yt_state;
       var debug = debug+"\n_yt_response:      "+_yt_response;
       var debug = debug+"\n_yt_promo:         "+_yt_promo;
       var debug = debug+"\n_yt_promo_url:     "+_yt_promo_url;
       var debug = debug+"\n_yt_promo_embed:   "+_yt_promo_embed;
       var debug = debug+"\n_yt_promo_perma:   "+_yt_promo_perma;
       var debug = debug+"\n_yt_promo_channel: "+_yt_promo_channel;
       var debug = debug+"\n_yt_theme:         "+_yt_theme;
       var debug = debug+"\n_yt_slider:        "+_yt_slider;
       
    // alert(debug);
    
    // -------------------------------------------------------------------------------------------------------------------
    // Flash laden
    // -------------------------------------------------------------------------------------------------------------------
 
    // allowScriptAccess must be set to allow the Javascript from one 
    // domain to access the swf on the youtube domain
       var params = { allowScriptAccess: "always", wmode: "transparent", bgcolor: _yt_color };
    
    // this sets the id of the object or embed tag to 'myytplayer'.
    // You then use this id to access the swf and make calls to the player's API
       var atts = { id: _yt_div, wmode: "transparent" };
       
    // Player laden
			if (parseInt(getParameters("hide")) !== 1) {
				swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", _yt_player, _yt_width, (_yt_height - 25), _yt_acht, null, null, params, atts);
			}
			else {
				swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", _yt_player, _yt_width, (_yt_height), _yt_acht, null, null, params, atts);       
			}
       

    // -------------------------------------------------------------------------------------------------------------------
    // Player bei ID-Übergabe starten
    // -------------------------------------------------------------------------------------------------------------------
       
       if ((_yt_id) && (_yt_id != ""))
       {
          window.setTimeout('var _yt_id = getParameters("hash"); if ((!_yt_id) || (_yt_id == "")) { var _yt_id = getParameters("id"); } if ((!_yt_id) || (_yt_id == "")) { var _yt_id = $("#ytLayer").attr("yt_id"); } var _yt_seekto = getParameters("seekto"); if ((!_yt_seekto) || (_yt_seekto == "")) { var _yt_seekto = $("#ytLayer").attr("yt_seekto"); } loadNewVideo(_yt_id, _yt_seekto, ""); var volume = ytCookies("volume", "", ""); setVolume(volume);', 3000);
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Titel aktualisieren?
    // -------------------------------------------------------------------------------------------------------------------
       
       if ((_yt_titel) && (_yt_titel != ""))
       {
          var _yt_titel = _yt_titel.replace(/%20/g," ");
          var _yt_titel = _yt_titel.replace(/%3C/g,"<");
          var _yt_titel = _yt_titel.replace(/%3E/g,">");
          
          var _yt_host = _yt_host.replace(/%20/g," ");
          var _yt_host = _yt_host.replace(/%3C/g,"<");
          var _yt_host = _yt_host.replace(/%3E/g,">");
          
          if ((_yt_host) && (_yt_host != ""))
          {
             var _yt_titel = _yt_host+": "+_yt_titel;
             
             $("#ytLayer").attr("yt_titel",_yt_titel);
             $("#ytLayer").attr("yt_host",_yt_host);
          }
          
          $("#ytHeaderTitleSpan").text(_yt_titel);
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Theme laden?
    // -------------------------------------------------------------------------------------------------------------------
       
       if ((_yt_theme) && (_yt_theme != ""))
       {
          if (_yt_theme == "bosch")
          {
             var src = "http://i2.ytimg.com/i/mXzxiDkECAWHt-d2nViSIg/1.jpg?v=9f037b";
          }
          
          $("#ytHeaderLogo").attr("src", src);
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Fullscreen-Controls anzeigen?
    // -------------------------------------------------------------------------------------------------------------------
       
       if (_yt_fullscreenOn == "1")
       {
          var src = $("#ytControlFullscreenImg").css("display","none");
          var src = $("#ytControlFullscreenOnImg").css("display","inline");
       }
       
       if (_yt_fullscreen == "0")
       {
          $("#ytControlFullscreen").css("display","none");
       }
       else if (_yt_fullscreen == "1")
       {
          $("#ytControlFullscreen").css("display","inline");
       }
       else
       {
          $("#ytControlFullscreen").css("display","none");
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Disclaimer anzeigen?
    // -------------------------------------------------------------------------------------------------------------------
       
       if (_yt_disclaimer == "1")
       {
          $("#ytDisclaimer").css("display","block");
       }
       else
       {
          $("#ytDisclaimer").css("display","none");
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Menü default anzeigen?
    // -------------------------------------------------------------------------------------------------------------------
       
       if (_yt_state != "")
       {
          window.setTimeout('ytPlaylist("on");', _yt_state);
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Channel updaten?
    // -------------------------------------------------------------------------------------------------------------------
       
       if (_yt_promo_channel == "1")
       {
          var channel = "http://youtube.com/user/"+_yt_favorites;
          $(".ytPromoChannel a").attr("href",channel);
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Links anzeigen?
    // -------------------------------------------------------------------------------------------------------------------
       
       if ((_yt_promo_embed   == "1")) { $(".ytPromoEmbed").css("display","block"); }
       if ((_yt_promo_url     == "1")) { $(".ytPromoUrl").css("display","block"); }
       if ((_yt_promo_perma   == "1")) { $(".ytPromoPerma").css("display","block"); }
       if ((_yt_promo_channel == "1")) { $(".ytPromoChannel").css("display","block"); }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Promotion-Fläche anzeigen?
    // -------------------------------------------------------------------------------------------------------------------
       
       if ((_yt_promo) && (_yt_promo != ""))
       {
          var _yt_promo = _yt_promo.replace(/%20/g," ");
          var _yt_promo = _yt_promo.replace(/%3C/g,"<");
          var _yt_promo = _yt_promo.replace(/%3E/g,">");
          var _yt_promo = _yt_promo.replace(/%2F/g,"/");
          var _yt_promo = _yt_promo.replace(/%3A/g,":");
          var _yt_promo = _yt_promo.replace(/%2C/g,",");
          var _yt_promo = _yt_promo.replace(/%23/g,"#");
          var _yt_promo = _yt_promo.replace(/%3D/g,"=");
          var _yt_promo = _yt_promo.replace(/%3F/g,"?");
          
       // IE 7-Workaround: Browser erkennen
          $.each($.browser, function(i, val) 
          {
          // alert("$.browser.version: "+$.browser.version);
                
             if ((i == "msie") && ($.browser.version.substr(0,1) == "7"))
             {
             // alert("ie7"+i+": "+val+", "+$.browser.version);
             // Abstand oben ausgleichen
                $(".ytPromo").css("marginTop","-13px");
             }
          });
             
       // alert(_yt_promo);
          
          $(".ytPromo").empty();
          $(".ytPromo").html(_yt_promo);
          $(".ytPromo").css("display","block");
       }
       else {
       	$(".ytPromo").empty();
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Player resizen
    // -------------------------------------------------------------------------------------------------------------------

       ytResize(_yt_width,_yt_height,_yt_color,_yt_fullscreen);
       
       function ytResize(width,height,color,fullscreen)
       {
          $("#ytLayer").css("width",width+"px");
          $("#ytLayer").css("height",height+"px");          
          $("#ytHeader").css("width",width+"px");
          
          if (parseInt(getParameters("hide")) !== 1) {
	          var ytPlayerHeight = height - 25;
					}
					else {
						var ytPlayerHeight = height;
					}	          
          
          $("#ytapiplayer").css("height",ytPlayerHeight+"px");
          $("#ytPlayer").css("height",ytPlayerHeight+"px");
          $("#ytPlayer").css("width",width+"px");
          $("#ytPlayer").css("background","#"+color);
          
          var ytControlTop = height - 25; // "298px";
          $("#ytControl").css("top",ytControlTop+"px");
          $("#ytControl").css("width",width+"px");
          
          if (fullscreen == "1") { var abstand = 231; var right = 60; }
          else                   { var abstand = 201; var right = 30; }          
          var ytControlSliderFrameWidth = width - abstand;     
          $("#ytControlSliderFrame").css("width",ytControlSliderFrameWidth+"px");          
          $("#ytControlVolumeSliderFrame").css("right",right);
          
          var ytMenuTop = height - 29; // "298px";
          $("#ytMenu").css("top",ytMenuTop+"px");
          $("#ytMenu").css("width",width+"px");
          
          var ytDisclaimerTop = height - (-10); // "335px";
          $("#ytDisclaimer").css("top",ytDisclaimerTop+"px");
          
          var debug =         "width:         "+width;
          var debug = debug+"\nheight:      "+height;
          var debug = debug+"\nytPlayerHeight:      "+ytPlayerHeight;
          var debug = debug+"\nytControlTop:     "+ytControlTop;
          var debug = debug+"\nytControlSliderFrameWidth:      "+ytControlSliderFrameWidth;
          var debug = debug+"\nytMenuTop:        "+ytMenuTop;
          var debug = debug+"\nytDisclaimerTop:     "+ytDisclaimerTop;
       // alert(debug);       
       }
       
    // -------------------------------------------------------------------------------------------------------------------
    // Mouseovers
    // -------------------------------------------------------------------------------------------------------------------
       
       $(".ytControlImg").hover(function()
       {
       // Bildpfad auslesen
          var src = $(this).attr("src");
          
       // Bildpfad um pfadteil ergänzen
          var src = src.replace(".png","");
          var src = src+""+_mouseover_path+".png";
          
       // Neuen Bildpfad einsetzen
          $(this).attr("src",src);
       },
       function()
       {
       // Bildpfad auslesen
          var src = $(this).attr("src");
          
       // pfadteil aus Bildpfad entfernen
          var src = src.replace(_mouseover_path,"");
          
       // Neuen Bildpfad einsetzen
          $(this).attr("src",src);
       });
       
    // -------------------------------------------------------------------------------------------------------------------
    // Slider Seek
    // -------------------------------------------------------------------------------------------------------------------
       
       ytLoadSlider('','','','Seek');
       
       $("#ytControlSliderSeek").mouseup(function()
       {
       // var sliderValue = document.getElementById('ytControlSeekTo').value;
         
          var sliderValue = $(this).slider('option', 'value');
          
          seekTo(sliderValue);
          
          document.getElementById('ytControlSeekTo').value = sliderValue;
          
          $("#playerstate").attr("mousestate","");
       });
       
       $("#ytControlSliderSeek").mousedown(function()
       {
          $("#playerstate").attr("mousestate","over");
       });
       
       $("#ytControlSliderSeek").mouseout(function()
       {
          $("#playerstate").attr("mousestate","");
       });
       
    // -------------------------------------------------------------------------------------------------------------------
    // Slider Volume
    // -------------------------------------------------------------------------------------------------------------------
       
       ytLoadSlider('0','100','0','Volume');
       
       $("#ytControlVolume").hover(function()
       {
       // 
          document.getElementById("ytControlVolumeSliderFrame").style.display = "block";
          $("#mousestatus").attr("value","over");
       },
       function()
       {
       // 
          document.getElementById("ytControlVolumeSliderFrame").style.display = "none";
          $("#mousestatus").attr("value","out");
       });
       
       $("#ytControlVolumeSlider").mouseup(function()
       {
       // var sliderValue = document.getElementById('ytControlSeekTo').value;
         
          var sliderValue = $(this).slider('option', 'value');
          
          ytplayer.setVolume(sliderValue);
          
          ytCookies("volume", sliderValue, "");
          
          $("#mousestatus").attr("value","over");
       });   
       
       $("#ytControlVolumeSlider").mousedown(function()
       {
          $("#mousestatus").attr("value","down");
       });
       
    // -------------------------------------------------------------------------------------------------------------------
    // Playlists laden
    // -------------------------------------------------------------------------------------------------------------------
       
       var debug = "Playlists laden\n\n";
       var _yt_playlistCsv = "";
       
    // Uploads an CSV anhängen
       if ((_yt_uploads) && (_yt_uploads != ""))
       {
          var _yt_playlistCsv = _yt_playlistCsv+""+ytFavorites(_yt_uploads, "uploads");
       
          var debug = debug+"Uploads mit ID:\n"+_yt_playlistCsv+"\n\n";
       }
       
    // Favoriten an CSV anhängen
       if ((_yt_favorites) && (_yt_favorites != ""))
       {
          var _yt_playlistCsv = _yt_playlistCsv+""+ytFavorites(_yt_favorites, "favorites");
       
          var debug = debug+"Favoriten mit ID:\n"+_yt_playlistCsv+"\n\n";
       }
       
    // Playlist an CSV anhängen
       if ((_yt_playlist) && (_yt_playlist != ""))
       {
          var playlistType = _yt_playlist.split(",");
          var playlistType = playlistType[1];
       
       // Playlist-ID oder CSV?
          if ((playlistType) && (_yt_playlist != ""))
          {
             var _yt_playlistCsv = _yt_playlistCsv+""+_yt_playlist;
       
             var debug = debug+"Playlist als CSV:\n"+_yt_playlistCsv+"\n\n";
          }
          else
          {
             var _yt_playlistCsv = _yt_playlistCsv+""+ytFavorites(_yt_playlist, "playlist");
       
             var debug = debug+"Playlist mit ID\n"+_yt_playlistCsv+"\n\n";
          }
       }
       
       var debug = debug+"Playlist CSV:\n"+_yt_playlistCsv;
       
    // Playlist rendern
       if ((_yt_playlistCsv) && (_yt_playlistCsv != ""))
       {
          ytPlaylistItems(_yt_playlistCsv);
       }
       else {
       	$("#ytPlaylist").empty(); 
       }
       
    // alert(debug);
       
    // Document Ready Ende
    });
    
 // ------------------------------------------------
 // http://visualrinse.com/bradley/mm491/reader.html
 // ------------------------------------------------
 
    function ytFavorites(user, method)
    {
       var debug = "";
    
       if (method == "uploads")
       {
          var url = "http://gdata.youtube.com/feeds/base/users/"+user+"/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile";
          var debug = debug+"Uploads-URL:\n"+url+"\n\n";
       }
       else if (method == "playlist")
       {
          var url = "http://gdata.youtube.com/feeds/api/playlists/"+user+"?max-results=50";
          var debug = debug+"Playlist-URL:\n"+url+"\n\n";
       }
       else if ((method == "favorites") || (!method))
       {
          var url = "http://gdata.youtube.com/feeds/base/users/"+user+"/favorites?client=ytapi-youtube-user&v=2";
          var debug = debug+"Favorites-URL:\n"+url+"\n\n";
       }
       
    // Webservice-URL
       if (url)
       {       
       // Use Function Parameter
          var get_Url = 'webservice.php?url='+url;
          
       // Debug
          var debug = debug+"Webservice-URL:\n"+get_Url;
       }
       else
       {
       // Debug
          var debug = debug+"Fehler :(\n\n'"+url+"'";
       }
       
    // alert(debug);
       
    // use jQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
       $.get(get_Url, function(d)
       {
          var debug = "$.get('"+get_Url+"', function('"+d+"');\n\n";
       
       // find each 'item' in the file and parse it
          $(d).find('entry').each(function()
          {
             var debug = debug+"$('"+d+"').find('entry').each(function()\n";
       
          // --------------------------------------------------------------------------------------------
          // RSS-Daten
          // --------------------------------------------------------------------------------------------

          // name the current found item this for this particular loop run
             var $item = $(this);
          // grab the post title
             var title = $item.find('title:eq(0)').text();
          // grab the post's URL
             var link = $item.find('link[rel="alternate"]').attr("href");
          // don't forget the pubdate
             var pubDate = $item.find('published').text();
             
          // ID freistellen
             var id = link.replace("http\:\/\/www\.youtube\.com\/watch\?v\=","");
             var id = id.replace("\&feature\=youtube_gdata","");
             
          // Titel säubern
             var title = title.replace(/%20/g," ");
             var title = title.replace(/%3C/g,"<");
             var title = title.replace(/%3E/g,">");
             var title = title.replace(/,/g,"");
             var title = title.replace(/;/g,"");
             var title = title.replace(/\?/g,"");
             var title = title.replace(/&/g,"");
             var title = title.replace(/#/g,"");
             var title = title.replace(/\//g,"");
             
             var debug = debug+"RSS-Daten freigestellt\n\nid: "+id+"\ntitle: "+title+"\n\n";
 
          // --------------------------------------------------------------------------------------------
          // HTML
          // --------------------------------------------------------------------------------------------

          // Bisherige Playlist aus Attribut lesen
             var previous = $('#ytLayer').attr("yt_favorites"); 
             
             var debug = debug+"Previous: "+previous+"\n";
             
          // User aus Attribut löschen
             if (previous == user) { var previous = ""; }
             
          // now create a var 'html' to store the markup we're using to output the feed to the browser window
             var newHtml = previous+''+id+','+title+';';
             
             var debug = debug+"Neues HTML: "+newHtml+"\n\n";
             
          // --------------------------------------------------------------------------------------------
          // Push
          // --------------------------------------------------------------------------------------------

          // Playlist in Attribut schreiben
             $('#ytLayer').attr("yt_favorites",newHtml);  
          });
       
          var debug = debug+".find abgeschlossen\n\n";
             
          var playlist = $('#ytLayer').attr("yt_favorites");  
          
          if ((playlist) && (playlist != "") && (playlist != user))
          {       
             var debug = debug+"\nplaylist returned: "+playlist+"\n\n";
             
          // return playlist;
             var antwort = ytPlaylistItems(playlist);
             var debug = debug+"\nantwort: "+antwort;
          }      
       });
       
       var antwort = $('#ytLayer').attr("yt_favorites");
 
    // alert(debug);
       
       return antwort;
    };
     
 // ----------------------------------------------------------------------------------------------------------------
 // Playlist rendern
 // ----------------------------------------------------------------------------------------------------------------
 
    function ytPlaylistItems(playlist)
    {
       var playlist = unescape(playlist)
       var debug = "ytPlaylistItems('"+playlist+"');\n\n";
       
    // String in Array
       var playlistArray = playlist.split(";");
       
       var debug = debug+"\n_yt_playlist: - "+playlistArray.length;
       var debug = debug+"\n_yt_playlist: - "+playlistArray[0];
       var debug = debug+"\n_yt_playlist: - "+playlistArray[1];
       var debug = debug+"\n_yt_playlist: - "+playlistArray[2];
       var debug = debug+"\n";
       
    // Liste leeren
       $("#ytPlaylist").empty();
       
    // alert(debug); 
          
       var i = 0;       
       while (i <= playlistArray.length - 2)
       {
          var debug = debug+"while ("+i+" <= "+playlistArray.length+" - 2)\n\n";  
       
       // Unter-Array-String
          var string = playlistArray[i];
          
          var debug = debug+"\n_yt_playlist "+i+" String (Length): "+string+" ("+string.length+")";
       
       // Unter-Array aufsplitten
          var string = string.split(",");
          
       // Variablen auslesen
          var id =    string[0];
          var titel = string[1];
          
          var debug = debug+"\n_yt_playlist "+i+" Id und Titel: "+id+", "+titel;
       
       // Helper: Item rendern
          var template = ytPlaylistTemplate(id,titel);
          
       // Listitem anhängen
          var html = document.getElementById("ytPlaylist").innerHTML;
          
       // Listitem anhängen
          $("#ytPlaylist").html(html+""+template);
          
          var debug = debug+"\n_yt_playlist "+i+" Template: "+template;
          var debug = debug+"\n";
          
       // Für while() hochzählen
          var i = i-(-1);
       }
       
       var debug = debug+"html: "+html+"\n\n";
       
    // alert(debug);
       return html;
    }
       
 // ----------------------------------------------------------------------------------------------------------------
 // Item rendern
 // ----------------------------------------------------------------------------------------------------------------
 
    function ytPlaylistTemplate(id,titel)
    {
       var template =          '<div class="ytPlaylistLinkSpan">';
       var template = template+'  <a class="ytPlaylistLink"';
       var template = template+'     rel="'+id+'"';
       var template = template+'     title="'+titel+'"';
       var template = template+'     href="javascript:void(0)"';
       var template = template+'     onclick="loadNewVideo(\''+id+'\', 0, this.title)">';
       var template = template+'     <img class="ytPlaylistThumbnail"';
       var template = template+'          src="http://i1.ytimg.com/vi/'+id+'/default.jpg" />';
       var template = template+'     '+titel;
       var template = template+'  </a>';
       var template = template+'</div>';
       
    // alert("ytPlaylistTemplate('"+id+"','"+titel+"');\n\n"+template);
    
    // Antwort ausgeben
       return template;
    }

 // -------------------------------------------------------------------------------------------------------------------
 // Fullscreen toggeln
 // -------------------------------------------------------------------------------------------------------------------

    function ytFullscreen(mode)
    { 
       if (mode == "on")
       {
          var fs_id =         getParameters("hash"); // Zuletzt geladene ID überschreibt
          var fs_titel =      getParameters("title");
          var fs_width =      "fullsize";
          var fs_height =     "fullsize";
          var fs_color =      getParameters("color");
          var fs_fullscreen = getParameters("fullscreen");
          var fs_disclaimer = getParameters("disclaimer");
          var fs_playlist =   getParameters("playlist");
          
          if ((!fs_id)     || (fs_id     == "")) { var fs_id =     getParameters("id"); } // Zuerst geladene ID
          if ((!fs_id)     || (fs_id     == "")) { var fs_id =     ""; }
          
          var fs_seekto =     document.getElementById('ytControlSeekTo').value;
          if ((!fs_seekto) || (fs_seekto == "")) { var fs_seekto = getParameters("seekto"); }
          if ((!fs_seekto) || (fs_seekto == "")) { var fs_seekto = ""; }
          
          var laden = "fullscreen.html?fullscreenOn=1&id="+fs_id+"&seekto="+fs_seekto+"&titel="+fs_titel+"&width="+fs_width+"&height="+fs_height+"&color="+fs_color+"&fullscreen="+fs_fullscreen+"&disclaimer="+fs_disclaimer+"&playlist="+fs_playlist+"#"+fs_id+"";
          
       // alert(laden);
          pause();
          
          var ref = ytPopup(laden);
       // alert(ref);
       }
          
       if (mode == "off")
       {
          var fs_fullscreenOn = getParameters("fullscreenOn");
          
          if (fs_fullscreenOn == "1")
          {
             stop();
             
             window.opener = "x"; 
             window.close();
          }
       }
    }
    
 // -------------------------------------------------------------------------------------------------------------------
 // Helper: neues Fenster
 // -------------------------------------------------------------------------------------------------------------------
 
    function ytPopup(url)
    {
       var availWidth =  window.screen.width - 10;
       var availHeight = window.screen.height - 50;
       
       var openOptions = "resizable=no,scrollbars=no,status=0,menubar=0,resizable=0,width="+availWidth+",height="+availHeight+"";
       
       var ref = window.open(url, "FullscreenYtPlayer", openOptions);
                  
       return ref;
    }

 // -------------------------------------------------------------------------------------------------------------------
 // UI
 // -------------------------------------------------------------------------------------------------------------------
 
    function ytState(status) 
    {
       if (status == "off")
       {
       // State-Box verbergen
          document.getElementById('ytStateContainer').style.display='none';
      
       // Buttons tauschen
          ytSwitch('ytStateSwitchOn','ytStateSwitchOff');
       }
       else
       {
       // Default State-Box anzeigen
          document.getElementById('ytStateContainer').style.display='block';
      
       // Buttons tauschen
          ytSwitch('ytStateSwitchOff','ytStateSwitchOn');
       }
          
    // Funktion beenden
       return false;
    }
    
 // -------------------------------------------------------------------------------------------------------------------
 // UI Helper
 // -------------------------------------------------------------------------------------------------------------------
 
    function ytSwitch(an,aus,style) 
    {
       if ((!style) && (style == ""))
       {
          var style = style;
          
       // alert(style);
       }
       else
       {
          var style = "block"; 
       }
       
       if ((an) && (an != ""))
       {
       // Elemente tauschen
          document.getElementById(an).style.display = style; 
       }
       
       if ((aus) && (aus != ""))
       {
       // Elemente tauschen
          document.getElementById(aus).style.display = 'none'; 
       }
          
    // Funktion beenden
       return false;
    }
    
 // -------------------------------------------------------------------------------------------------------------------
 // UI Helper
 // -------------------------------------------------------------------------------------------------------------------
 
    function ytLoadSlider(min,max,value,mode)
    {
       if (mode == "Volume")
       {
          var orientation = "vertical";
          var element = "#ytControlVolumeSlider";
       }
       else
       {
          var orientation = "horizontal";
          var element = "#ytControlSliderSeek";
       }
       
       if ((!min) || (min == "") || (min == "--"))
       {
          var min = "0";
       }
       
       if ((!max) || (max == "") || (max == "--"))
       {
          var max = "0";
       }
       
       if ((!value) || (value == "") || (value == "--"))
       {
          var value = "0";
       }
       
    // alert("ytLoadSlider(min,max,value)\n\nmode: '"+mode+"'\nmin: '"+min+"'\nmax: '"+max+"'\nvalue: '"+value+"'");
       
       $(element).slider({ orientation: orientation, min: min, max: max, value: value, animate: true });
    }
    
 // -------------------------------------------------------------------------------------------------------------------
 // UI Helper
 // -------------------------------------------------------------------------------------------------------------------
 // var value = $(element).slider('option', 'value');
 // ytRefreshSlider(0,100,value,"Volume")
 // -------------------------------------------------------------------------------------------------------------------

    function ytRefreshSlider(min,max,value,mode)
    {
       if (mode == "Volume")
       {
          var element = "#ytControlVolumeSlider";
          var min = "0";
          var max = "100";
       }
       else
       {
          var element = "#ytControlSliderSeek";
       }
       
       if ((min) && (min != ""))
       {
          var min = Math.round(min);
          $(element).slider('option', 'min', min);
       }
       
       if ((max) && (max != ""))
       {
          var max = Math.round(max);
          $(element).slider('option', 'max', max);
       }
       
       if ((value) && (value != ""))
       {
          var value = Math.round(value);
          $(element).slider('option', 'value', value);
       }
       
    // alert("ytRefreshSlider(min,max,value)\n\nmin: '"+min+"'\nmax: '"+max+"'\nvalue: '"+value+"'");
    }
    
 // -------------------------------------------------------------------------------------------------------------------
 // UI Helper
 // -------------------------------------------------------------------------------------------------------------------
 
    function ytPlaylist(state)
    {
       if (state == "on")
       {
          ytSwitch('ytControlPlaylistOff','ytControlPlaylistOn');
          
          var _yt_height = getParameters("height");
          
          if ((!_yt_height) || (_yt_height == "")) { var _yt_height = $("#ytLayer").attr("yt_height"); }

          if (_yt_height == "fullsize")
          { 
             var _yt_height = $(window).height();
          }
       
          var ytMenuTop = _yt_height - 117;
          
          var titel = document.title;
          var titel = titel.split("Samsung");
          if (titel[1])
          {
             var opa = 1;
          }
          else
          {
             var opa = 0.9;
          }
          
          $("#ytHeader").animate({ height: "33px", opacity: opa }, 300);
          $("#ytMenu")  .animate({ height: "92px", opacity: opa, top: ytMenuTop+"px" }, 300);
          
          window.setTimeout('$("#ytPlaylist").css("overflow","auto");', 400);
       }
       else if (state == "off")
       {
          $("#ytPlaylist").css("overflow","hidden");
          
          ytSwitch('ytControlPlaylistOn','ytControlPlaylistOff');
          
          var _yt_height = getParameters("height");
          if ((!_yt_height) || (_yt_height == "")) { var _yt_height = $("#ytLayer").attr("yt_height"); }

          if (_yt_height == "fullsize")
          { 
             var _yt_height = $(window).height();
          }
       
          var ytMenuTop = _yt_height - 25; // "298px"
          
          var titel = document.title;
          var titel = titel.split("Samsung");
          if (titel[1])
          {
             var opa = 1;
          }
          else
          {
             var opa = 0.7;
          }
          
          $("#ytHeader").animate({ height: "0px", opacity: opa }, 300);
          $("#ytMenu")  .animate({ height: "0px", opacity: opa, top: ytMenuTop+"px" }, 300);
       }
    }
 
  function setVideoLink() {      

        $(".ytPromoUrl a").attr("href", getVideoUrl());
  }
  
 // -------------------------------------------------------------------------------------------------------------------
 // SDK: Youtube Javascript API 
 // -------------------------------------------------------------------------------------------------------------------
 
    function updateHTML(elmId, value) 
    {
    // IE-spezifisch: Value für Input-Feld
       if (document.getElementById(elmId).nodeName.toLowerCase() == "input")
       {
          document.getElementById(elmId).value = value;
       }
       else
       {
          document.getElementById(elmId).innerHTML = value;
       }
    }

    function setytplayerState(newState) 
    {
       updateHTML("playerstate", newState);
    }

    function onYouTubePlayerReady(playerId) 
    {
       ytplayer = document.getElementById("myytplayer");
       setInterval(updateytplayerInfo, 200);
       updateytplayerInfo();
       ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
       ytplayer.addEventListener("onError", "onPlayerError");
    }

    function onytplayerStateChange(newState) 
    {
      setytplayerState(newState);
       
      if (parseInt(getParameters("hide")) === 1) {
	      if (newState === 3) {
	      	obj_controllerTimer.allowHide = true;
	      	
	      	if (obj_controllerTimer.timer !== -1) {
	      		window.clearTimeout(obj_controllerTimer.timer);
	      	}
	      	
	      	if (obj_controllerTimer.visible) {
		      	obj_controllerTimer.timer = window.setTimeout(function() {
		      		hideController();
		      	}, obj_controllerTimer.delay);
	      	}
	      }
	      else if (newState === -1 || newState === 0 || newState === 2) {
	      	obj_controllerTimer.allowHide = false;
	      	
					showController(function() {});	
	      }
      }
    }

		function hideController() {
			var obj_controllbar = $(obj_controllerTimer.selector);
			
			if (obj_controllerTimer.allowHide) {
				obj_controllbar.stop(true, true);
				obj_controllerTimer.visible = false;
				
				obj_controllbar.animate({
					top: '+=' + obj_controllbar.outerHeight(true),
					opacity: 0
				}, obj_controllerTimer.fadeSpeed, function() {
				});
			}
		}		
		
		function showController(obj_pCallback) {
			var obj_controllbar = $(obj_controllerTimer.selector);
			
			if (! obj_controllerTimer.visible) {
				obj_controllbar.stop(true, true);
				obj_controllerTimer.visible = true;
				
				obj_controllbar.animate({
					top: '-=' + obj_controllbar.outerHeight(true),
					opacity: 1
				}, obj_controllerTimer.fadeSpeed, function() {		
					obj_pCallback();
				});
			}
		}

    function onPlayerError(errorCode) 
    {
      var obj_errorCodes = {
        '100': 'Sorry,\r\nvideo not found!',
        '101': 'Sorry,\r\nthis video is not available in your country!',  
        '150': 'Sorry,\r\nthis video is not available in your country!'
      };
      
      alert(obj_errorCodes[errorCode.toString()]);
    }

    function timePretty(value)
    {       
       var value = parseInt(value);
          
    // Debugging
       var debug = "timePretty("+value+") { ";
       
    // Minuten ermitteln
       var minutes = value / 60;
       var minutesRound = Math.floor(minutes);
       
    // Debugging
       var debug = debug+"minutes rounded: "+minutesRound+", ";
       
    // Minuten Zweistellig 
       if (minutesRound <= 9)
       {
          var minutesString = minutesRound.toString();
          var minutesString = "0"+minutesString;
       }
       else
       {
          var minutesString = minutesRound;
       }
       
    // Debugging
       var debug = debug+"minutes zweistellig: "+minutesString+", ";
       
    // Übrige Sekunden ermitteln
       var secondsRound = value - (minutesRound * 60);
       var secondsRound = Math.floor(secondsRound);
       
    // Debugging
       var debug = debug+"seconds rounded: "+secondsRound+", ";
       
    // Sekunden Zweistellig
       if (secondsRound <= 9)
       {
          var secondsString = secondsRound.toString();
          var secondsString = "0"+secondsString;
       }
       else
       {
          var secondsString = secondsRound;
       }
       
    // Debugging
       var debug = debug+"seconds zwei: "+secondsString+", ";
       
    // String hübsch zusammensetzen
       var prettyString = minutesString+":"+secondsString;
       
    // Debugging
       var debug = debug+"prettyString: "+prettyString+" }<br />";
       
    // Debugging
    // $("#ytSandbox").prepend(debug);
       
       return prettyString;
    }

    function updateytplayerInfo() 
    {
    // Bug :(
    // var bytesloaded =     getBytesLoaded();
       var bytestotal =      getBytesTotal();
       var videoDuration =   getDuration();
       var videoTime =       getCurrentTime();
       var startbytes =      getStartBytes();
       var volume =          getVolume();
       
       var videoTimePretty = "";
       
    // Bug :(
    // updateHTML("bytesloaded",   bytesloaded);
       updateHTML("bytestotal",    bytestotal);
       updateHTML("videoduration", videoDuration);
       updateHTML("videotime",     videoTime);
       updateHTML("startbytes",    startbytes);
       updateHTML("vol",           volume);  
       updateHTML("ytTime",        timePretty(videoTime)); 
       updateHTML("ytDuration",    timePretty(videoDuration));       
          
       var playerstate = document.getElementById("playerstate").innerHTML;
       var mousestate = $("#playerstate").attr("mousestate");
          
       if ((playerstate == "1") && (mousestate != "over"))
       {
          ytRefreshSlider("0",videoDuration,videoTime,"Seek");
          
       // alert('updateytplayerInfo()\nytRefreshSlider("0","'+videoduration+'","'+videotime+'","Seek");');
       }
    }
    
 // functions for the api calls
    function loadNewVideo(id, startSeconds, titel) 
    {
       if (ytplayer) 
       {
          ytplayer.loadVideoById(id, parseInt(startSeconds));
         
       // Buttons tauschen
       // document.getElementById('ytPlayAn').style.display='none';
       // document.getElementById('ytPlayAus').style.display='inline';
          
          if (titel) 
          {
          // Stringlängen-Attribut für Menü lesen
             var lange = $("#ytHeaderTitleSpan").attr("lange");
             var lange = parseInt(lange);
             
             var host = $("#ytLayer").attr("yt_host");
             
             if ((host) && (host != ""))
             {          
                var titel = host+": "+titel;
             }
             
             $("#ytHeaderTitleSpan").text(constrain(titel,lange,"..."));
          }
          else
          {
          // $("#ytHeaderTitleSpan").text("KMF Social YouTube Player");
          }
          
          $("#ytPlayer").attr("nowplaying",id);
          
          window.location.hash = id;
          
          getVideoLink();
          setVideoLink();
       }
          
    // Funktion beenden
       return false;
    }

    function cueNewVideo(id, startSeconds) 
    {
       if (ytplayer) 
       {
          ytplayer.cueVideoById(id, startSeconds);
       }
    }

    function play() 
    {
       if (ytplayer) 
       {
          ytplayer.playVideo();
      
       // Buttons tauschen
          ytSwitch('ytControlPause','ytControlPlay');
       }
    }

    function pause() 
    {
       if (ytplayer) 
       {
          ytplayer.pauseVideo();
      
       // Buttons tauschen
          ytSwitch('ytControlPlay','ytControlPause');
       }
    }

    function stop() 
    {
       if (ytplayer) 
       {
          ytplayer.stopVideo();
      
       // Buttons tauschen
          ytSwitch('ytControlPlay','ytControlPause');
       }
    }

    function getPlayerState() 
    {
       if (ytplayer) 
       {
          return ytplayer.getPlayerState();
       }
    }

    function seekTo(seconds) 
    {
       if (ytplayer) 
       {
          ytplayer.seekTo(seconds, true);
       }
    }

    function getBytesLoaded() 
    {
       if (ytplayer) 
       {
       // Bug :(
       // return ytplayer.getVideoBytesLoaded();
       }
    }

    function getBytesTotal() 
    {
       if (ytplayer) 
       {
          return ytplayer.getVideoBytesTotal();
       }
    }

    function getCurrentTime() 
    {
       if (ytplayer) 
       {
          return ytplayer.getCurrentTime();
       }
    }

    function getDuration() 
    {
       if (ytplayer) 
       {
          return ytplayer.getDuration();
       }
    }

    function getStartBytes() 
    {
       if (ytplayer) 
       {
          return ytplayer.getVideoStartBytes();
       }
    }

    function newVolume(value)
    {
    // Value to Int
       var value = parseInt(value) + 0;
    
    // Buttons tauschen
       if (value > 0)
       {
       // Debugging     
       // $("#ytSandbox").prepend("if: "+value+","+value1+","+value2+"; ");
         
       // Buttons tauschen
          ytSwitch('ytControlVolumeMute','ytControlVolumeUnmute');
            
       // API aktualisieren
       // ytplayer.unMute();
       }
       else
       {
       // Debugging     
       // $("#ytSandbox").prepend("else: "+value+","+value1+","+value2+"; ");
       
       // Buttons tauschen
          ytSwitch('ytControlVolumeUnmute','ytControlVolumeMute');
             
       // API aktualisieren
       // ytplayer.mute();
       }
             
       if ((ytplayer) && (value) && (value != ""))
       {
       // API aktualisieren
          ytplayer.setVolume(value);
          
       // Input Text aktualisieren
          document.getElementById('vol').value = value;
             
       // Slider aktualisieren
          $("#ytControlVolumeSlider").slider('option', 'value', value);
          
       // Debugging     
       // $("#ytSandbox").prepend("newVolume(value) { value: '"+value+"' }<br />");
       }
          
       return value;
    }

    function mute() 
    {
       if (ytplayer) 
       {
       // Aktuelles Volume lesen
          var volume = $("#vol").attr("value");
          
       // Volume Default einsetzen
          if ((!volume) || (volume == "")) 
          {
             var volume = "0";
          }
          
       // Volume zwischenspeichern
          $("#playerstate").attr("volume",volume);
          
       // API aktualisieren
          ytplayer.setVolume("0");
          
       // Controls aktualisieren
          newVolume("0");
          
       // Debugging          
       // $("#ytSandbox").prepend("mute() { neues volume: '0', gespeichertes volume: '"+volume+"' }<br />");
       }
    }

    function unMute() 
    {
       if (ytplayer) 
       {
          ytplayer.unMute();
          
       // Volume lesen
          var volume = $("#playerstate").attr("volume");
          
       // API aktualisieren
          ytplayer.setVolume(volume);
          
       // Controls aktualisieren
          newVolume(volume);
          
       // Debugging
       // $("#ytSandbox").prepend("unMute() { wiederhergestelltes volume: '"+volume+"' }<br />");
       }
    }
    
    function setVolume(newVolumeValue) 
    {
       if (ytplayer) 
       {
          ytplayer.setVolume(newVolumeValue);
          
          var volumestate = $("#mousestatus").attr("value");
          
          if (volumestate != "down")
          {
             if ($.browser.msie == true)
             {          
                window.newVolume(newVolumeValue);
             }
             else
             {          
                newVolume(newVolumeValue);
             }
          }
          
       // Debugging
       // $("#ytSandbox").prepend("setVolume() { newVolume: "+newVolume+", volumestate: "+volumestate+"' }<br />");
       }
    }

    function getVolume() 
    {
       if (ytplayer) 
       {
          var getVolume = ytplayer.getVolume();
          
       // Volume lesen
          $("#vol").attr("value",getVolume);
          
          var volumestate = $("#mousestatus").attr("value");
          
          if (volumestate != "down")
          {  
             newVolume(getVolume);
          }
          
       // Debugging
       // $("#ytSandbox").prepend("getVolume() { getVolume: "+getVolume+", volumestate: "+volumestate+"' }<br />");
          
          return getVolume;
       }
    }
    
    function getEmbedCode() 
    {
    // var embed = ytplayer.getVideoEmbedCode();
       
       var id = $("#ytPlayer").attr("nowplaying",id);
       
    // var embed = '<iframe src="http://beta.kmf.de/youtube/#'+id+'" width="400" height="323" frameborder="0" scrolling="no"></iframe>';
    // var embed = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/'+id+'?fs=1&amp;hl=de_DE"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+id+'?fs=1&amp;hl=de_DE" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';
       var embed = '<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="323" src="http://www.youtube.com/embed/'+id+'?rel=0" frameborder="0"></iframe>';
       
       alert(embed);
    }

     function getVideoUrl() 
    {
       var url = ytplayer.getVideoUrl();
       
       return url.replace("&feature=player_embedded","");
    }
    
    function getVideoLink() 
    {
    // var url = ytplayer.getVideoUrl();
       
       var id = $("#ytPlayer").attr("nowplaying",id);
       var url = "http://beta.kmf.de/youtube/#"+id;
              
       $("#ytLink").attr("href",url);
    }
    
    function clearVideo() 
    {
       if (ytplayer) 
       {
          ytplayer.clearVideo();
       }
    }

 // ----------------------------------------------------------------------------------------------------------------
 // Helper: String kürzen
 // ----------------------------------------------------------------------------------------------------------------
    
    function constrain(str,n,hellip)
    { 
       if(str.length > n)
       {  
          var s = str.substr(0, n);
          var words = s.split(' '); 
          words[words.length - 1] = '';
          str = words.join(' ') + '' + hellip;
       }
       
       return str;
    }
    
 // --------------------------------------------------------------------------------------------------
 // Helper: URL-Parameter lesen                                                             
 // --------------------------------------------------------------------------------------------------

    function getParameters(name)
    {
       if (name == "hash")
       {
          var hashUrl = window.location.hash;
          var hashUrl = hashUrl.replace("#","");
          return decodeURIComponent(hashUrl);
       }
       else
       {
          name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
          var regexS = "[\\?&]"+name+"=([^&#]*)";
          var regex = new RegExp( regexS );
          var results = regex.exec( window.location.href );
          if( results == null )
          {
            return "";
          }
          else
          {
            return decodeURIComponent(results[1]);
          }
       }
    }

 // -------------------------------------------------------------------------------------------------------------------
 // Helper: Cookies
 // -------------------------------------------------------------------------------------------------------------------
 // ytCookies("volume", "",   "Anfang");
 // ytCookies("volume", "50", "Set");
 // ytCookies("volume", "",   "Get");
 // ytCookies("",       "",   "Nichts");
 // -------------------------------------------------------------------------------------------------------------------
    
    function ytCookies(getset, value, debuggen)
    {
    // 
       if ((getset) && (value))
       {
          $.cookie("ytCookie_"+getset, value, { expires: 365 });
          var antwort = "1";
          var debug = "Cookie '"+getset+"' geschrieben: '"+value+"'";
       }
       
    // 
       else if ((getset) && (!value))
       {
          var antwort = $.cookie("ytCookie_"+getset);
          var debug = "Cookie '"+getset+"' gelesen: '"+antwort+"'";
       }
       
    // 
       else
       {
          var antwort = "0";
          var debug = "Nichts passiert: '"+getset+"', '"+value+"'";
       }
       
    // 
       if (debuggen)
       {
          alert(debuggen+":\n\n"+antwort+":\n\n"+debug);
       }
       
       return antwort;
    }
    
