/* (c) 2010 WWW.iKAL.CZ – All rights reserved.*/
function _ikal_kalendar(){
   this.eid=function(id){return document.getElementById(id);}
   this.trim=function(s){return s.replace(/^\s+|\s+$/g,"");}
   this.y2k=function(number){return (number < 1000) ? number + 1900 : number; }
   this.getDN=function(){var now = new Date(); return now.getDay();}
   this.getWeek=function(){
    var now = new Date();
    var year=this.y2k(now.getYear());
    var month=now.getMonth();
    var day=now.getDate();
    var when = new Date(year,month,day);
    var newYear = new Date(year,0,1);
    var offset = 7 + 1 - newYear.getDay();
    if (offset == 8) offset = 1;
    var daynum = ((Date.UTC(this.y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(this.y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;
    var weeknum = Math.floor((daynum-offset+7)/7);
    if (weeknum == 0) {
        year--;
        var prevNewYear = new Date(year,0,1);
        var prevOffset = 7 + 1 - prevNewYear.getDay();
        if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52;
    }
    return weeknum;
   }
   var ccal='000000';
   var ctxt='666666';
   var bhd='cc0000';
   var bkal='ffffff';
   var btime='999999';
   var ctime='000000';
   var csec='666666';
   var htime='22';
   var hsec='10';
   var hcal='26';
   var htxt='12';
   var showsec=1;
   var showt=1;
   var shown=1;
   var showw=1;
   var timerset=false;
   var otimec=false; var otime=false; var osec=false;
   var oday=false; var omonth=false; var oyear=false;
   var oname=false; var oweek=false;
   var timezd=':';
   var names=new Array('Svatopluk','Matěj/Matyáš','Liliana','Dorota','Alexandr');   var nm=new Array('leden','únor','březen','duben','květen','červen','červenec','srpen','září','říjen','listopad','prosinec');
   var dn=new Array('neděle','pondělí','úterý','středa','čtvrtek','pátek','sobota','nedělě');
   this.init=function(params){
      var p=params.split(',');
      for(x=0;x<p.length;x++) {
         var pcode=p[x].split(':');
         try{if(pcode[0]&&pcode[1]) {var ec=this.trim(pcode[0])+'=\''+this.trim(pcode[1])+'\';'; eval(ec);}
         }catch(err){alert(err);}
      }
   }
   this.gohome=function(){
      window.open('http://www.ikal.cz/','_self');
   }
   this.show=function(){
      var root=this.eid('ikal-kalendar');
      var blcheck=0; if(root) blcheck=root.innerHTML.indexOf('kalendář'); 
      //if(root&&blcheck>0){
         root.innerHTML=
            '<div onclick="iKAL_KALENDAR.gohome();return false">'+
            '<div id="ikal_hd" style="font-size:'+htxt+'px;background:#'+bhd+' url(http://www.ikal.cz/i/wk1.png) no-repeat;padding:0;color:#fff;height:19px;overflow:hidden"><div style="padding-top:2px;font-weight:bold">'+
            dn[this.getDN()]+
            '</div></div>'+
            '<div id="ikal_cbox" style="margin:0 1px;border:1px solid #ccc;border-top:none;background:#'+bkal+' url(http://www.ikal.cz/i/wk2.png) repeat-x top left">'+
            '<div id="ikal_aday" style="font-weight:bold;font-size:'+hcal+'px;padding:8px 0 4px 0;color:#'+ccal+'"></div>'+
            '<div id="ikal_amonth" style="font-size:'+htxt+'px;padding-bottom:1px;color:#'+ctxt+'"></div>'+
            '<div id="ikal_ayear" style="font-size:'+htxt+'px;padding:1px 0;color:#'+ctxt+'"></div>'+
            '</div>'+
            '<div style="margin:0 16px;background:#'+btime+'" id="ikal_timec"><span id="ikal_atime"></span><span id="ikal_asec"></span></div>'+
            '<div id="ikal_c2box" style="margin-top:3px;font-size:'+htxt+'px">'+
            '<div id="ikal_aname" style="font-weight:bold;color:#'+ctxt+'">'+names[0]+'</div>'+
            '<div id="ikal_aweek" style="color:#'+ctxt+'">týden '+this.getWeek()+'</div>'+
            '</div>'+
            '</div>'
            ;
         
         root.style.lineHeight='125%';
         root.style.width='90px';
         root.style.textAlign='center';
         root.style.margin='0 auto';
         root.style.cursor='pointer';
         
         this.otime=document.getElementById('ikal_atime');this.osec=document.getElementById('ikal_asec');this.oday=document.getElementById('ikal_aday');
         this.omonth=document.getElementById('ikal_amonth'); this.oyear=document.getElementById('ikal_ayear');
         this.otimec=document.getElementById('ikal_timec'); this.oname=document.getElementById('ikal_aname'); this.oweek=document.getElementById('ikal_aweek');
         root.style.textDecoration='none';
         this.otime.style.color='#'+ctime; this.osec.style.color='#'+csec;
         this.otime.style.fontSize=htime+'px'; this.osec.style.fontSize=hsec+'px';
         if(showt==false) this.otimec.style.display='none';
         if(shown==false) this.oname.style.display='none';
         if(showw==false) this.oweek.style.display='none';
         this.timerset=true;
         this.refreshtimer();
      /*}else{
         root.innerHTML='Neplatna instalace Widgetu pro kalendář www.iKAL.cz!';
      }*/
   }
   this.refreshtimer=function(){
      if(this.timerset==true) {
         var local_time = new Date();
         var hod = local_time.getHours();
         var min = local_time.getMinutes();
         var sec = local_time.getSeconds();
         var day = local_time.getDate();
         var month = local_time.getMonth();
         var year = local_time.getYear(); if(year < 2000) { year = year + 1900; }
         dz=this.timezd;this.timezd=(dz=='.'?':':'.');
         this.otime.innerHTML=(hod<10?'0':'')+hod+this.timezd+(min<10?'0':'')+min;
         if(showsec==1){this.osec.innerHTML=(sec<10?'0':'')+sec; }else{ this.osec.innerHTML='';}
         this.oday.innerHTML=day; this.omonth.innerHTML=nm[month]; this.oyear.innerHTML=year;
      }
   }
}
iKAL_KALENDAR = new _ikal_kalendar();
window.setInterval(function () {iKAL_KALENDAR.refreshtimer();}, 1000);



