if(300 <= 0 || 320 <= 0){
  document.write('<div id="container_player"><div id="player-wrapper"><div id="companion"></div><div id="player"></div></div></div>');
}else{
    var wrap = '<div id="container_player">';
        wrap += '<div id="player-wrapper">';
          wrap += '<div id="companion"></div>';
          wrap += '<div id="player"></div>';
         wrap += '</div>';
         wrap += '<div id="pcontainer">';
           wrap += '<div class="playlist">';
             wrap += '<div id="container_clips" class="clips low"></div>';
           wrap += '</div>';
         wrap += '</div>';
       wrap += '</div>';
          
  document.write(wrap);
}

  lazy_load_jQuery = function() {
    lazy_load_jQuery.getScript("http://cdn.clipkit.de/lib/js/jquery.js");

    lazy_load_jQuery.tryReady(0);
  }

  lazy_load_jQuery.getScript = function(filename) {
    var fileref = document.createElement('script');
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", filename);
    if (typeof fileref!="undefined"){
        document.getElementsByTagName("head")[0].appendChild(fileref);
    }
  }

  lazy_load_jQuery.tryReady = function(time_elapsed) {
    if (typeof jQuery == "undefined") {
      if (time_elapsed <= 5000) {
        setTimeout("lazy_load_jQuery.tryReady(" + (time_elapsed + 200) + ")", 200);
      }
    } else {
      jQuery.noConflict();
      lazy_load_flowplayer();
    }
  }

  /*
   * Start Loading...
   */
  if (typeof jQuery == "undefined") {

    lazy_load_jQuery();

  } else {
    jQuery(function(){
      lazy_load_flowplayer();
    });
  }
  function lazy_load_flowplayer(){
    if (typeof flowplayer == "undefined") {
      jQuery.ajax({
        url: 'http://cdn.clipkit.de/lib/js/flowplayer.js',
        type: 'GET',
        dataType: 'script',
        cache: true,
        success: function(response) {
          lazy_load_flowplayer_playlist();
        }
      })
    } else {
      lazy_load_flowplayer_playlist();
    }
  }

  function lazy_load_flowplayer_playlist(){
    jQuery.ajax({
      url: 'http://cdn.clipkit.de/lib/js/flowplayer.playlist.js',
      type: 'GET',
      dataType: 'script',
      cache: true,
      success: function(response) {
        load_player_config();
      }
    });
  }


  function lazy_load_flowplayer_nuggad(){

    var config = playlistConfig;
    if(typeof config.user.plugins.nuggad.nuggrid == 'undefined'){
        var nuggrid = encodeURIComponent(top.location.href);
      }else{
        var nuggrid = config.user.plugins.nuggad.nuggrid;
      }
      
    var nuggn = config.user.plugins.nuggad.nuggn;
    var nuggsid = config.user.plugins.nuggad.nuggsid;

    jQuery.ajax({
        url: "http://clipkit.nuggad.net/rc?nuggn="+nuggn+"&nuggsid="+nuggsid+"&nuggrid=" + nuggrid,
        type: 'GET',
        dataType: 'script',
        cache: false,
        success: function(response) {
          if(typeof n_pbt != 'undefined'){
            playlistConfig.user.plugins.liverail.LR_TAGS  += ',' + (n_pbt.replace(';',',').replace(';',''));
          }
          init_player();
        },
        error: function(){
          init_player();
        }
      });
    
  }

  var playlistConfig;

  function load_player_config() {
    jQuery.ajax({
      type: 'GET',
      url: 'http://signin.clipkit.de/202/player/187/playlist/443/config.json',
      dataType: 'jsonp',
      success: function(response) {
        playlistConfig = response;
        if(typeof response.user.plugins.nuggad != 'undefined' && response.user.plugins.liverail != 'undefined'){
            lazy_load_flowplayer_nuggad();
        }else{
             init_player();  
        }

        init_css();
       }
    });
  }

  function init_css(){
    jQuery("head").append('<link rel="stylesheet" href="http://cdn.clipkit.de/202/playlist/template/playlist.css" type="text/css" />');
  }


  function init_player() {
    var config = playlistConfig;

    jQuery('#player').css({
      'width': config.player.css.width + 'px',
      'height': config.player.css.height + 'px'
    });
    jQuery('#player-wrapper').css({
      'width': config.player.css.width + 'px',
      'height': config.player.css.height + 'px'
    });
    jQuery('#container_player').css({
      'width': config.player.css.width + 'px',
      'height': config.player.css.height + 'px'
    });
    var actualTime = new Date();

    var playerParams = {
      width: config.player.css.width + 'px',
      height: config.player.css.height + 'px',
      logo: config.player.logo,
      clip: config.clip,
      canvas: config.player.canvas,
      playlist: config.playlist+'?'+actualTime.getTime(),
      plugins: {
        controls: config.player.plugins.controls
      },
      onLoad: function() {
            jQuery("#pcontainer").css({
                visibility:'visible'
            });
            var playlistHeight = 320;

            var playlistElementHeight = 50;
            var upDownButtonHeight = 16;
            
            var elemCount = parseInt((playlistHeight-2*upDownButtonHeight) / playlistElementHeight);


        var playlistObj = this.getPlaylist();

        var splashScreen = "http://cdn.clipkit.de/567/video/57279/thumbnails/previous.png?phash=0f3dc891f107291cd496153ecea16220";

        if(splashScreen != playlistObj[0].url)
        {
          var newClip = {
            scaling: 'fit',
            url: splashScreen,
            title: 'Preview'
          };

          this.addClip(newClip,0);

          this.play(0);

          if(this.getCommonClip().autoMute == true){
              this.mute();
          }else{
              this.unmute();
          }
         }
      }

    };
    if(config.player.autoMute != 'undefined'){
        if(playerParams.clip.autoMute == 'undefined'){
            playerParams.clip.autoMute = config.player.autoMute;
        }
        playerParams.clip.autoMute = playerParams.clip.autoMute || config.player.autoMute;
    }
    if(typeof config.user.plugins.liverail != "undefined" && typeof config.user.plugins.liverail.LR_PUBLISHER_ID != "undefined"){
      playerParams.plugins.liverail = config.user.plugins.liverail;
      if(typeof config.clip.clipkitPlaylistId != "undefined"){
        playerParams.plugins.liverail.LR_VIDEO_AMID = config.clip.clipkitPlaylistId;
      }
    }

    if(typeof config.user.plugins.secure_stream != 'undefined'){
        playerParams.plugins.secure_stream = config.user.plugins.secure_stream;
    }


    flowplayer('player', {src: 'http://cdn.clipkit.de/lib/swf/v-3.2.5/clipkitplayer.swf', wmode: 'opaque' }, playerParams);
    


    if(300 > 0 || 320 > 0){

      if(parseInt(config.player.css.height) > parseInt(320))
      {
        var playlistheight = parseInt(config.player.css.height);
      }
      else
      {
        var playlistheight = parseInt(320);
      }

      if('right' == 'left'){
        jQuery('#container_player').css({
          'width': config.player.css.width + 'px',
          'height': playlistheight + 'px'
        });
        jQuery('#pcontainer').css({
          'width': 300 + 'px',
          'height':320 - 2 + 'px',
          'left': 0,
          'top': 0
        });
        jQuery('#player-wrapper').css({
          'width': config.player.css.width + 'px',
          'height': config.player.css.height + 'px',
          'left': 300 + 'px',
          'top': 0
        });
      }else if('right' == 'right'){
        jQuery('#container_player').css({
          'height': playlistheight + 'px'
        });
        jQuery('#pcontainer').css({
          'width': 300 + 'px',
          'height':320 - 2 + 'px',
          'left': config.player.css.width + 'px',
          'top': 0
        });
        jQuery('#player-wrapper').css({
          'width': config.player.css.width + 'px',
          'height': config.player.css.height + 'px',
          'left': 0,
          'top': 0
        });
      }else if('right' == 'top'){
        jQuery('#container_player').css({
          'height': (parseInt(config.player.css.height) + parseInt(320)) + 'px'
        });
        jQuery('#pcontainer').css({
          'width': 300 + 'px',
          'height':320 - 2 + 'px',
          'left': 0,
          'top': 0
        });
        jQuery('#player-wrapper').css({
          'width': config.player.css.width + 'px',
          'height': config.player.css.height + 'px',
          'left': 0,
          'top': 320 + 'px'
        });
      }else{// if('right' == 'bottom'){
        jQuery('#container_player').css({
          'height': (parseInt(config.player.css.height) + parseInt(320)) + 'px'
        });
        jQuery('#pcontainer').css({
          'width': 300 + 'px',
          'height':320 - 2 + 'px',
          'left': 0,
          'top': config.player.css.height + 'px'
        });
        jQuery('#player-wrapper').css({
          'width': config.player.css.width + 'px',
          'height': config.player.css.height + 'px',
          'left': 0,
          'top': 0
        });
      }

      jQuery('div.playlist').css({
        'height': 320 + 'px',
        'width': 300  + 'px',
        'overflow': 'auto'
      });

      flowplayer('player').playlist("div.clips", {
          preview: 1,
          loop: true,
          template: '<a href="${url}" class="first ${clipkit:className}" title="Clip abspielen / anhalten"><img src="${clipkit:imagePath}"><span><b>${title}</b><br />${clipkit:vdescription}</span><br /></a>'});

	  if(typeof config.user.clickThruTracker != "undefined"){

	    	var trackerCode = '<object width="1" height="1">';
	    	trackerCode += '<param name="movie" value="http://cdn.clipkit.de/lib/swf/clipkit.third-party-ad-tracker.swf"></param>';
	    	trackerCode += '<param name="allowFullScreen" value="true"></param>';
	    	trackerCode += '<param name="allowscriptaccess" value="always"></param>';
	    	trackerCode += '<param name="flashvars" value="pc=' + config.user.clickThruTracker + '&publisher=' + config.user.website + '&lr_publisher=' + config.user.plugins.liverail.LR_PUBLISHER_ID + '"></param>';
	    	trackerCode += '<embed src="http://cdn.clipkit.de/lib/swf/clipkit.third-party-ad-tracker.swf" flashvars="pc=' + config.user.clickThruTracker + '&publisher=' + config.user.website + '&lr_publisher=' + config.user.plugins.liverail.LR_PUBLISHER_ID + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="1" height="1"></embed>';
	    	trackerCode += '</object>';


	    	jQuery('#container_player').append( trackerCode );
	   }
    }
  }

