/*
Rest of the Configuration is set in flvplayer.swf
    protocols : rtmp, rtmpt
    url :	/Streaming, /main, /video
    bitrates : 150,400,800
    bitratekeys : low,mid,high
*/
var BB_FLASH_SERVER = '194.60.217.142:80';

var bbPlayers = {};

/**
 * Inserts an FlashVideoPlayer
 * @param String containerName id of the div for the player
 * @param int id id of the video
 * @param int width original width of the video
 * @param int height original height of the video
 * @param String color color for the player controls ex. -> 'FFCC00'
 * @param String movieName optional name of the movie
 * @return void
 **/
function openPlayer(containerName, id, width, height, color, movieName){
  //Inserts MovieName, optional
  if (movieName) {
    var movieNameDiv = document.getElementById('movie_name');
    if(movieNameDiv !== null) {
      movieNameDiv.innerHTML = movieName;
    }
  }
  
  //is Div for player available?
  var div = document.getElementById(containerName);
  if(div === null) {
    return;
  }
  
  //Is link for player vailable?
  var link = document.getElementById(containerName + '_movie_' + id);
  if(link === null) {
    return;
  }
  //Is color set?
  if (color === null) {
    color = 'FFCC00';
  }
    
  //Set all links to italic
  var links = div.getElementsByTagName('a');
  if(links !== null){
    for(var i = 0; i < links.length; i++){
      if(links[i].id !== null && links[i].id.indexOf(containerName) === 0){
        links[i].style.fontStyle = 'normal'; 
      }
    }
  }
  link.style.fontStyle = 'italic';
  //Insert Movie text
  var p = document.getElementById(containerName + '_player_text');
  if(p !== null){
    var t = document.getElementById(containerName + '_movie_text_' + id);
      if(t !== null) {
        p.innerHTML = t.innerHTML;
      }
      else {
        p.innerHTML = '&nbsp;';
      }			
    }
  //Calculate Size for Player
  var w = 340;
  var h = 255;
  if(width > 0 && height > 0){
     h = w / width * height;
  }
  //Create player
  bbPlayers[containerName] = {'movieid' : id, 'displaystate' : 'normal'};
    
  var player = new SWFObject('../images/flvplayer.swf', containerName + '_flashplayer', w, h, '9');
    
  player.addParam('allowfullscreen','true');
  player.addParam("allowScriptAccess", "always");
  player.addParam('allownetworking', 'all');  

  player.addVariable('autostart','true');	
  player.addVariable('server',BB_FLASH_SERVER);
  player.addVariable('id',id);
  player.addVariable('color',color);
    
  player.write(containerName + '_player');
}