
/**
 * flow.playlist 0.11. Flowplayer playlist script
 * 
 * http://flowplayer.org/tools/flow-playlist.html
 *
 * Copyright (c) 2008 Tero Piirainen (tero@flowplayer.org)
 *
 * Released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * >> Basically you can do anything you want but leave this header as is <<
 *
 * Version: 0.11 - 05/19/2008
 */ 
(function($) {		
	$.fn.extend({
		playlist: function(params, config, opts) { 			
			return this.each(function() {
				new playlist($(this), params, config, opts);
			});
		}		
	});		
			
	function playlist(root, params, config, playlistOpts) {
		var player = null;

		var opts = {
			playingClass: 'playing',
			pausedClass: 'paused',
			player: '#player',
			loop:false
		}
		
		opts = $.extend(opts, playlistOpts); 		
		
		config = config || {};
		if (typeof params == 'string') params = {src:params};
		 
		if (!$(opts.player).length) {
			alert("flow.playlist not configured properly\nnonexisting element " + opts.player);
			return;
		}
		
    
    
		var items = root.children().children();

		items.click(function(event) 
    {	
			if(this.name == "playerFile")
      {
        
        absPosition(this)
        
        //Einblenden falls ausgeblendet
        if(document.getElementById("playerWindow").style.display == 'none')
          document.getElementById("playerWindow").style.display = 'block';
      
        //Angeklicktes Element holen
  			var el = $(this);
  
  			//Abspiel-Status umschalten
  			el.parent().parent().find("." + opts.playingClass).removeClass(opts.playingClass).removeClass(opts.pausedClass);				
  			el.addClass(opts.playingClass);
  			
        //URL holen
  			config.videoFile = el.attr("href");
        
        //Player anwerfen...
  			if (player == null) {
  				player = flashembed($(opts.player)[0], params, {config:config}); 
  			} else {
  				//player.setConfig(config);
          player = flashembed($(opts.player)[0], params, {config:config}); 
  			} 
  	
  			//Clip ist fertig
  			window.onClipDone = function() 
        {
  				el.parent.parent.removeClass(opts.playingClass).removeClass(opts.pausedClass);
  				
  				//Nächsten Eintrag abspielen
  				if (el.next().length)
            el.next().click();
  				//ansonsten Player beenden		
  				else {
  					if (opts.loop) {
  						items.eq(0).click();
  					} else {
  						player.DoStop();
  						player.Seek(0);
  					}
  				}
  				return false;
  			}	  			
  	
  			window.onPause = function() {
  				if (el.hasClass(opts.playingClass)) 
            el.addClass(opts.pausedClass);
  			}
  	    
  			window.onResume = function() {
  				el.removeClass(opts.pausedClass);
  			}
        
    	  //Fenster schließen Event hinzufügen
        document.getElementById('playerCloser').onclick = function()
        {
          if (player != null && player.error != "True")
            player.Pause();
            
          document.getElementById('playerWindow').style.display = 'none';
        };
   			return false;
			}
		});
    
var itemsa = root.children().children().children();

		itemsa.click(function(event) 
    {	
			if(this.name == "playerFile")
      {
        
        absPosition(this)
        
        //Einblenden falls ausgeblendet
        if(document.getElementById("playerWindow").style.display == 'none')
          document.getElementById("playerWindow").style.display = 'block';
      
        //Angeklicktes Element holen
  			var el = $(this);
  
  			//Abspiel-Status umschalten
  			el.parent().parent().find("." + opts.playingClass).removeClass(opts.playingClass).removeClass(opts.pausedClass);				
  			el.addClass(opts.playingClass);
  			
        //URL holen
  			config.videoFile = el.attr("href");
        
        //Player anwerfen...
  			if (player == null) {
  				player = flashembed($(opts.player)[0], params, {config:config}); 
  			} else {
  				//player.setConfig(config);
          player = flashembed($(opts.player)[0], params, {config:config}); 
  			} 
  	
  			//Clip ist fertig
  			window.onClipDone = function() 
        {
  				el.parent.parent.removeClass(opts.playingClass).removeClass(opts.pausedClass);
  				
  				//Nächsten Eintrag abspielen
  				if (el.next().length)
            el.next().click();
  				//ansonsten Player beenden		
  				else {
  					if (opts.loop) {
  						items.eq(0).click();
  					} else {
  						player.DoStop();
  						player.Seek(0);
  					}
  				}
  				return false;
  			}	  			
  	
  			window.onPause = function() {
  				if (el.hasClass(opts.playingClass)) 
            el.addClass(opts.pausedClass);
  			}
  	    
  			window.onResume = function() {
  				el.removeClass(opts.pausedClass);
  			}
        
    	  //Fenster schließen Event hinzufügen
        document.getElementById('playerCloser').onclick = function()
        {
          if (player != null && player.error != "True")
            player.Pause();
            
          document.getElementById('playerWindow').style.display = 'none';
        };
   			return false;
			}
		});
	}
})(jQuery);

  function absPosition(el) 
  {
  
    if(el.parentNode.parentNode.id == "searchresult")
    {
      document.getElementById('playerWindow').style.right = "3em";
      document.getElementById('playerWindow').style.top =  (el.parentNode.offsetTop + 140) + "px";
    }
    else
    {  
      if(el.parentNode.parentNode.id == "vnavcenter")
      {
        document.getElementById('playerWindow').style.right = "3em";
        document.getElementById('playerWindow').style.top =  (el.parentNode.parentNode.offsetTop + 20) + "px";
      }
      else
      {
        if(el.parentNode.parentNode.parentNode.id == "StartseiteGross" || el.parentNode.parentNode.id == "StartseiteGross")
        {
          document.getElementById('playerWindow').style.right = "3em";
          if (el.parentNode.nodeName == "H4")
            document.getElementById('playerWindow').style.top =  (el.parentNode.offsetTop) + "px";
          else
            document.getElementById('playerWindow').style.top =  (el.parentNode.parentNode.offsetTop) + "px";
        }
        else
        {
          document.getElementById('playerWindow').style.top =  (el.offsetTop + 10) + "px";
        }
      }
    } 
  }

