//***************************************************************************

var timestamp = 0;
var dt = new Date();

//***************************************************************************
// cookies handling

function nameDefined(ckie,nme)
{
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}
function delBlanks(strng)
{
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}
function getCookieValue(ckie,nme)
{
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}
function testCookie(cname, cvalue) {  //Tests to see if the cookie 
   var cookie=document.cookie;           //with the name and value 
   var chkdCookie=delBlanks(cookie);  //are on the client computer
   var nvpair=chkdCookie.split(";");
   if(nameDefined(nvpair,cname))       //See if the name is in any pair
   {   
      tvalue=getCookieValue(nvpair,cname);  //Gets the value of the cookie
      if (tvalue == cvalue) return true;
	   else return false;
   }
   else return false;
}

//***************************************************************************

function open_win(id) { getElement(id).style.visibility = "visible"; }
function close_win(id) { getElement(id).style.visibility = "hidden"; }

//***************************************************************************

function set_clock()
{
  dt.setTime(timestamp * 1000);
  h = numberFormatter("00")(dt.getHours());
  m = numberFormatter("00")(dt.getMinutes());
  getElement("time").innerHTML = h + ":" + m;
  timestamp += 1;
}

function run_clock(ts)
{
  timestamp = ts;
  set_clock();
  window.setInterval(set_clock, 1000);
}

//***************************************************************************

function onl(show_actuality)
{
  if (!testCookie("first", "yes"))
  {
    var futdate = new Date();
    var expdate = futdate.getTime();
    expdate += 3600*1000;
    futdate.setTime(expdate);
    var newCookie="first=yes; ";
    newCookie += " expires=" + futdate.toGMTString();
    window.document.cookie=newCookie;

    if (show_actuality) open_win("actuality");
  }
}

//***************************************************************************
//***************************************************************************

function img_preview(fn)
{
  showElement("preview_box");
  getElement("preview_img").src = fn;
}

/********************************************************/

function hide_preview()
{
  hideElement("preview_box");
}

//***************************************************************************
//***************************************************************************

var g_orig_img = new Array();
function kolecko(text_id, image_id, src_hover)
{
  g_orig_img[text_id] = $(image_id).attr("src");
  $(text_id).mouseenter(function (evt) {
    $(image_id).attr("src", g_root + src_hover);
  });
  $(text_id).mouseleave(function (evt) {
    $(image_id).attr("src", g_orig_img[text_id]);
  });
}

$(document).ready(function() {
  kolecko("#vip1t", "#vip1i", "images/kolecko-orangeove.png");
  kolecko("#vip2t", "#vip2i", "images/kolecko-orangeove.png");
  kolecko("#mt1", "#mi1", "images/kolecko-orangeove.png");
  kolecko("#mt2", "#mi2", "images/kolecko-orangeove.png");
  kolecko("#mt3", "#mi3", "images/kolecko-orangeove.png");
  kolecko("#mt4", "#mi4", "images/kolecko-orangeove.png");
  kolecko("#onlt", "#onli", "images/kolecko-cervene.png");
  kolecko("#vnt", "#vni", "images/kolecko-orangeove.png");
  kolecko("#cent", "#ceni", "images/kolecko-orangeove.png");
  kolecko("#poptt", "#popti", "images/kolecko-orangeove.png");
  if (g_is_pension) {
    $("#bm_wellness").mouseenter(function (evt) { $("#bm_wellness_s").show(); });
    $("#bm_wellness").mouseleave(function (evt) { $("#bm_wellness_s").hide(); });
  } else {
    $("#bm_pension").mouseenter(function (evt) { $("#bm_pension_s").show(); });
    $("#bm_pension").mouseleave(function (evt) { $("#bm_pension_s").hide(); });
  }
})

