//==== onetApp CLASS

var $onet;
var $onet_version = "std040";

function badBrowser ()
{
  if ((window.innerWidth != $onet.nsWinWidth) || (window.innerHeight != $onet.nsWinHeight))
    location.reload()
}

function protoCode ($class)
{
  var $code = '';
  for (var $i = 1; $i < arguments.length; ++ $i)
    $code += $class +'.prototype.'+ arguments[$i] +'='+ arguments[$i] +';';
  $code += $class +'.prototype.ok=1;';
  return $code;
}

function nullErrorHandler ()
{
  return true;
}

function onetApp ()
{
//==== onetApp PUBLIC METHODS

function onPageLoad ($code)
{
  $onet.onPgLdCode += $code +";";
}

function onStreamAvail ($code)
{
  $onet.onStAvCode += $code +";";
}

function streamCheck ()
{
  if (! (document.createElement && document.body.appendChild))
    return

  var $js = document.createElement('script')
  $js.type = "text/javascript"
  $js.src = "/_s/kropka/s.js"
  document.body.appendChild ($js)
}

function streamOK ($code)
{
  setTimeout ($onet.onStAvCode, 50);
}

function urlEncode ($str)
{
  $str = ""+ $str
  $str = $str.replace (/\%/g, "%25")
  $str = $str.replace (/\s/g, "%20")
  $str = $str.replace (/\#/g, "%23")
  $str = $str.replace (/\&/g, "%26")
  $str = $str.replace (/\+/g, "%2b")
  $str = $str.replace (/\?/g, "%3f")
  $str = $str.replace (/\"/g, "%22")
  $str = $str.replace (/\'/g, "%27")
  return $str
}

function logoutLink ($tpre, $apre, $apost, $tpost)
{
  if ($onet.zuoIsl) document.write (unescape (
    $tpre + '<a href="http://www.onet.pl/logout.rd">'+
    $apre + $onet.zuoUid + $apost +
    '</a>' + $tpost))
}

function loginSwitch ($code1, $code0)
{
  if ($onet.zuoIsl)
  {
    var $login = $onet.zuoUid
    eval ($code1)
  }
  else
  {
    eval ($code0)
  }
}

function getInfo1 ($ver)
{
  if ($ver != $onet_version)
    $onet.dvError ($onet_version +'.js: library version mismatch ('+ $ver +')')
    
  var $info = new Object ()

  $info.scrWidth  = window.screen && screen.width ? screen.width : 0;
  $info.scrHeight = window.screen && screen.height ? screen.height : 0;
  $info.scrBits = 0;
  if (window.screen.colorDepth) $info.scrBits = window.screen.colorDepth;
  if (window.screen.pixelDepth) $info.scrBits = window.screen.pixelDepth;
  $info.winWidth = 0;
  if (window.innerWidth) $info.winWidth = window.innerWidth;
  if (document.body && document.body.clientWidth) $info.winWidth = document.body.clientWidth;
  $info.winHeight = 0;
  if (window.innerHeight) $info.winHeight = window.innerHeight;
  if (document.body && document.body.clientHeight) $info.winHeight = document.body.clientHeight;

  $onet.info = $info

  var $res = '&RI='+ urlEncode ($onet.curid)+
    '&DU='+ urlEncode ($onet.lhref)+
    '&DR='+ urlEncode ($onet.dref)+
    '&CS='+ urlEncode ($info.scrWidth+'x'+$info.scrHeight+'x'+$info.scrBits)+
    '&CW='+ urlEncode ($info.winWidth+'x'+$info.winHeight)+
    '&C1='+ urlEncode ($onet.now)+
    '&CL='+ urlEncode ($onet_version);

  return $res
}

function getInfoG ()
{
	var dt=new Date();
	var url=new String();
	var d=document;
	var href=new String(d.location);
	var w=window;
	var ref;
	if (d.referrer) { ref = new String(d.referrer); } else { ref = ""; }
	if(typeof(Error)!='undefined') {
		eval("try { if (typeof(top.document.referrer)=='string') { ref = top.document.referrer } } catch(_ex) { }");
		eval("try { while (w!=top) { typeof(w.parent.document.location); w = w.parent; } } catch(_ex) {}");
	}
	eval(' if (typeof(w.gemius_id)=="undefined") { w.gemius_id = Math.floor(Math.random()*1000000000); w.gemius_cnt = 1; } else { w.gemius_cnt++; }');
	url+='&tz='+dt.getTimezoneOffset()+'&href='+escape(href.substring(0,280))+'%23_'+w.gemius_id+'_'+w.gemius_cnt+'&ref='+escape(ref.substring(0,299));
	if (screen) {
		var s=screen;
		if (s.width) url+='&screen='+s.width+'x'+s.height;
		if (s.colorDepth) url+='&col='+s.colorDepth;
	}
	return url;
}

//==== onetApp PRIVATE METHODS

function hexToDec ($hex)
{
  return parseInt ("0x"+ $hex)
}

function decToHex ($dec, $minl)
{
  if (arguments.length < 2) $minl = 0;
  $dec = parseInt ($dec)
  var $d2h = "0123456789abcdef";
  var $hex = "";
  while ($dec > 0)
  {
    $hex = $d2h.charAt ($dec & 0xf) + $hex;
    $dec >>= 4
    -- $minl
  }
  while ($minl > 0)
  {
    $hex = "0" + $hex;
    -- $minl
  }
  return $hex
}

function zuoStr ($offset)
{
  var $str = ""
  var $len = hexToDec (document.cookie.substr ($offset, 1*2))
  for (var i = 0; i < $len; ++ i)
    $str += String.fromCharCode (hexToDec (document.cookie.substr ($offset+2+i*2, 2)))
  return $str
}

function usingFrames ()
{
  $onet.unFrame = 0
}

function pageLoadHook ()
{
  if ((self != top) && $onet.unFrame) top.location.href = self.location.href;

  if (document.layers)
  {
    $onet.nsWinWidth  = window.innerWidth;
    $onet.nsWinHeight = window.innerHeight;
    onresize          = badBrowser;
  }

  if ($onet.xjs)
    onet ('onPageLoad', '$onet.statGFinal()')

  if ($onet.onStAvCode)
    onet ('onPageLoad', '$onet.streamCheck()')

  setTimeout ($onet.onPgLdCode, 50);

  return true;
}

function statError ($img)
{
  $img.onerror = null;

  if (window.location.protocol && ("http:" == window.location.protocol))
    $img.src = $img.src.replace (/^([^\/]+\/+)[^.]+(.+)$/, "$1www$2&RA=2")
}

function statGFinal ()
{
  if (! (window.location.protocol && ("http:" == window.location.protocol)))
    return
  if (! (document.createElement && document.body.appendChild))
    return

  var $js = document.createElement('script')
  $js.type = "text/javascript"
  $js.src = $onet.xjs
  document.body.appendChild ($js)
}

function statGFunc ($img, $ok)
{
  $onet.statg = $img
  return new Function ('$onet.statGLoad ('+ $ok +')')
}

function statGLoad ($ok)
{
  if (! $onet.statg)
    return

  $img = $onet.statg
  $img.onerror = null;
  $img.onload = null;

  if (! ($ok && $img.width && ($img.width > 1)))
    return

  var $now = (new Date()).getTime()
  $onet.xjs = "http://onet.hit.gemius.pl/_"+ $now +"/pbi_pe.js?id=W@vC6QnwKYIM3DNDKF@_APT7"
}

function clickIt ($link)
{
  if (! $onet.clickImg)
    $onet.clickImg = new Array ()

  var $img = new Image ()
  $img.src = $link +','+ $onet.pgid + (new Date()).getTime()
  $onet.clickImg[$onet.clickImg.length] = $img
}

function igetIEVer ()
{
  var $ua = navigator.userAgent
  var $mi = $ua.indexOf("MSIE")
  if ($ua.indexOf("Win") < 0)             return ""
  if ($ua.indexOf("MSIE") < 0)            return ""
  if ($ua.indexOf("Opera") >= 0)          return ""
  if ($ua.charAt($mi+5) < 4)              return ""
  if ($ua.charAt($mi+5) > 9)              return ""
  var $re = /^([\d.]+)/i;
  if (!$re.test ($ua.substring($mi+5)))   return ""
  $res = parseFloat (RegExp.$1)
  if (isNaN ($res))                       return ""
  return $res
}

function getIEVer ()
{
  return $onet.iev;
}

function isIE ($ver)
{
  if (! arguments.length) $ver = 5.00;
  return $onet.iev && $onet.iev >= $ver;
}

function set ($key, $val)
{
  $onet[$key] = $val;
}

function get ($key, $val)
{
  return $onet[$key];
}

function dvError ($msg)
{
  if (! window.fac424a6d2ff31fed70c79e47db5b406) return
  fac424a6d2ff31fed70c79e47db5b406 ('error', $msg)
}

function test ($arg)
{
  alert ($arg.src);
}

//==== onetApp CONSTRUCTOR

function construct ()
{
  $onet.onPgLdCode = ''
  $onet.onStAvCode = ''
  $onet.unFrame = 1;

  $onet.now   = (new Date()).getTime()
  $onet.curid = decToHex (Math.floor (Math.random() * 0x7ffff), 5) +
    decToHex (Math.floor ($onet.now / 1000), 8) +
    decToHex (Math.floor ($onet.now % 1000), 3)
  $onet.iev   = igetIEVer ()

  $onet.lhref = ''
  $onet.dref  = ''
  var $onerror = window.onerror
  window.onerror = nullErrorHandler
  $onet.lhref = location.href
  $onet.dref  = document.referrer
  window.onerror = $onerror

  if ('undefined' != typeof (document.cookie))
  {
    var $offset = document.cookie.indexOf ("onet_uid=")
    if ($offset >= 0)
    {
      $offset = document.cookie.indexOf ("=", $offset) + 1
      var $endstr = document.cookie.indexOf (";", $offset)
      if ($endstr == -1) $endstr = document.cookie.length
      $onet.zuoIsl = 1
      $onet.zuoUid = document.cookie.substring ($offset, $endstr)
    }
    else
    {
      $offset = document.cookie.indexOf ("onetzuo_ticket=")
      if ($offset >= 0)
      {
        $offset += 15
  
        var $zuoUid = zuoStr ($offset+47*2)
        if ("" != $zuoUid)
        {
          $onet.zuo = 1
          $onet.zuoUid = $zuoUid
          $onet.zuoMbx = zuoStr ($offset+(47+1+hexToDec (document.cookie.substr ($offset+47*2, 1*2)))*2)
    
          var $exp = 1000 * hexToDec (document.cookie.substr ($offset+38*2, 4*2));
          var $isl = $exp - $onet.now
          $onet.zuoIsl = $isl > 0 ? $isl : 0
        }
      }
    }
  }

  onload = $onet.pageLoadHook;
}

if (! this.ok)
{
  eval (protoCode ('onetApp',
    'construct',
    'onPageLoad',
    'onStreamAvail',
    'streamCheck',
    'streamOK',
    'pageLoadHook',
    'usingFrames',
    'logoutLink',
    'loginSwitch',
    'getInfo1',
    'getInfoG',
    'getIEVer',
    'isIE',
    'statError',
    'statGFunc',
    'statGLoad',
    'statGFinal',
    'set',
    'get',
    'clickIt',
    'dvError',
    'test'
  ));
}

//==== onetApp END

}

//==== onetApp ACCESSOR

function onet ()
{
  if (! $onet)
  {
    $onet = new onetApp ()
    $onet.construct ()
  }

  var $alen = arguments.length;
  if (! $alen)
    return $onet_version;

  var $call = 'call' +'@'+ $alen
  if (! $onet[$call] && $onet[arguments[0]])
  {
    var $code = 'return $onet[$args[0]] ( '
    for (var $i = 1; $i < $alen; ++ $i)
    {
      $code += '$args['+ $i +']'
      if ($i + 1 < $alen) $code += ','
    }
    $code += ' )'
    $onet[$call] = new Function ("$args", $code);
  }

  if ($onet[$call])
    return $onet[$call] (arguments)
  else
    return ""
}

