var player_config;

var flow = {
	player_format : function(player, format) {
		if(player == 'player') {
			d.getElementById(player).style.height = (format == 1) ? '297px' : '400px';
		}
	},
	
  init : function(config) {
    player_config = flow.base64_decode(config).split('|');
    var controls = (player_config[4]) ? player_config[4].split(';') : new Array();

    d.getElementById(player_config[0]).style.backgroundImage = 'url(' + player_config[3] + ')';
		flow.player_format(player_config[0], player_config[1]);
    
    flowplayer(player_config[0],  baseURL + '/_js/flowplayer/flowplayer.swf' , {
    
// COMMERCIAL SETTINGS START
        key: '#$a6153a48350ea92d975', 
        
        contextMenu: [ 
          '*rtn-media Player'
        ],
        
        logo: { 
          url: baseURL + '/images/rtn-media-' + player_config[0] + '.png', 
          top: 10,
          right: 10,
          fullscreenOnly: false, 
          displayTime: 0 
        },
        
        play: {
          replayLabel: '', 
          label: '',
          url: baseURL + '/_js/flowplayer/play_' + player_config[0] + '.png',
          width: (player_config[0] == 'sidebar' ? 50 : 83), 
          height: (player_config[0] == 'sidebar' ? 50 : 83) 
        },
// COMMERCIAL SETTINGS END

        canvas: { 
          backgroundColor:'#FFFFFF', 
          backgroundGradient: 'high' 
        }, 
        
        clip:  { 
          url: baseURL + '/videos/' + player_config[2],
          autoPlay: true, 
          autoBuffering: false,
          debug: false
        },
      
        plugins: { 
            controls: { 
              url: baseURL + '/_js/flowplayer/controls.swf', 
   
            // hide controlbar
              autoHide: 'fullscreen', 
              hideDelay: 2000,
              
            // buttons
              buttonColor: '#f80202',
              buttonOverColor: '#3333cc',
            
            // progress bar
              backgroundColor: '#FFFFFF',
              backgroundGradient: 'none', 
              scrubberHeightRatio: 0.6,
              scrubberBarHeightRatio: 0.8,
              progressGradient:  	'none',
              bufferGradient:  	'none',
              sliderGradient:  	'none',
              progressColor: '#3333ccx',
              bufferColor: '#f80202',
              sliderColor: '#3333cc',
              
            // timer
              volumeSliderGradient: 'none',
              timeBgColor: '#FFFFFF',
              timeColor: '#f80202', 
              durationColor: '#000000',
              
            // volume
              volumeBarHeightRatio: 0.8,
              volumeSliderHeightRatio: 0.6,
              volumeSliderGradient: 'none',
              volumeSliderColor: '#3333cc',
              
            // tooltips
              tooltipColor: '#f80202',
              tooltipTextColor: '#ffffff',
       
            // visible buttons
              play: true, 
              volume: flow.in_array('volume', controls), 
              mute: true, 
              time: flow.in_array('time', controls), 
              stop: flow.in_array('stop', controls), 
              playlist: false, 
              fullscreen: true, 
              scrubber: true
            }
        }
    });
  },
  
  in_array : function(item, arr) {
    for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
    return false;
  },
  
  playVideo : function(config) {
    player_config = flow.base64_decode(config).split('|');
		flow.player_format(player_config[0], player_config[1]);
    $f(player_config[0]).play(player_config[2]);
    window.scrollBy(0,-10000);
  },

  base64_decode: function(data) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

    if(!data) return data;
    data += '';

    do {
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) tmp_arr[ac++] = String.fromCharCode(o1);
        else if (h4 == 64) tmp_arr[ac++] = String.fromCharCode(o1, o2);
        else tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
    } while(i < data.length);

    return tmp_arr.join('');
  }
}