jQuery(function ($) {
   mapa.init(); 
   mapa2.init(); 
   mapa3.init(); 
   mapa4.init();
   $("#kraj-cr").attr('oldvalue', $("#kraj-cr").val());
});



/* DOM ready
--------------------------------------- */
function onDomReady(f){
  var a = onDomReady, b = navigator.userAgent, d = document, w = window, c = "onDomReady", e = "addEventListener", o = "opera", r = "readyState", s = "<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r," == \"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
  a[c] = (function(o){return function(){a[c] = function(){}; for(a=arguments.callee;!a.done; a.done = 1) f(o ? o() : o)}}) (a[c]);
  if(d[e])d[e]("DOMContentLoaded",a[c],false);
  if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9)) (function(){/loaded|complete/.test(d[r])?a[c]() : setTimeout(arguments.callee,1)})();
  else if(/MSIE/i.test(b))d.write(s);
};


/* obj
--------------------------------------- */
function getObj(id) {
  var obj = document.getElementById ? document.getElementById(id) : document.all[id];  
  return obj;
};

/*
CSS Browser Selector v0.2.8
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('chrome')?'chrome webkit safari':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();


/* mapa kontaktu
--------------------------------------- */
var mapa = { 
  region: [],
    
  init: function () {
    if(!getObj('mapa')) return; 
    
    this.region[6] = 'praha';
    this.region[10] = 'jihomoravsky-kraj';
    this.region[7] = 'pardubicky-kraj';
    this.region[4] = 'moravskoslezsky-kraj';
    this.region[11] = 'kralovehradecky-kraj';
    this.region[14] = 'stredocesky-kraj';
    this.region[9] = 'vysocina';
    this.region[2] = 'jihocesky-kraj';
    this.region[1] = 'karlovarsky-kraj';
    this.region[5] = 'liberecky-kraj';
    this.region[13] = 'olomoucky-kraj';
    this.region[8] = 'plzensky-kraj';
    this.region[12] = 'ustecky-kraj';
    this.region[3] = 'zlinsky-kraj';

    this.box = getObj('mapa');
    this.box.onmouseout = this.reset;
    
    var area = this.box.getElementsByTagName('area');        
    var i = 0, count = area.length;     
    for(i; i<count; i++) {
      area[i].onmouseover = this.setup;
    }
    
    this.width = this.box.clientWidth;
    this.height = this.box.clientHeight;    
  },
  
  setup: function () {  
    var i = 0, count = mapa.region.length, k = 0; 
    for(i; i<count; i++) {
      if(this.id == mapa.region[i]) {
        k = i;
      }    
    }
             
    mapa.box.style.backgroundPosition = k < 8 ? '0px -' + (k * mapa.height) + 'px' : '-' + mapa.width + 'px -' + ((k-7) * mapa.height) + 'px';
  },
  
  reset: function() { 
    this.style.backgroundPosition = '0px 0px';
  }
}

/* mapa kontaktu HP
--------------------------------------- */
var mapa2 = { 
  region: [],
    
  init: function () {
    if(!getObj('mapa2')) return; 
    
    
    this.region[6] = 'praha';
    this.region[10] = 'jihomoravsky-kraj';
    this.region[7] = 'pardubicky-kraj';
    this.region[4] = 'moravskoslezsky-kraj';
    this.region[11] = 'kralovehradecky-kraj';
    this.region[14] = 'stredocesky-kraj';
    this.region[9] = 'vysocina';
    this.region[2] = 'jihocesky-kraj';
    this.region[1] = 'karlovarsky-kraj';
    this.region[5] = 'liberecky-kraj';
    this.region[13] = 'olomoucky-kraj';
    this.region[8] = 'plzensky-kraj';
    this.region[12] = 'ustecky-kraj';
    this.region[3] = 'zlinsky-kraj';

    this.box = getObj('mapa2');
    this.box.onmouseout = this.reset;
    
    var area = this.box.getElementsByTagName('area');        
    var i = 0, count = area.length;     
    for(i; i<count; i++) {
      area[i].onmouseover = this.setup;
    }
    
    this.width = this.box.clientWidth;
    this.height = this.box.clientHeight;    
  },
  
  setup: function () {  
    var i = 0, count = mapa2.region.length, k = 0; 
    for(i; i<count; i++) {
      if(this.id == mapa2.region[i]) {
        k = i;
      }    
    }
             
    mapa2.box.style.backgroundPosition = k < 8 ? '0px -' + (k * mapa2.height) + 'px' : '-' + mapa2.width + 'px -' + ((k-7) * mapa2.height) + 'px';
  },
  
  reset: function() { 
    this.style.backgroundPosition = '0px 0px';
  }
}

/* mapa Praha
--------------------------------------- */
var mapa3 = { 
  region: [],
    
  init: function () {
    if(!getObj('mapa3')) return; 
    
    this.region[1] = 'praha-6';
    this.region[2] = 'praha-5';
    this.region[3] = 'praha-7';
    this.region[4] = 'praha-1';
    this.region[5] = 'praha-2';
    this.region[6] = 'praha-4';
    this.region[7] = 'praha-8';
    this.region[8] = 'praha-3';
    this.region[9] = 'praha-9';
    this.region[10] = 'praha-10';

    this.box = getObj('mapa3');
    this.box.onmouseout = this.reset;
    
    var area = this.box.getElementsByTagName('area');        
    var i = 0, count = area.length;     
    for(i; i<count; i++) {
      area[i].onmouseover = this.setup;
    }
    
    this.width = this.box.clientWidth;
    this.height = this.box.clientHeight;    
  },
  
  setup: function () {  
    var i = 0, count = mapa3.region.length, k = 0; 
    for(i; i<count; i++) {
      if(this.id == mapa3.region[i]) {
        k = i;
        //alert(k);
      }    
    }
             
    mapa3.box.style.backgroundPosition = '0px -' + (k * mapa3.height) + 'px';
  },
  
  reset: function() { 
    this.style.backgroundPosition = '0px 0px';
  }
}

/* mapa Praha HP
--------------------------------------- */
var mapa4 = { 
  region: [],
    
  init: function () {
    if(!getObj('mapa4')) return; 
    
    this.region[4] = 'praha-1';
    this.region[5] = 'praha-2';
    this.region[8] = 'praha-3';
    this.region[6] = 'praha-4';
    this.region[2] = 'praha-5';
    this.region[1] = 'praha-6';
    this.region[3] = 'praha-7';
    this.region[7] = 'praha-8';
    this.region[9] = 'praha-9';
    this.region[10] = 'praha-10';

    this.box = getObj('mapa4');
    this.box.onmouseout = this.reset;
    
    var area = this.box.getElementsByTagName('area');        
    var i = 0, count = area.length;     
    for(i; i<count; i++) {
      area[i].onmouseover = this.setup;
    }
    
    this.width = this.box.clientWidth;
    this.height = this.box.clientHeight;    
  },
  
  setup: function () {  
    var i = 0, count = mapa4.region.length, k = 0; 
    for(i; i<count; i++) {
      if(this.id == mapa4.region[i]) {
        k = i;
        //alert(k);
      }    
    }
             
    mapa4.box.style.backgroundPosition = '0px -' + (k * mapa4.height) + 'px';
  },
  
  reset: function() { 
    this.style.backgroundPosition = '0px 0px';
  }
}

/* ilayer */
/* EN
function ilayerCloseBtn() {

 document.getElementById('ilayer-en').style.display = 'none';
}*/

function ilayerCloseBtn() {

 document.getElementById('ilayer').style.display = 'none';
}


/* prepocet kurzu v infobaru */
  function getValueAndSetRate( refObject, targetObject, refValue ) {
    var parsedValue;
    var parsedString;

    try {
      parsedValue = parseInt(refObject.value, 10);
      if( refObject.value == "") {
        return true;
      }
      // Value formatting.
      parsedString = Math.round(parsedValue * refValue * 1000)/1000 + "";
      parsedString = parsedString.replace(".", ",");
      if(parsedString.indexOf(",") == -1) {
        parsedString = parsedString + ",000";
      }
      if(parsedString.match("^([0-9]+),([0-9]{1})$")) {
        parsedString = parsedString + "00";
      }
      if(parsedString.match("^([0-9]+),([0-9]{2})$")) {
        parsedString = parsedString + "0";
      }
      if(parsedString.length > 8) {
        parsedString = parsedString.substr(0, 7);
      }
      if( parsedString.substr( parsedString.length - 1 , 1 ) == "," ) {
        parsedString = parsedString.substr( 0, parsedString.length - 1 );
      }
      
      document.getElementById( targetObject ).innerHTML = parsedString;
      // Non-number input check.
      if( parsedValue != refObject.value ) {
        if( (parsedValue + "") == "NaN" ) {
          refObject.value = 1;
          parsedValue = 1;
          getValueAndSetRate( refObject, targetObject, refValue );
         }
        refObject.value = parsedValue;
      }
    } catch( eException ) { 
    }
  }
