function o(a){return document.getElementById(a);};

function setOpacity(obj,value) {
	obj.style.opacity = value/100;
	obj.style.filter = 'alpha(opacity=' + value + ')';
};



function mouseXY(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft+document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop+document.documentElement.scrollTop;
	}
  return [posx,posy];
};

function getPageScroll(){
	var sc=[];
	if (self.pageYOffset) {
		sc = [self.pageXOffset,self.pageYOffset];
	} else if (document.documentElement ){
	  sc = [document.documentElement.scrollLeft,document.documentElement.scrollTop];
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		sc = [document.body.scrollLeft,document.body.scrollTop];
	}
	return sc;
};

function windowSize(){
	var ws=[];
	if (self.innerHeight) {	// all except Explorer
		ws=[self.innerWidth,self.innerHeight];
	} else if (document.documentElement) { // Explorer 6 Strict Mode
		ws=[document.documentElement.clientWidth,document.documentElement.clientHeight];
	} else if (document.body) { // other Explorers
	ws=[document.body.clientWidth,document.body.clientHeight];

	}
	return ws;
};
function no_flash(){
 popMsg.show('<br><br>Aby oglądać klipy musisz zainstalować wtyczkę <br><a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player</a> w wersji 9.0.0 lub nowszej.<br><br><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>');
}

function nextClipPlease(id){
if(id<0)
popPlayer.play();
var id=parseInt(id)+1;
var pl=play_list.getList();
if(id>=pl.length)id=0;
var itm =pl[id];
if(itm && play_list.on)window.location='./?'+itm[1]+'='+itm[0]+'&ap&pli='+(id)+'#playlist';

};
  var alt={
    id:null,
    win_size:null,
    install:function(id){
      this.id=id||'alt';
      this.win_size=windowSize();
      document.body.appendChild(NODE.make('div',{'id':this.id}));
      document.body.appendChild(NODE.make('p',{'id':'alta'}));
      o('alta').innerHTML="<!-- -->";
      o(this.id).innerHTML='<div id="'+this.id+'cont"></div>';
      EVENT.add(document.body,'mousemove',alt.move);
      //EVENT.add(window,'scroll',alt.hide );
      EVENT.add(window,'resize',alt.resize);
      setOpacity(o('alta'),85);
      setOpacity(o(this.id),85);
    },
    move:function(e){
      var mp=mouseXY(e);
      
      var ofs=( mp[0]+220+25>alt.win_size[0]?mp[0]+222-alt.win_size[0]+25 :0 );
      NODE.css(o(alt.id),{
        'left':(mp[0]+5-ofs )+'px',
        'top':(mp[1]+38)+'px'
      });
      NODE.css(o('alta'),{
        'left':(mp[0]+5 )+'px',
        'top':(mp[1]+22)+'px'
      });
      
    
    },
    resize:function(e){

      alt.win_size=windowSize();
    },
    show:function(text){
      NODE.css(o('alta'),{
        'display':'block'
      });
      NODE.css(o(this.id),{
        'display':'block'
      });
      o(this.id+'cont').innerHTML=text;
    },
    hide:function(){
      NODE.css(o(alt.id),{
        'display':'none'
      });
      NODE.css(o('alta'),{
        'display':'none'
      });
    }
  
  
  
  };

  //REF do okienka  (musi byc jako samodzielna zmienna)
  var popupWin=null;

  var popPlayer={
  
    q:'',
    stream:function(){
          popupWin.octoPlayEmbedded('Time.400', 'TV', 426,240,2);
          popPlayer.resize('Time.400');
        },
   
   
    install:function(){
      /*this.play();
      if(o('press_play_low'))
      o('press_play_low').onclick=function(){
        popPlayer.q='low';
        if(ch_o()){
        popPlayer.stream=function(){
          popupWin.octoPlayEmbedded('Time.400', 'TV', 426,270,2);
          popPlayer.resize('Time.400');
        }
      popPlayer.show();return false;
      }
      };
      if(o('press_play_high'))
      o('press_play_high').onclick=function(){
      popPlayer.q='hi';
      if(ch_o()){
        popPlayer.stream=function(){
         popupWin.octoPlayEmbedded('Time.800', 'TV', 426,270,2);
          popPlayer.resize('Time.800');
        }
      popPlayer.show();return false;
      }
      };*/
      
     
    },
    resize:function(arg){
    
      if(popupWin && !popupWin.closed)
      switch(arg){
        case 'Time.800' :
          
          popupWin.resizeTo(730,721);
        break;
        case 'Time.400' :
          popupWin.resizeTo(450,300); 
        break;
      }
    },
    show:function(){
      if(popupWin && !popupWin.closed){
        popPlayer.play();
      }else{
        popupWin=window.open('player.html#'+popPlayer.q,"_blank","toolbar=0, location=0, directories=0, status=0,titlebar=0, menubar=0, scrollbars=0, resizable=0, copyhistory=0, width=650, height=420");
        popupWin.focus();
     } 
    },
    stop:function(){
      if(popupWin)
      popupWin.octoEmbeddedPlayerStop('TV');
    },
    play:function(){
      if(popupWin && !popupWin.closed){
      popupWin.octoEmbeddedPlayerPlay('TV');
      popupWin.focus();
      }
    }
    
  
  };



  var overlay={
    id:null,
    oid:null,
    visible:false,
    install:function(id,oid){
      this.id=id||'overlay';
      this.oid=oid||'main';
      EVENT.add(window,'resize',function(){overlay.resize()} );
      this.resize();
    },
    resize:function(){
      if(overlay.visible)
      NODE.css(o(this.id),{
      'width':o(this.oid).offsetWidth+'px',
      'height':o(this.oid).offsetHeight+'px'
      });
    },
    show:function(){
      overlay.visible=true;
      o('banner_top').style.visibility="hidden";
      if(!o(this.id))
      document.body.appendChild(NODE.make('div',{'id':this.id}));
      setOpacity(o(this.id),70);
      overlay.resize();
    },
    hide:function(){
     o('banner_top').style.visibility="visible";
      overlay.visible=false;
      document.body.removeChild(o(this.id));
    }
  };
  
  var imagePreview={
    id:null,
    link:null,
    lo_img:'static/gfx/loading.gif',
    lo_size:[60,60],
    on:false,
    install:function(id){
      this.id=id||'imagePreview';
      var img = new Image();
      img.src=this.lo_img;
    },
    show:function(_link){
      imagePreview.on=true;
      if(!o(this.id))
      document.body.appendChild(NODE.make('div',{'id':this.id}));
      o(this.id).innerHTML='<img id="'+this.id+'Img" src="'+this.lo_img+'"/><div><a href="#" id="'+this.id+'Prev">◄</a><span id="'+this.id+'Title"></span><a href="#" id="'+this.id+'Next">►</a></div>';
      o(this.id+"Img").onclick=this.hide;
      NODE.css(o(this.id),{'background':''});
      this.link=_link;
      var img = new Image();
      overlay.show();
      o(this.id+"Prev").style.display=o(this.id+"Next").style.display='none';
      
      img.onload=function(){
          if(!imagePreview.on)
          return;
          if(imagePreview.link.getAttribute('rel'))
            imagePreview.setSlides(imagePreview.link);
          var sc=getPageScroll();
          var ws=windowSize();
          var rs=1;
          if(this.width>ws[0] || this.height>ws[1]){
             rs = ( this.height*ws[0]/this.width>ws[1] ? ws[1]/(this.height+80) : w[0]/(this.width+60) );
          }
          o(imagePreview.id+'Img').src=this.src;
          o(imagePreview.id+'Img').width=this.width*rs;
          o(imagePreview.id+'Img').height=this.height*rs;
          NODE.css(o(imagePreview.id),{
          'background':'#fff',
          'borderWidth':'10px',
          'left':((ws[0]-this.width*rs)/2)+'px',
          'top':(sc[1]+(ws[1]-this.height*rs)/2)+'px'
          });
        
      };
      o(this.id+'Img').src=this.lo_img;
      o(this.id+'Img').width=this.lo_size[0];
      o(this.id+'Img').height=this.lo_size[1];
      var sc=getPageScroll();
      var ws=windowSize();
      NODE.css(o(this.id),{
      'borderWidth':'0',
      'display':'block',
      'left':((ws[0]-this.lo_size[0])/2)+'px',
      'top':(sc[1]+(ws[1]-this.lo_size[1])/2)+'px'
      });
      
      img.src=_link.href;
    },
    hide:function(){
      imagePreview.on=false;
      document.body.removeChild(o(imagePreview.id));
      overlay.hide();
     
     //NODE.css(o(imagePreview.id),{'background':'','display':'none'});
      //o(imagePreview.id+'Img').src=imagePreview.lo_img;
      //o(imagePreview.id+'Img').width=imagePreview.lo_size[0];
      //o(imagePreview.id+'Img').height=imagePreview.lo_size[1];
    },
    
    setSlides:function(link){
      if(!imagePreview.on)return;
        var ind;
        var arr = q('a[rel='+link.getAttribute('rel')+']');
        for( var i=0;i<arr.length;i++){
        if(arr[i]==link){
         ind=i;
         break;
         }
        }
        if(ind){
          o(this.id+"Prev").style.display='inline';
          o(this.id+"Prev").onclick=function(){this.blur(); imagePreview.show(arr[ind-1]);return false; };
        }else{
          o(this.id+"Prev").style.display='none';
        }
        if(ind<arr.length-1){
          o(this.id+"Next").style.display='inline';
          o(this.id+"Next").onclick=function(){this.blur();  imagePreview.show(arr[ind+1]);return false; };
        }else{
          o(this.id+"Next").style.display='none';
        }
        
      }
      
  };
  
  var flvPreview={
    id:'flvPreview',
    show:function(flv){
        var sc=getPageScroll();
        var ws=windowSize();
        overlay.show();
        document.body.appendChild(NODE.make('div',{'id':flvPreview.id}));
        o(flvPreview.id).innerHTML='<a id="'+flvPreview.id+'Close">Zamknij</a><embed height="350" width="400" type="application/x-shockwave-flash" src="http://eskatv.eska10.sm.pl//static/player.swf" name="fpb" bgcolor="#000000" quality="high" flashvars="imageurl=http://eskatv.eska10.sm.pl/static/gfx/flv_intro.jpg&amp;flvurl='+flv+'&amp;autoPlay=1&amp;id=-1" wmode="opaque" id="fpb" allowfullscreen="true"/>'
        NODE.css(o(flvPreview.id),{
        'left':((ws[0]-400)/2)+'px',
        'top':(sc[1]+(ws[1]-350)/2)+'px'
        });
        o(flvPreview.id+"Close").onclick=function(){
          flvPreview.hide();
        return false;
        }
    },
    hide:function(){
       o(flvPreview.id).removeChild( o(flvPreview.id).getElementsByTagName('embed')[0] ); 
      document.body.removeChild(o(flvPreview.id));
      overlay.hide();
    }
  }
  var popMsg={
    id:'popMsg',
    show:function(msg){
        var sc=getPageScroll();
        var ws=windowSize();
        overlay.show();
        document.body.appendChild(NODE.make('div',{'id':popMsg.id}));
        o(popMsg.id).innerHTML=msg+'<a id="'+popMsg.id+'Close">Zamknij</a>'
        NODE.css(o(popMsg.id),{
        'left':((ws[0]-o(popMsg.id).offsetWidth+10)/2)+'px',
        'top':(sc[1]+(ws[1]-o(popMsg.id).offsetHeight+10)/2)+'px'
        });
        o(popMsg.id+"Close").onclick=function(){
          popMsg.hide();
        return false;
        }
    },
    hide:function(){
       
      document.body.removeChild(o(popMsg.id));
      overlay.hide();
    }
  }

var pli=null;

function forEach(object,fun /*, thisp*/){for (var i = 0,len = object.length; i < len; i++)fun.call(arguments[2], object[i], i);};

function ajax(met,url,func,params)
  {
  var xmlHttp;
  try{xmlHttp=new XMLHttpRequest();}catch (e){
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){
      try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
    {
       if(xmlHttp.readyState==4)
       {
        func(xmlHttp.responseText);
       }
     };
	if(met=="get"||met=="GET"){xmlHttp.open(met,url,true);xmlHttp.send(null);}
if(met=="post"||met=="POST"){
	xmlHttp.open(met,url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.send(params);
	}
	return xmlHttp;
  };


function filter(object,fun /*, thisp*/){
    var res = new Array();
    for (var i = 0,len = object.length; i < len; i++)if (fun.call(arguments[1], object[i], i))res.push(object[i]);
    return res;
};

if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp*/)
  {
    var len = this.length;
    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        res[i] = fun.call(thisp, this[i], i, this);
    }

    return res;
  };
};

  Array.prototype.inArray = function(val /*, thisp*/)
  {
    var len = this.length;
    for (var i = 0; i < len; i++)
    {
      if (this[i]==val)
        return true;
    }

    return false;
  };





function PeriodicalExecuter(func,freq,val){
  this.timer=null;
  var that=this;
  this.val=val||0;
  this.freq=freq||1;
  this.timer = setInterval(function(){func(that)},this.freq);
  this.stop = function(){
    clearTimeout(this.timer)
  }
    
  


};




  NODE = {
    getPos:function(obj){var curleft = curtop = 0;
        if (obj.offsetParent) {curleft = obj.offsetLeft;curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {curleft += obj.offsetLeft;curtop += obj.offsetTop;}}
        return [curleft,curtop];
    },
    addClass:function (obj,c){
    
      if(obj.className.indexOf(c)==-1 )
      obj.className+=" "+c;
      
    },
    removeClass:function (obj,c){
    
      if(obj)
      obj.className=obj.className.replace(new RegExp("(\s*"+c+")","gi"),'');
    },
    make:function(tag,attr,css){
      var elem=document.createElement(tag);
      for(var i in attr){
      elem.setAttribute(i,attr[i]);
      }
      for(var i in css){
      elem.style[i]=css[i];
      }
      return elem;
    },
    makeText:function(arg){
    return document.createTextNode(arg);
    },
    css:function(obj,css){
     for(var i in css){
      obj.style[i]=css[i];
      }
      return obj;
    
    },
    getStyle:function (el,styleProp)
    {
    	
    	var stylIE = styleProp.replace(/-(.){1,1}/g ,function(s){return s.charAt(1).toUpperCase();});
    
    	var x = el;
    	if (x.currentStyle)
    		var y = x.currentStyle[stylIE];
    	else if (window.getComputedStyle)
    		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    	return y;
    }
    
  
  };

EVENT = {
    add : function(obj,evt,fn) {
	   if (obj.addEventListener)obj.addEventListener(evt,fn,false);
	   else if (obj.attachEvent){
       obj["e"+evt+fn] = fn;
        obj.attachEvent( "on"+evt, function() { obj["e"+evt+fn](); } );
        }
    //
    },
    fire:function(obj,event){

        if (document.createEventObject){
            // dispatch for IE
            var evt = document.createEventObject();
            return obj.fireEvent('on'+event,evt)
        }
        else{
            // dispatch for firefox + others
            var evt = document.createEvent("HTMLEvents");
            evt.initEvent(event, true, true ); // event type,bubbling,cancelable
            return !obj.dispatchEvent(evt);
        }

    
    },
    remove : function(obj,evt,fn) {
      if (obj.removeEventListener)obj.removeEventListener(evt,fn,false);
      else if (obj.detachEvent){
      obj.detachEvent( "on"+type, obj["e"+type+fn] );
      obj["e"+type+fn] = null;
      }
    },
    target : function(e) {
      var targ;
      if (!e) var e = window.event;
      if (e.target) targ = e.target;
      else if (e.srcElement) targ = e.srcElement;
      if (targ.nodeType == 3)targ = targ.parentNode;
      return targ;	
    },
    related : function(e) {
     if (!e) var e = window.event;
	    return  e.relatedTarget || e.toElement;
    },
    cancel : function(e) {
      try{
      if (!e) var e = window.event;
      e.cancelBubble = true;
      if (e.stopPropagation) e.stopPropagation();
      }catch(ex){}	
    },
    mouseXY : function(e){
      var e = e || window.event;
      return (e.pageX?[e.pageX,e.pageY]:[e.clientX,e.clientY])
    },
    key:function(e) {
    	var code;
    	if (!e) var e = window.event;
    	if (e.keyCode) code = e.keyCode;
    	else if (e.which) code = e.which;
    	return code;
    }

  };
/*Prosty querySelector by Orzech:) */
function q(query,context){
  var base_context=context=context||new Array(document);
  var filters={
  hasClass:function(c){return this.className.split(/\s+/).inArray(c)  },
  isTag:function(t){return (this.nodeType==1&&this.nodeName==t.toUpperCase())},
  isNode:function(){return (this.nodeType==1)},
  attr:function(a,v){return this.getAttribute(a)==v}
  };
  var get=[];
  get['#']=function(id){return [document.getElementById(id)]};
  get['']=get[' ']=function(tag){return this.getElementsByTagName(tag)};
  get['>']=function(){return this.childNodes};
  get['<']=function(id){return [this.parentNode]};
  get['+']=function(id){return [this.nextSibling]};
  get['~']=function(id){return [this.previousSibling]};
  var exe;
  var fin=new Array();
  forEach(query.split(','),function(q_part){
  var gen_reg =new RegExp(/([_><~\+\s#]{0,1})([a-z_\d]*)(\.{0,1})([a-zA-Z\.\d_\-]*)(\[[a-z\d;=\-]+\])*(:[a-zA-Z\-]+){0,1}/g);
  while((exe=gen_reg.exec(q_part)) && exe[0]){
    var new_context=new Array();var filter_arr=new Array();var s_i=null;var e_i=null;var only_last=false;var m;
    
    if( exe[1]!=''&&exe[1]!=' '&&exe[1]!='#' )
      filter_arr.push(  (exe[2]?['isTag',exe[2]]:['isNode'])  );
    
    if(exe[3]=='.')
    forEach(exe[4].split('.'),function(v,k){ filter_arr.push( ['hasClass',v] ); } );
    
    if(m=/^\[(\d+)\-(\d*)\]$/gi.exec(exe[5]) ){
      s_i=m[1];e_i=(m[2]?parseInt(m[2])+1:null);
    }else if(m=/^\[(\d+)\]$/gi.exec(exe[5]) ){
      s_i=m[1];e_i=parseInt(m[1])+1;
    }else if(m=/^\[(\w+)=(\w+)\]$/gi.exec(exe[5])){
       filter_arr.push(  ['attr',m[1],m[2]]  );
    }else if(m=/^:([\-a-zA-Z]*)$/gi.exec(exe[6])){
      if(m[1]=='first-child'){s_i=0;e_i=1}
      else if(m[1]=='last-child'){only_last=true}
    }
    forEach(context,function(v,k){
        var   t=get[exe[1]].apply(v, exe[2]?[exe[2]]:['*']);
      //alert("GET FROM "+(s_i?s_i:0)+" TO "+(e_i?e_i:t.length)+"\nfilters: "+filter_arr+"\nlist:\n-----\n"+t+"\n----\nlen="+t.length)
      var item=0;
      var ee_i=(e_i?e_i:t.length);
      var ss_i=(s_i?s_i:0);
      if(only_last){ee_i=t.length;ss_i=ee_i-1;}
      for(var i=0;i<t.length;i++){
        var test_ok=1;
        for(var j=0;j<filter_arr.length;j++){
          if( filters[filter_arr[j][0]].apply(t[i],filter_arr[j].slice(1) )){
            test_ok=1;
          }else{
            test_ok=0;
            break;
          }
        }
        if(test_ok){
          if(item>=ss_i )new_context.push(t[i]);
          item++;
          if(item>=ee_i)break;
        }
      }
    });
   context=new_context;
  }
  fin=fin.concat(context);
  context = base_context;
  })
 return fin;
};


var COOKIE={
create:function (c_name,value,expiredays) {
	var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
  
},

read:function (c_name) {
	if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
},
erase:function (name) {
	COOKIE.create(name,"",-1);
}
};
var g20={
  list:null,
  getList:function(){
    g20.list=new Array();
    var t = COOKIE.read('g20')
    if(t){  
     g20.list=t.split('|');
    }
    return g20.list;  
  },
  saveList:function(){
    COOKIE.create('g20',g20.list.join('|'),7);
  },
  add:function(id){
    g20.list.push(id);
    g20.saveList()
  }
}


var play_list={
  on:window.location.hash=='#playlist',
  list:null,
  getList:function(){
    var list=[];
    var t = COOKIE.read('epl')
    if(t){  
      t=t.split('~');
      for(var i=0;i<t.length;i++){
        var itm=t[i].split('^');
        list.push([itm[0],itm[1],itm[2]]);
      }
    }
    play_list.list=list;
    return list;  
  },
  saveList:function(list){
    play_list.list=list;
    for(var i=0;i<list.length;i++){
     list[i]=list[i].join('^');
    }
    COOKIE.create('epl',list.join('~'),7);
    
  },
  is_in:function(id,type){
    for(var i=0;i<play_list.list.length;i++)
    if(play_list.list[i][0]==id && play_list.list[i][1]==type )
    return true;
    return false;
  
  },
  add:function(id,type,name){
    var list=play_list.getList();
    list.push( [id,type,name]);
    play_list.saveList(list);
    
  },
  remove:function(index){
    var pl=play_list.getList();  
    pl.splice(index,1);
    play_list.saveList( pl );
  
  },
  clear:function(){
  play_list.list=[];
  play_list.saveList( [] );
  },
  resize:function(){
    var ws=windowSize();

      NODE.css(o('playover'),{
      'right':parseInt((ws[0]-970)/2)+'px',
      'display':'block'
      });
  }
  

};



    function to_playlist_ev(){
    forEach(q('a.tops'),function(v){
    
      v.onclick=function(){
        
        var r=/(clip|wywiad)=(\d+)/gi;
        var  m = r.exec(v.href);
        
        if(m)
        play_list.add(m[2],m[1],v.getAttribute('rel') );
        update_play_list();
        
      return false;
      }
      
    });
    };


function printr(obj){
var s='';
for(i in obj){
s+=i+" = "+obj[i]+"<br>";
}
return s;
};
function addClass(c){
if(this.className.indexOf(c)==-1 )
this.className+=c;
};
function removeClass(c){
if(this)
this.className=this.className.replace(new RegExp("(\s*"+c+")","gi"),'');
};
function hasClass(c){
return this.className.indexOf(c)!=-1;
};



function init_amenu(){
    if(o('amenu'))
    o('amenu').onclick=function(e){
      var t=EVENT.target(e);
      
      if(t.nodeName=="A" && !hasClass.call(t,'cvj') ){
        if(!amenu_resp && amenu_xml)
        amenu_xml.abort();
        var url=t.href;
        if(t.href.indexOf('#')!=-1)url=t.href.substring(0,t.href.indexOf('#'));
        
        amenu_resp=false;
        var uid=o('amenu').parentNode.id.replace('cont','')
        
        o('dotted').innerHTML=pager.lo_html;
        
        amenu_xml = ajax('GET',url+"&JS="+uid,function(arg){amenu_resp=true;if(arg){o('cont'+uid).innerHTML=(arg);init_amenu();init_artb();} },'' );
        return false;
      }
    
    };
};

function init_artb(){
    forEach(q("a.artb"),function(v){
    v.onclick=function(){
    imagePreview.show(v);
    return false;
    } 
    });
};

function init_letters(){
  if(o('letters'))
  o('letters').onclick=function(e){
    var t=EVENT.target(e);
    if(t.nodeName=="A"){
      if(!letters_resp && letters_xml)
      letters_xml.abort();
      var url=t.href;
      if(t.href.indexOf('#')!=-1)url=t.href.substring(0,t.href.indexOf('#'));
      
     
      letters_resp=false;
      var uid=o('letters').parentNode.id.replace('cont','') 
      o('search_results').innerHTML=pager.lo_html
      letters_xml = ajax('GET',url+"&JS="+uid,function(arg){letters_resp=true;if(arg){o('cont'+uid).innerHTML=(arg);init_letters();init_pager();} },'' );
      return false;
    }
  
  };

};

function init_pager(){
pager.init();
var l=new Image();
l.src='static/gfx/20-0.gif';
}


var pager={
    xml:null,
    lo_html:'<img id="loading" src="static/gfx/20-0.gif" />',
    page_loaded:false,
    init:function(){
      forEach(q('div.pager'),function(v){
      if(!hasClass.call(v,'nj') )
      v.onclick=function(e){
        var t=EVENT.target(e);
          if(t.nodeName=="A"){
            if(hasClass.call(t,'p_prev') )
            pager.prev(this,t);
            else if(hasClass.call(t,'p_next') )
            pager.next(this,t);
            else
            pager.page(this,t);
          }
        return false;
      }
      });
    },
    prev:function(pgr,link){
      if(pager.getPoint(pager.getCurrent(pgr))>0 ){
      if(pager.getCurrent(pgr)==link.nextSibling){
       pager.recount(pgr,pager.getPoint(link)-2 );
       pager.submit(q('a.p_next~a',[pgr])[0]);
       pager.recount(pgr,pager.getPoint(q('a[1]',[pgr])[0]) );
      }else{
        pager.submit(q('a.cur~a',[pgr])[0]);
        pager.recount(pgr,pager.getPoint(q('a[1]',[pgr])[0]) );
      }
     }
    },
    next:function(pgr,link){
      if(pager.getPoint(pager.getCurrent(pgr))<pager.getMax(pgr)-1 ){
     if(pager.getCurrent(pgr)==link.previousSibling ){
     pager.recount(pgr,pager.getPoint(link) );
     pager.submit(q('a.p_prev+a',[pgr])[0]);
     pager.recount(pgr,pager.getPoint(q('a[1]',[pgr])[0]) );
     }else{
     pager.submit(q('a.cur+a',[pgr])[0]);
     pager.recount(pgr,pager.getPoint(q('a[1]',[pgr])[0]) );
     }
     }
    },
    page:function(pgr,link){
      
      pager.submit(link)
      pager.recount(pgr,pager.getPoint(q('a[1]',[pgr])[0]) );
    },
    recount:function(pgr,beginOn){
      var max = pager.getMax(pgr),uid=pager.getUid(pgr),curp=pager.getPoint(pager.getCurrent(pgr));
      var list=pgr.getElementsByTagName('a');
      var re=new RegExp('pager\\['+uid+'\\]=([\\d\\-]+)',"gi");
      list[0].href=list[0].href.replace(re,'pager['+uid+']='+( curp-1 )  );
      list[0].className=(curp==0?'p_prev hid':'p_prev');
      for(var i=1;i<list.length-1;i++){
        list[i].innerHTML=beginOn+i;
        list[i].href=list[i].href.replace(re,'pager['+uid+']='+( beginOn+i-1 )  );
        list[i].style.display=(beginOn+i-1>=max? 'none':'inline');

      }
       list[list.length-1].href=list[list.length-1].href.replace(re,'pager['+uid+']='+( curp+1 )  );
       list[list.length-1].className=(curp==max-1?'p_next hid':'p_next');
    },
    
    getMax:function(pgr){
      return parseInt( q('a:last-child',[pgr])[0].getAttribute('rel') );
    },
    getUid:function(node){
      if(node.nodeName=='A')
      node=node.parentNode;
      return parseInt(node.id.replace('uid',''));
    },
    getPoint:function(link){
       var re=new RegExp('pager\\['+pager.getUid(link)+'\\]=([[\\d\\-]+)',"gi");
       return parseInt(re.exec(link.href)[1]);
    },
    getCurrent:function(pgr){
      return q('a.cur',[pgr])[0];
    },
    submit:function(link){
        var max = pager.getMax(link.parentNode),point=pager.getPoint(link);
        if(point<0 || point>max || link.className=='cur')
        return;
        pager.getCurrent(link.parentNode).className='';
        link.className='cur';
        var uid=pager.getUid(link);
        if(!pager.page_loaded && pager.xml)
          pager.xml.abort();
          
          if(hasClass.call(link.parentNode,'whpager' ))
          o('search_results').innerHTML=pager.lo_html;
          else
          o('cont'+uid).innerHTML=pager.lo_html;
          
          pager.page_loaded=false;
          var url=link.href;
          if(url.indexOf('#')!=-1)url=url.substring(0,url.indexOf('#'));
          pager.xml= ajax("GET",url+"&JS="+uid,function(resp){ if(resp)o('cont'+uid).innerHTML=resp;pager.page_loaded=true; to_playlist_ev();if(o('uid'+uid).parentNode.id=='search_results'){init_pager();init_letters();} ;},'');
        
    
    }

};





function update_play_list(){
var ws=windowSize();

NODE.css(o('playover'),{
'right':parseInt((ws[0]-970)/2)+'px',
'display':'block'
});

EVENT.add(window,'resize',play_list.resize);

 var list=play_list.getList()
    var t="";
    var ml=28;

    for(var i=0;i<list.length;i++){
    if(list[i][2].length>ml)
    list[i][2]=list[i][2].substring(0,ml)+"...";
    t+='<div><a href="./?'+list[i][1]+'='+list[i][0]+'&ap&pli='+i+'#playlist">'+(pli==i?'&#9658;':'')+list[i][2]+'</a><a class="del" id="del'+i+'">X</a></div>';
    }
    
    if(list.length==0)
    t=' ';
    o('plcont').innerHTML=t;
    o('pladded').innerHTML=list.length;
    
    if(window.location.hash=='#playlist'){
    o('pl_pl').style.display='block';
    
    }
   
    if(play_list.on)
    o('pl_play').innerHTML='Zatrzymaj <span style="color:#fff; font-family: Arial;">■</span>';
    else
    o('pl_play').innerHTML='Odtwarzaj Playlistę <span style="color:#fff; font-family: Arial;">►</span>';
};


function menul1_hide(){
  var ls = q("#menu_top>li.hover")[0]
    if(ls)
    removeClass.call(ls,'hover');
    o('menu_top').style.borderBottomColor='#F04A24'
};
var g_t;
var suggest_resp=false,suggest_xml=null;
var letters_resp=false,letters_xml=null;
var amenu_resp=false,amenu_xml=null;
    function ch_o(){
      
      var ok=1;
      var msg='';
        if(!octoOK()){
        
        msg='<div style="width:290px;"><br><br><br>Aby oglądać Eska.TV musisz zainstalować wtyczke <b>Octoshape</b>.<br>Wtyczkę możesz pobrać ze strony <BR><BR><a class="btn inl" target="_blank" href="http://www.octoshape.com/plugin/get.asp?VARIANT=Time&playlink=Time.800">www.octoshape.com</a><br><br>Po zainstalowaniu wtyczki <b>Octoshape</b>, w celu jej poprawnego działania,<br> Twoja przeglądarka będzie musiala zostać ponownie uruchomiona.</div>';
        ok=0;
        }
        if(octoNeedsNewFxWmpPlugin() ){
         msg+='<br><br>Jeżeli używasz przegladarki <b>FireFox</b><br> musisz zainstalowac nową wersję wtyczki <b>Windows Media Player</b><br><br> <a class="btn inl" target="_blank" href="http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx">Pobierz nową wersje wtyczki WMP</a><br><br> Po zainstalowaniu tej wtyczki,<br> także uruchom ponownie swoją przeglądarke.';
          ok=0;
        }
        if(!ok)
        popMsg.show(msg);
        
        return ok;
    };

    var program={
      update:function(){
        if(o('program')){
        
          var uid = (o('program').parentNode.id).replace('cont','')
          
           ajax("POST","/?JS=10&pager=0&r="+Math.random(),function(resp){ if(resp)o('cont10').innerHTML=resp;setTimeout("program.update()",30*1000);program.init();},'');
          
        }
      },
      init:function(){
        forEach(q('.program[0] p'),function(v,k){
        if(v.offsetWidth<v.scrollWidth)
          {
            v.onmouseover=function (){
              if(v.p)
              v.p.stop();
              var e=v.offsetWidth-v.scrollWidth+parseInt(NODE.getStyle(v,'text-indent'));
      
              v.p=new PeriodicalExecuter(function(p){ 
                    var cur= parseInt(NODE.getStyle(v,'text-indent'));
                    cur+=Math.floor((p.val-cur)/5);
                    v.style.textIndent=cur+"px";
                    if( Math.round(cur-p.val)==0)
                    clearTimeout(p.timer);
               },1,e);
               
               
            };
            
            v.onmouseout=function (){
              
    
              if(v.p)
              v.p.stop();
              v.p=new PeriodicalExecuter(function(p){ 
                    var cur= parseInt(NODE.getStyle(v,'text-indent'));
                    cur+=Math.ceil((p.val-cur)/5);
                    v.style.textIndent=cur+"px";
                    if( Math.round(cur-p.val)==0)
                    clearTimeout(p.timer);
               },1,0);
               
            };
        }
    
   });
      
      }
      
      
}
    

/* DOM gotowy - zaczynamy */
function start_the_party(){

    
    pager.init();
   
    
    
    //if(o('program')){
    //  var uid = parseInt(o('program').parentNode.id.replace('cont',''))
    //  
    //}
     program.update();
    
    ///////top menu drops down
    forEach(q("#menu_top>li"),function(v){
    EVENT.add(v,'mouseover',function(e){
      var c=v.getElementsByTagName('ul');
      
      
      
      
      o('menu_top').style.borderBottomColor='#01ACD6';
      var ls=q("li.hover[0]",[this.parentNode])[0];
      if(ls)ls.className=ls.className.replace(/\s*hover/gi,'');
      
      if(c.length)
      this.className+=" hover";
      else
      menul1_hide();
      
      
    })
    });
    //and hides after some time
    o('menu_top').onmouseout=function(e){g_t=setTimeout("menul1_hide()",1500)};
     o('menu_top').onmouseover=function(e){clearTimeout(g_t)};
    /////////

    
   
    
    to_playlist_ev();
    
    
    o('playlist').onclick=function(e){
      var targ=EVENT.target(e);
      if(targ.className=="del"){
        var id=targ.id.replace('del','');
        if(id<pli)pli--;
        if(id==pli)pli=-1;
        play_list.remove(id);
        update_play_list();
      }
    };
    
    o('playlist').onmouseover=function(){
      var l=play_list.getList();
      if(l.length){
       o('pl_pl').style.display='block';
      
      }else{
        o('alt').className=o('alta').className='';
        alt.show('<div style="text-align:justify;">Twoja Playlista to miejsce, gdzie możesz kolekcjonować wybrane przez Ciebie hity. Wystarczy, że sefując po ESKA TV klikniesz, dostępny przy każdym hicie <img src="t.gif" class="plus" /> a numer znajdzie się na Twojej Playliście. Dzięki temu będziesz miał szybki dostęp do ulubionych kawałków. A co więcej będziesz mógł je oglądać nieustannie, ciągiem, jeden po drugim.</div> ');
      }
      
      
      if(pl_timer)
      clearTimeout(pl_timer);
      return false;
    };
    var pl_timer=null;
    o('playlist').onmouseout=function(){
      pl_timer=setTimeout("o('pl_pl').style.display='none'",700);
      alt.hide();
      return false;
    };
    
    o('pl_clear').onclick=function(){
      play_list.clear();
      update_play_list();
    };
    o('pl_play').onclick=function(){
        play_list.on=!play_list.on;
      
        update_play_list();
        
        if(play_list.on)
        nextClipPlease(-1)
      
      return false;
    
    };
    update_play_list();
    
    document.body.appendChild(NODE.make('div',{'id':'suggest'}));
    overlay.install();
    imagePreview.install();
    
    
    o('suggest').innerHTML='';
    o('q').onclick=function(e){if(o('suggest').innerHTML)o('suggest').style.display='block'};
    o('suggest').onmousedown=function(e){var t;if( (t=EVENT.target(e)).nodeName=='A' ){o('q').value=t.innerHTML;o('q').select()};};
    o('q').onblur=function(){setTimeout("o('suggest').style.display='none'",100)};
    o('q').onkeydown=function(e){
      var key=EVENT.key(e),np={40:'+',38:'~'},fp={40:':first-child',38:':last-child'};
      var sel=q("a.sel[0]",[o('suggest')])[0],nex;
      if(key in np && ( (nex=q("a.sel"+np[key]+"a",[o('suggest')])[0]) || (nex=q("a"+fp[key],[o('suggest')])[0] ) )  )nex.className='sel';
      if(key==13 && sel){this.value=sel.innerHTML;return true}
      if(key in np && sel)sel.className="";
    };
   
   o('q').onkeyup=function(e){
    var key=EVENT.key(e);
    if(key!=38 && key!=40){
      if(!suggest_resp && suggest_xml)
      suggest_xml.abort();
      suggest_resp=false;
      suggest_xml = ajax('GET','./suggest/?q='+this.value+"&JS",function(arg){suggest_resp=true;if(arg){o('suggest').innerHTML=(arg);o('suggest').style.display='block'}else{o('suggest').style.display='none'} },'' );
    }
  
  };
     
    var p=NODE.getPos(o('q'));
    NODE.css(o('suggest'),{'left':p[0]+'px','top':(p[1]+o('q').offsetHeight )+'px','width':(o('q').offsetWidth+80)+'px'}  );
    //PLAYLISTA
    
    forEach(q("a.artb"),function(v){
    v.onclick=function(){
    imagePreview.show(v);
    
    return false;
    } 
    });
    
    //if(o('vj_images'))
    forEach(q("div.video a"),function(v){
      v.onclick=function(){
      if(swfobject.hasFlashPlayerVersion("9.0.18"))
      flvPreview.show(v.href);
      else
      no_flash();
    
    return false;
    } 
    });
    
    //PROGRAM
    
    
    
   //ALT
   alt.install();
   
    forEach(q('.listed'),function(v,k){
    
    
      v.onmouseover=function(e){
        var t=EVENT.target(e);
        var r=new RegExp(/l./gi);
        var m=(v.className).match(r);
        
        if(t.nodeName=='IMG' && m && hasClass.call(t,'nl') ){
          o(alt.id).className=m[m.length-1]+'s';
          o('alta').className=m[m.length-1]+'s';
          t.parentNode.title=t.title="";
          alt.show( q('b',[t.parentNode])[0].innerHTML+"<BR><span>"+q('span',[t.parentNode])[0].innerHTML+"</span>");
        }
      };
      v.onmouseout=function(e){
        alt.hide();
      };
    
    });
    
    forEach(q('div.box'),function(v,k){
      EVENT.add(v,'mouseover',function(e){
        var t=EVENT.target(e);
       // var r=EVENT.related(e);
        //if(r && hasClass.call(r,'tops') )
       // t=r;
        
        if(hasClass.call(t,'tops') ){
            o('alta').className=o(alt.id).className='lys';
            
            var r=/(clip|wywiad)=(\d+)/gi;
            var  m = r.exec(t.href);
            
            if(m && play_list.is_in(m[2],m[1]) )
            alt.show('Ten klip już się<br> znajduje na  Twojej playliście!');
            else
            alt.show('Oglądaj hity dobrze wyselekcjonowane!<br> Jeśli podoba Ci się ten numer to dodaj go do Twojej Playlisty!');
            
            t.onmouseout=function(){
            alt.hide();
            }
            
        }
        
        
      });
      //EVENT.add(v,'mouseout',function(e){
       // var t=EVENT.target(e);
        //if(hasClass.call(t,'tops') ){
          //  alt.hide();
        //}
      //});
    });
    
    
    forEach(q('div.g20 a.rate'),function(v){
    
    v.onmouseover=function(){alt.show('Głosuj na ten utwór!');}
    v.onmouseout=function(){alt.hide();}
    v.onclick=function(){
      alt.show('<b>Twój głos został przyjęty</b>');
      var id=parseInt(this.id.replace('g',''));
      ajax("POST","g20_vote.php?id="+id,function(){g20.add(id);setOpacity(o('g'+id),30)},'' );
      return false;
    }
    });
    if(q('div.g20')[0]){
      var l=g20.getList();
     for(var i=0;i<l.length;i++)
     if(o('g'+l[i])) setOpacity(o('g'+l[i]),30);
    }
    
    
    
    init_letters();
    init_amenu();
    init_artb();
    popPlayer.install();

    
};



