/*!
 * Parts of the code inspired by jquery
 * http://jquery.com/
 */


function ShowImg(IMGPATH, PAGETITLE, IMGDESCRIPTION)
{
	var URL
	
	initWidth  = 250;
	initHeight = 150;
	
	xPos = (screen.availWidth - initWidth) / 2;
	yPos = (screen.availHeight - initHeight) / 2;
	
	URL='/showimg.asp?imgpath='+IMGPATH+'&pagetitle='+PAGETITLE+'&imgdescription='+IMGDESCRIPTION;
	window.open(URL,'','status=no,scrollbars=yes,resizable=yes,width='+initWidth+',height='+initHeight+',top='+yPos+',Left='+xPos)
}



function objGet(x) 
{
	if (typeof x != 'string') return x;
	else if (Boolean(document.getElementById)) return document.getElementById(x);
	else if (Boolean(document.all)) return eval('document.all.'+x);
	else return null;
}


function objSetStyle (obj,prop,val)
{
	var o = objGet(obj);
	if (o && o.style) 
	{
		eval ('o.style.'+prop+'="'+val+'"');
		return true;
	}
	else 
		return false;
}


function objDisplay (obj,on,type) 
{
	if (on && !type) type = 'block';
	return objSetStyle(obj,'display',(on) ? type:'none');
}


function browserSpec()
{ 
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.ff=(this.agent.indexOf("Firefox")>-1);
	this.ns6=(!ff && this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.mac=this.agent.indexOf("Mac")>-1;

	return this
}


function zmenaBarvy (id, barva1, cas1, barva2, cas2)
{
  if (document.getElementById)
  {
    document.getElementById(id).style.color = barva1;
	setTimeout('zmenaBarvy("' +  id + '","' + barva2 + '",' + cas2 + ',"' + barva1 + '",' + cas1 + ')', cas1);
  }
  else if (document.all)
  {
    document.all[id].style.color = barva1;
	setTimeout('zmenaBarvy("' +  id + '","' + barva2 + '",' + cas2 + ',"' + barva1 + '",' + cas1 + ')', cas1);
  }
}



var timerID = null; 
var timerRunning = false; 

function dispDifTime() { 

DifDays = 0;
DifHours = 0;
DifMinutes = 0;
DifSeconds = 0;

DateMin = new Date ("march 1, 2009");
DateMax = new Date ("april 1, 2009");

DateFrom = new Date;
DateTo = new Date("march 31, 2009") 
DateTo.setHours(23,59,59,0);

msPerDay = 24 * 60 * 60 * 1000 ; 

msLeft = (DateTo.getTime() - DateFrom.getTime()); 
msLeftBeforeDays = msLeft;

DifDays = Math.floor (msLeft/msPerDay);
msLeft = msLeft - (DifDays*msPerDay);

msLeftBeforeHours = msLeft;

tmpHoursText = '*** msLeft='+msLeft; 
DifHours = Math.floor(msLeft/(60*60*1000));
tmpHoursText = tmpHoursText  + ' DifHours='+DifHours + ' ';
msLeft = msLeft - (DifHours*(60*60*1000));

msLeftBeforeMinutes = msLeft;

DifMinutes = Math.floor(msLeft/(60*1000));
msLeft = msLeft - (DifMinutes*(60*1000));

msLeftBeforeSeconds = msLeft;
DifSeconds = Math.floor(msLeft/(1000));

if (DifDays > 4) DaysText = "dnů";
else{
 if (DifDays > 1) DaysText = "dny";
 else{
  if (DifDays == 1) DaysText = "den";
  else{
   if (DifDays == 0) DaysText = "dnů";
  }
 }
}   

if (DifHours > 4) HoursText = "hodin";
else{
 if (DifHours > 1) HoursText = "hodiny";
 else{
  if (DifHours == 1) HoursText = "hodina";
  else{
   if (DifHours == 0) HoursText = "hodin";
  }
 }
}   

if (DifMinutes > 4) MinutesText = "minut";
else{
 if (DifMinutes > 1) MinutesText = "minuty";
 else{
  if (DifMinutes == 1) MinutesText = "minuta";
  else{
   if (DifMinutes == 0) MinutesText = "minut";
  }
 }
}   

if (DifSeconds > 4) SecondsText = "vteřin";
else{
 if (DifSeconds > 1) SecondsText = "vteřiny";
 else{
  if (DifSeconds == 1) SecondsText = "vteřina";
  else{
   if (DifSeconds == 0) SecondsText = "vteřin";
  }
 }
}   

ResultText = '';
if (DifDays > 0) {
  ResultText = DifDays + ' ' + DaysText;
  NextText = ", "
}
else
{   
  NextText = ""
}

if (DifHours > 0) {
  ResultText = ResultText + NextText + DifHours + ' ' + HoursText;
  NextText = ", "
}
else
{   
  if (ResultText == "") NextText = "";
  else NextText = ", ";
}

if (DifMinutes > 0) {
  ResultText = ResultText + NextText + DifMinutes + ' ' + MinutesText;
  NextText = ", "
}
else
{   
  if (ResultText == "") NextText = "";
  else NextText = ", ";
}

if (DifSeconds > 0) ResultText = ResultText + NextText + DifSeconds + ' ' + SecondsText;
ResultText = ResultText + '.';

if ((DateFrom < DateMax) && (DateFrom > DateMin)) { 
 if(document.all){
      document.getElementById('difTimeText').innerText = ResultText;
 } 
 else{
     document.getElementById('difTimeText').textContent = ResultText;
 }
}



timerID = setTimeout("dispDifTime()",1000); 
timerRunning = true; 
} 

var timerID = null; 
var timerRunning = false; 
function stopclock () { 
if(timerRunning) 
clearTimeout(timerID); 
timerRunning = false; 
} 

function stopClock() { 
        stopclock();     
        return; 
} 

function startclock () { 
stopclock(); 
dispDifTime(); 
} 

$(document).ready(function() {


    if (!Array.indexOf) {
      Array.prototype.indexOf = function (obj, start) {
        for (var i = (start || 0); i < this.length; i++) {
          if (this[i] == obj) {
            return i;
          }
        }
      };
    }


  $.navi  = {
    eventClass: '.keynav',
    focusClass: '.withfocus',
    //  CACHE INDICES
    last: 0,
    crnt: 0,
    //  REF CURRENTLY VISIBLE LIST ITEMS
    visibles:  function () {
      return jQuery.makeArray($( $.navi.eventClass + ':visible'));
    },
    reset: function () {
      $.navi.last = 0;
      $.navi.crnt = 0;

      $($.navi.eventClass)
        .removeClass($.navi.focusClass.substr(1, $.navi.focusClass.length));
      $('html,body')
        .scrollTop('0');
    },

    navGoto: function() {
      if ( $($.navi.focusClass).children().find('a').length ) {
        location.href = $($.navi.focusClass).children().find('a').attr('href');
        return;
      }
      location.href = $($.navi.focusClass).children('a').attr('href');
    },

    getPos: function (_element)  {
      var l = 0, t  = 0, w = $.navi.pInt($.css(_element,'width')), h = $.navi.pInt($.css(_element,'height'));

      while (_element.offsetParent){
          l += _element.offsetLeft + (_element.currentStyle ? $.navi.pInt(_element.currentStyle.borderLeftWidth):0);
          t += _element.offsetTop  + (_element.currentStyle ? $.navi.pInt(_element.currentStyle.borderTopWidth):0);
          _element = _element.offsetParent;
      }

      l += _element.offsetLeft + (_element.currentStyle ? $.navi.pInt(_element.currentStyle.borderLeftWidth):0);
      t += _element.offsetTop  + (_element.currentStyle ? $.navi.pInt(_element.currentStyle.borderTopWidth):0);

      var cx = Math.round(t+(h/2)), cy = Math.round(l+(w/2));

      return {x:l, y:t, w:w, h:h, cx:cx, cy:cy};
    },

    pInt: function (v) {
      v = parseInt(v, 10);
      return isNaN(v) ? 0 : v;
    },

    getClosest: function(_current,_quad) {
      var closest, od = 1000000, nd = 0, found = false;

      for(i=0;i<_quad.length;i++) {
        var _element  = _quad[i];
        nd = Math.sqrt(Math.pow(_current.pos.cx-_element.pos.cx,2)+Math.pow(_current.pos.cy-_element.pos.cy,2));


        if(nd < od) {
          closest = _element;
          od      = nd;
          found   = true;
        }
      }

      return closest;
    },

    quad: function(_current, fQuad) {

      var $visibles = $.navi.visibles(),
          _visible  = '',
          quad      = [];

      for( var i = 0, _len  = $visibles.length; i <  _len; i++ ) {
        _visible = $visibles[i];

        if(_current == _visible) {
          continue;
        }

        _current.pos  = $.navi.getPos(_current);
        _visible.pos  = $.navi.getPos(_visible);


        if(  fQuad( (_current.pos.cx - _visible.pos.cx),(_current.pos.cy - _visible.pos.cy)) ) {
          quad.push(_visible);
        }
      }
      return quad;
    }
  };
    

  jQuery("#choice > ul > li.choice-item").each(function(){
    var item;
  if ( jQuery(this).has("ul").length ) {
      item = jQuery("<span class='node'>+</span>").click(function(e){
        jQuery(this)
          .text( jQuery(this).text() === "+" ? "-" : "+" )
          .parent().next().toggle();
        return false;
      });
      
      if (/actual-item/.test(this.className)) {
        item.text('-');
      } else {
        jQuery(this).find(".sub").hide();
      }
      
    } else {
      item = jQuery("<span class='node'>&nbsp;</span>");
    }

    jQuery(this).children("a").prepend( item );
  });


  jQuery("#choice > ul > li.choice-item > ul > li").each(function(){
    var item; 
  if ( jQuery(this).has("ul").length ) {
      item = jQuery("<span class='node'>+</span>").click(function(e){
        jQuery(this)
          .text( jQuery(this).text() === "+" ? "-" : "+" )
          .parent().next().toggle();
        return false;
      });
      
      if (/actual-item/.test(this.className)) {
        item.text('-');
      } else {
        jQuery(this).find(".sub").hide();
      }
      
    } else {
      item = jQuery("<span class='node'>&nbsp;</span>");
    }

    jQuery(this).children("a").prepend( item );
  });

});

