var globalVideoId = Math.round(Math.random() * 2345);

function DefaultFlashObject()
{
   this.width_object =           1;
   this.height_object =          1;
   this.wmode =                  '';
   this.flash_vars =             '';
   this.bgcolor =                '#000000';
   this.color =                  '#FFFFFF';
   this.movie =                  '';
   
   this.mini_file =              '/_d/wideo/flash/player_mini_16x9_002.swf'; //srodtekst - 2008-09-05
   this.midi_file =              '/_d/wideo/flash/player_news_16x9_004.swf'; //news - 2009-02-12
   this.ad_file =                (typeof(adplayer_news) == 'undefined') ? '' : adplayer_news;
   this.adsmall_file =           '/_d/wideo/flash/player_prawy_samsung_2.swf'; //prawy ad - 2008-11-25
   this.small_file =             '/_d/wideo/flash/player_prawy_16x9_001.swf'; // prawy - 2008-09-05
   this.fakty_file =             '/_d/wideo/flash/player_fakty_16x9_002.swf';
   this.full_file =              this.midi_file;
   this.big_file =               '/_d/wideo/flash/player_big_16x9_006.swf'; //wideo - 2009-02-12

   this.audio_file =              '/_d/wideo/flash/psound_001.swf';
   this.add_file =               '/_d/wideo/flash/nowy_wpis_007.swf';
   
   this.sport_file =             '/_d/tabele/tab_sport_006.swf';
   this.wig20_file =             '/_d/biz/line.swf';
   this.sonda_file =             '/_d/sondy/bar2d.swf';
   this.wybory_file =            '/_d/wybory/player_wybory_11.swf'; // 2007-11-13
   
   this.requiredMajorVersion =   8;
   this.requiredMinorVersion =   0;
   this.requiredRevision =       0;

   this.cdn_array =              [1];

   this.DrawPlayer = function()
   {
      var r =                    '';
      globalVideoId = globalVideoId+10;
      var fo =                   new SWFObject(this.movie, 'flash_obj'+globalVideoId, this.width_object, this.height_object,
                                                this.requiredMajorVersion+'.'+this.requiredMinorVersion+'.'+this.requiredRevision, this.bgcolor);

      if (fo.installedVer.versionIsValid(fo.getAttribute('version')))
      {
         fo.addParam('allowScriptAccess',    'always');
         if (this.wmode)
         {
            fo.addParam('wmode',             this.wmode);
         }
         if (this.flash_vars)
         {
            fo.addParam('FlashVars',         this.flash_vars);
         }

         r += fo.getSWFHTML();
      }
      else
      {
         r += '<div style="border: 1px solid #DADADA; height: 100%; text-align: center; width: 100%;">';
            r += '<br><a href="http://www.macromedia.com/go/getflashplayer">Musisz uaktualnić Flash Player\'a do wersji min. '+
                     this.requiredMajorVersion+'.'+this.requiredMinorVersion+'.'+this.requiredRevision+'</a>';
         r += '</div>';
      }

      return r;
   };
   
   this.PickCDN = function()
   {
      return this.cdn_array[Math.floor(Math.random() * this.cdn_array.length)];
   };
}


function MVideoAPMode(oid_kategoria)
{
   var ap_map = { '555' : 1, 
                  '539' : 1, 
                  '535' : 1, 
                  '498' : 1, 
                  '536' : 1, 
                  '554' : 1, 
                  '557' : 1,
                  '560' : 2, 
                  '561' : 2,
                  '562' : 2, 
                  '563' : 2,
                  '564' : 2
                 };

   if (typeof ap_map[oid_kategoria] == 'undefined')
      return 1;
   else  
      return ap_map[oid_kategoria];
}



function FlashPlayer(_params)
{
   this.flash_id        = (typeof(_params.flash_id) != 'undefined') ? _params.flash_id : 0;
   this.mm_id             = (typeof(_params.mm_id) != 'undefined') ? _params.mm_id : 0;
   this.image           = (typeof(_params.image) != 'undefined') ? _params.image : '';
   this.width_object    = (typeof(_params.width_object) != 'undefined') ? _params.width_object : 450;
   this.height_object   = (typeof(_params.height_object) != 'undefined') ? _params.height_object : 322;
   this.auto_play       = (typeof(_params.auto_play) != 'undefined') ? _params.auto_play : 0;
   this.return_mode     = (typeof(_params.return_mode) != 'undefined') ? _params.return_mode : 0;
   this.add_flashvars   = (typeof(_params.add_flashvars) != 'undefined') ? _params.add_flashvars : 0;
   this.movie           = (typeof(_params.swf) != 'undefined') ? _params.swf : this.midi_file;
   this.wmode           = 'transparent';
   this.player_html     = '';
   this.flash_vars      = '';
   
   if ((AUTOPLAY_OFF) && (this.return_mode != 1))
   {
      this.auto_play = 0;
   }

   this.ShowPlayer = function(flash_id, mm_id, image)
   {
      var r    = '';
      var adv  = '';

      if (!VIDEO_OFF)
      {
         if ((typeof(spotturl) != 'undefined') && (typeof(spotturl.ad_id) != 'undefined') && (typeof(spotturl.ad_url) != 'undefined'))
         {
            adv = '&a=' + spotturl.ad_id + '&al=' + spotturl.ad_url
         }
         this.flash_vars   = 'flashId=' + flash_id + '&ap=' + this.auto_play + '&v=' + mm_id + '&i=' + image + adv+'&cdn=' + this.PickCDN();

         if (typeof(this.add_flashvars) != 'undefined')
         {
            this.flash_vars += '&' + this.add_flashvars;
         }

         r += this.DrawPlayer();

         if (this.return_mode == 1)
         {
            this.player_html = r;
         }
         else
         {
            document.write(r);
         }
      }
      else
      {
         document.write('<img src="http://m.onet.pl/_m/'+image+'">');
      }
      return false;
   }

   this.showPlayerHtml = function()
   {
      return this.player_html;
   }

   return this.ShowPlayer(this.flash_id, this.mm_id, this.image);
}



/* WRAPPERY PLAYERÓW - BEGIN */

function MidiPlayer(flash_id, mm_id, image, oid_kategoria, auto_play, add_flashvars, width_object, height_object)
{
   var apmode = (typeof(oid_kategoria) != 'undefined') ? MVideoAPMode(oid_kategoria) : 1;
   var add_flashvars = (typeof(add_flashvars) != 'undefined') ? add_flashvars : 'e=0';
   params = {  swf: this.midi_file,
               flash_id: flash_id,
               mm_id: mm_id,
               image: image,
               width_object: (typeof(width_object) != 'undefined') ? width_object : 450,
               height_object: (typeof(height_object) != 'undefined') ? height_object : 285,
               auto_play: (typeof(auto_play) != 'undefined') ? auto_play : 0,
               return_mode: 0,
               add_flashvars: add_flashvars + '&apmode=' + apmode
      };

   // 16:9
   if (apmode == 2)
   {
   } 

   return new FlashPlayer(params);
}


function AdPlayer(flash_id, mm_id, image, oid_kategoria, auto_play, add_flashvars, width_object, height_object)
{
   var apmode = (typeof(oid_kategoria) != 'undefined') ? MVideoAPMode(oid_kategoria) : 1;
   var add_flashvars = (typeof(add_flashvars) != 'undefined') ? add_flashvars : 'e=0';
   params = {  swf: this.ad_file,
               flash_id: flash_id,
               mm_id: mm_id,
               image: image,
               width_object: (typeof(width_object) != 'undefined') ? width_object : 450,
               height_object: (typeof(height_object) != 'undefined') ? height_object : 285,
               auto_play: (typeof(auto_play) != 'undefined') ? auto_play : 0,
               return_mode: 0,
               add_flashvars: add_flashvars + '&apmode=' + apmode
      };

   // 16:9
   if (apmode == 2)
   {
   } 

   return new FlashPlayer(params);
}


function MiniPlayer(flash_id, mm_id, image, title, oid_kategoria)
{
   var apmode = (typeof(oid_kategoria) != 'undefined') ? MVideoAPMode(oid_kategoria) : 1;
   params = {  swf: this.mini_file,
               flash_id: flash_id,
               mm_id: mm_id,
               image: image,
               width_object: 230,
               height_object: 161,
               add_flashvars: 't=' + (title+1) + '&apmode=' + apmode
      };

   // 16:9
   if (apmode == 2)
   {
   } 

   return new FlashPlayer(params);
}


function SmallPlayer(flash_id, mm_id, image, oid_kategoria, width_object, height_object)
{
   var apmode = (typeof(oid_kategoria) != 'undefined') ? MVideoAPMode(oid_kategoria) : 1;
   params = {  swf: this.small_file,
               flash_id: flash_id,
               mm_id: mm_id,
               image: image,
               width_object: (typeof(width_object) != 'undefined') ? width_object : 300,
               height_object: (typeof(height_object) != 'undefined') ? height_object : 200,
               auto_play: 1,
               return_mode: 1,
               add_flashvars: 'apmode=' + apmode
      };
      
   // 16:9
   if (apmode == 2)
   {
   } 

   return new FlashPlayer(params);
}


function AdSmallPlayer(flash_id, mm_id, image, oid_kategoria, width_object, height_object)
{
   var apmode = (typeof(oid_kategoria) != 'undefined') ? MVideoAPMode(oid_kategoria) : 1;
   params = {  swf: this.adsmall_file,
               flash_id: flash_id,
               mm_id: mm_id,
               image: image,
               width_object: (typeof(width_object) != 'undefined') ? width_object : 300,
               height_object: (typeof(height_object) != 'undefined') ? height_object : 260,
               auto_play: 1,
               return_mode: 1,
               add_flashvars: 'apmode=' + apmode
      };
      
   // 16:9
   if (apmode == 2)
   {
   }
      
   return new FlashPlayer(params);
}


function FaktyPlayer(flash_id, mm_id, image, oid_kategoria, width_object, height_object)
{
   var apmode = (typeof(oid_kategoria) != 'undefined') ? MVideoAPMode(oid_kategoria) : 1;
   params = {  swf: this.fakty_file,
               flash_id: flash_id,
               mm_id: mm_id,
               image: image,
               width_object: (typeof(width_object) != 'undefined') ? width_object : 450,
               height_object: (typeof(height_object) != 'undefined') ? height_object : 301,
               auto_play: 0,
               add_flashvars: 'apmode=' + apmode
      };
      
   // 16:9
   if (apmode == 2)
   {
   }
      
   return new FlashPlayer(params);
}


function BigPlayer(flash_id, oid, auto_play, oid_kategoria)
{
   params = {  swf: this.big_file,
               flash_id: flash_id,
               width_object: 670,
               height_object: 372,
               auto_play: (typeof(auto_play) != 'undefined') ? auto_play : 0,
               add_flashvars: 'd=' + oid + '&off=' + VIDEO_OFF
      };
      
   return new FlashPlayer(params);
}

/* WRAPPERY PLAYERÓW - END */


function FullPlayer(flash_id, oid)
{
   this.width_object =           '100%';
   this.height_object =          '100%';
   this.auto_play =              1;
   this.width_win =              screen.availWidth;
   this.height_win =             screen.availHeight;
   this.name =                   'TVN24_Wideo';
   if(navigator.appName == "Microsoft Internet Explorer")
   {
      this.parameters =             'top=0, left=0, status=no, toolbar=no, location=no, menubar=no, directories=no, scrollbars=no, resizable=yes, fullscreen=no, width='+
                                 (this.width_win-10)+', height='+(this.height_win-30);
   }
   else
   {
      this.parameters =             'status=no, toolbar=no, location=no, menubar=no, directories=no, scrollbars=no, resizable=yes, fullscreen=yes, width='+
                                 this.width_win+', height='+this.height_win;
   }

   this.ShowPlayer = function(flash_id, oid)
   {
   var r =                    '';
   var new_win;

      if (!VIDEO_OFF)
      {
         this.flash_vars =       'flashId='+flash_id+'&ap='+this.auto_play+'&v='+oid+'&cdn='+this.PickCDN();
         this.movie =            this.full_file;

         r += '<html>';
         r += '<head>';
            r += '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
         r += '</head>';
         r += '<script language="javascript" type="text/javascript">';
            r += "function FullPlayer(a,b){window.close();}";
         r += '</script>';
         r += '<body style="background: '+this.bgcolor+'; color: '+this.color+'; margin: 0; padding: 0;">';
            r += this.DrawPlayer();
         r += '</body>';
         r += '</html>';
      }

      new_win = window.open('', this.name, this.parameters);
      new_win.document.open();
      new_win.document.write(r);
      new_win.document.close();
      if (window.focus)
      {
         new_win.focus();
      }
   }


   this.ShowPlayer(flash_id, oid);
   return void(0);
}


function AudioPlayer(flash_id, url_a)
{
   this.width_object =           209;
   this.height_object =          35;
   this.wmode =                  'transparent';
   
   this.auto_play =              0;
   if (AUTOPLAY_OFF)
   {
      this.auto_play =           0;
   }

   this.ShowPlayer = function(flash_id, url_a)
   {
   var r =                    '';

      if (!VIDEO_OFF)
      {
         this.flash_vars =       'flashId='+flash_id+'&autoplay='+this.auto_play+'&plik='+url_a;
         this.movie =            this.audio_file;

         r += this.DrawPlayer();
         document.write(r);
      }

      return false;
   }

   return this.ShowPlayer(flash_id, url_a);
}

/* -----------------------------------------------------------------------------------------------*/

function AddPlaylist()
{
   this.width_object =           1;
   this.height_object =          1;
   this.wmode =                  'transparent';
   
   this.div_flash_id =           'flash_add_item';
   this.div_ajax_id =            'ajax';

   this.AddItem = function(flash_id, oid, vid, name)
   {
   var r =                    '';

      this.flash_vars =       'flashId='+flash_id+'&oid='+oid+'&vid='+vid+'&nazwa='+name;
      this.movie =            this.add_file;

      r += this.DrawPlayer();
      document.getElementById(this.div_flash_id).innerHTML = r;
      AjaxRequest('1,'+oid+',0,playlista_akcja.html', this.div_ajax_id, 3);

      return false;
   }
}



function SportTable(flash_id)
{
   this.width_object =           338;
   this.height_object =          800;
   this.wmode =                  'transparent';
   
   this.data =                   '/sport.xml';

   this.ShowTable = function(flash_id)
   {
   var r =                    '';

      this.flash_vars =       'flashId='+flash_id+'&l='+this.data;
      this.movie =            this.sport_file;

      r += this.DrawPlayer();
      document.write(r);

      return false;
   }

   return this.ShowTable(flash_id);
}

function WIG20()
{
   this.width_object =           275;
   this.height_object =          130;
   this.wmode =                  'transparent';

   this.ShowTable = function()
   {
   var r =                    '';

      this.flash_vars =       'dataURL=/xtb/wig20.xml&chartWidth=275&chartHeight=130';
      this.movie =            this.wig20_file;

      r += this.DrawPlayer();
      document.write(r);

      return false;
   }

   return this.ShowTable();
}


function WynikiSondy(oid,width,height)
{
   this.width_object =           width;
   this.height_object =          height;
   this.wmode =                  'transparent';
   
   this.data =                   '/'+oid+',sonda_wyn.xml';

   this.ShowTable = function()
   {
   var r =                    '';

      this.flash_vars =       'dataURL='+this.data+'&chartWidth='+this.width_object+'&chartHeight='+this.height_object;
      this.movie =            this.sonda_file;

      r += this.DrawPlayer();
      document.write(r);

      return false;
   }

   return this.ShowTable();
}

function VideoList()
{
   this.http =          null;
   this.destName =      'ajax_video_list';

   this.AjaxRequest = function(url)
   {
   var dest = document.getElementById(this.destName);

      http = new mkwHTTP(2);
      http.Get(
                  {
                     'url':         url,
                     'onLoading' :  function(o)
                                    {
                                       dest.innerHTML = '<div class="a1" style="color: #AAAAAA; text-align: center;">Proszę czekać...</div>';
                                    },
                     'onSuccess' :  function(o)
                                    {
                                       res = o.ResponseText;
                                       if (typeof(res) == 'string')
                                       {
                                          dest.innerHTML = res;
                                       }
                                    },
                     'onError' :    function(i)
                                    {
                                       dest.innerHTML = '<div class="a1" style="text-align: center;"></div>';
                                    }
                  }
               );
   }
}

function CategoryList(id, active, className)
{
   this.http =          null;
   this.destName =      'ajax_video_list';
   this.id =            id;
   this.active =        typeof(active) == 'undefined' ? 0 : active;
   this.className =     typeof(className) == 'undefined' ? 'zakladki' : className;

   this.Show = function(n)
   {
      var underscore = '_';
      while (document.getElementById('' + this.id + underscore + this.active))
      {
         document.getElementById('' + this.id + underscore + this.active).className = this.className + underscore + 'n';
         document.getElementById('' + this.id + underscore + n).className = this.className + underscore + 'a';
         underscore += '_';
      }
      this.active = n;
   }

   this.AjaxRequest = function(url)
   {
   var dest = document.getElementById(this.destName);

      http = new mkwHTTP(2);
      http.Get(
                  {
                     'url':         url,
                     'onLoading' :  function(o)
                                    {
                                       dest.innerHTML = '<div class="a1" style="color: #AAAAAA; text-align: center;">Proszę czekać...</div>';
                                    },
                     'onSuccess' :  function(o)
                                    {
                                       res = o.ResponseText;
                                       if (typeof(res) == 'string')
                                       {
                                          dest.innerHTML = res;
                                       }
                                    },
                     'onError' :    function(i)
                                    {
                                       dest.innerHTML = '<div class="a1" style="text-align: center;"></div>';
                                    }
                  }
               );
   }
}


function SWFobject(swf, flashVars, szerokosc, wysokosc, backgroundcolor, no_write)
{
   this.width_object    = ''+szerokosc+'';
   this.height_object   = ''+wysokosc+'';
   this.bgColor         = ''+backgroundcolor+'';
   this.flash_vars      = ''+flashVars+'';
   this.movie           = ''+swf+'';

   this.r = this.DrawPlayer();
   if (!no_write)
   {
      document.write(this.r);
   }
}


FlashPlayer.prototype   = new DefaultFlashObject();

AdPlayer.prototype      = new DefaultFlashObject();
AdSmallPlayer.prototype = new DefaultFlashObject();
SmallPlayer.prototype   = new DefaultFlashObject();
MiniPlayer.prototype    = new DefaultFlashObject();
MidiPlayer.prototype    = new DefaultFlashObject();
FaktyPlayer.prototype   = new DefaultFlashObject();
FullPlayer.prototype    = new DefaultFlashObject();
BigPlayer.prototype     = new DefaultFlashObject();
AudioPlayer.prototype   = new DefaultFlashObject();
AddPlaylist.prototype   = new DefaultFlashObject();
SportTable.prototype    = new DefaultFlashObject();
WIG20.prototype         = new DefaultFlashObject();
WynikiSondy.prototype   = new DefaultFlashObject();
SWFobject.prototype     = new DefaultFlashObject();

var play_list = new AddPlaylist();