// pozice mysi
var x = 0;
var y = 0;

document.onmousemove = alertCoord;

function alertCoord(e) {
  var xcoord, ycoord;
  if( !e ) { e = window.event; }
  if( !e ) { return; }
  if( typeof( e.pageX ) == 'number' ) {
    xcoord = e.pageX;
    ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    xcoord = e.clientX;
    ycoord = e.clientY;
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      xcoord += document.body.scrollLeft;
      ycoord += document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      xcoord += document.documentElement.scrollLeft;
      ycoord += document.documentElement.scrollTop;
    }
  //} else { return; }
  }

  x = xcoord;
  y = ycoord;

}

// konec pozice mysi


// univerzalni zobrazeni - skryti objektu
function sci_showelm(elm){
  if(document.getElementById(elm)){
    if(document.getElementById(elm).style.display == "none"){
      document.getElementById(elm).style.display = "";
    } else {
      document.getElementById(elm).style.display = "none";
    }
  }
}

// zaskrtnuti regionu z mapky
function checkreg(elm){
  if(document.getElementById('ch_' + elm)){
    if(document.getElementById('ch_' + elm).checked == true){
      document.getElementById('ch_' + elm).checked = false;
    } else {
      document.getElementById('ch_' + elm).checked = true;
    }
  }
}


// Benefit Program a Obsazenost
function bpshow(stav, recid){
  var editpos = 20;
  var ie = document.all?true:false;
  var opera = navigator.userAgent.indexOf('Opera') != -1 ? true : false;

  if(!editpos){editpos = 0}

  if((ie == true) && (opera == false)) {
    Y_pos=(y - editpos);
  } else {
    Y_pos=(y + 10 - editpos);
  }
  X_pos=(x - 310);
  if(X_pos < 0){
    X_pos = (x + 20);
  }

  document.getElementById('pbdivshow').style.top = Y_pos + 'px';
  document.getElementById('pbdivshow').style.left = X_pos + 'px';

  if(stav == "on"){

    document.getElementById('pbdivshow_info').innerHTML = document.getElementById(recid).innerHTML;

    document.getElementById('pbdivshow').style.display = "";
  } else {
    document.getElementById('pbdivshow').style.display = "none";
  }

}

// titulky obrazku
function title2script(stav, recid){
  var editpos = 20;
  var ie = document.all?true:false;
  var opera = navigator.userAgent.indexOf('Opera') != -1 ? true : false;

  if(!editpos){editpos = 0}

  if((ie == true) && (opera == false)) {
    Y_pos=(y - editpos);
  } else {
    Y_pos=(y + 10 - editpos);
  }
  X_pos=(x - 310);
  if(X_pos < 0){
    X_pos = (x + 20);
  }

  document.getElementById('pbdivshow').style.top = Y_pos + 'px';
  document.getElementById('pbdivshow').style.left = X_pos + 'px';

  if(stav == "on"){

    document.getElementById('pbdivshow_info').innerHTML = document.getElementById(recid).title;

    document.getElementById('pbdivshow').style.display = "";
  } else {
    document.getElementById('pbdivshow').style.display = "none";
  }

}


// strankovani v titulce regionu
function minikategoryregion(kategorie, oblast, stranka, lang){

  myDiv = document.getElementById('minikat' + kategorie);

  if (xmlHttp)
  {
    try
    {

      var params = "&kategorie=" + kategorie +
                   "&stranka=" + stranka +
                   "&oblast=" + oblast +
                   "&lanG=" + lang +
                   "&subakce=minikat";
      xmlHttp.open('GET', 'http://' + document.location.host + '/redakce/ajax.php?akce=lbckraj' + params, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);


    }
    catch (e)
    {
      alert("Can't connect to server 2:\n" + e.toString());
    }
  }

}

function ajaxshowrecord(record, lang){

  var ie = document.all?true:false;
  var opera = navigator.userAgent.indexOf('Opera') != -1 ? true : false;
  var verze = parseInt(navigator.appVersion);
  var vyska = 600;
  var odzhora = 50;

  if (document.documentElement && document.documentElement.scrollTop) {
    sScroll = document.documentElement.scrollTop;
  } else if (document.body) {
    sScroll = document.body.scrollTop;
  } else {
    sScroll = 0;
  }

  if(parseInt(navigator.appVersion)>3){
    if (navigator.appName=="Netscape") {
      sirkao = window.innerWidth;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      sirkao = document.body.offsetWidth;
    }
  }

  if (verze >= 4){
    vyskao = screen.height;
    vyska = vyskao - 400;
  }
  var sirka = 550;
  var odleva = (sirkao - 550) / 2;

//  if((ie == true) && (opera == false)) {
    odzhora = (odzhora + sScroll);
//  }


  document.getElementById('divshowajax').style.top = odzhora + 'px';
  document.getElementById('divshowajax').style.left = odleva + 'px';
//  document.getElementById('divshowajax').style.height = vyska + 'px';
  document.getElementById('divshowajax').style.width = sirka + 'px';

  myDiv = document.getElementById('divshowajaxobs');

  if (xmlHttp)
  {
    try
    {

      var params = "&record=" + record +
                   "&lanG=" + lang +
                   "&subakce=showrecord";
      xmlHttp.open('GET', 'http://' + document.location.host + '/redakce/ajax.php?akce=scinfo' + params, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);


    }
    catch (e)
    {
      alert("Can't connect to server 2:\n" + e.toString());
    }
  }

  document.getElementById('divshowajax').style.display = "";

}

var oldchange;
function changemapreg(changto){

  if(changto == 'sluknovsko'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63524&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'ceske_svycarsko'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63517&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'machuv_kraj'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63523&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'luzicke_hory'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63522&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'frydlantsko'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63519&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'jizerske_hory'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63520&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'cesky_raj'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63518&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else if(changto == 'krkonose'){
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63521&x=260&y=130';
    document.getElementById('a_' + changto).style.fontWeight = "bold";
    oldchange = 'a_' + changto;
  } else {
    var newimage = 'http://' + document.location.host + '/galerie/obrazky/image.php?img=63516&x=260&y=130';
    if(document.getElementById(oldchange)){
      document.getElementById(oldchange).style.fontWeight = "normal";
    }
    oldchange = '';
  }
  document.getElementById('mapa_regionu').src = newimage;

}

/**
 * Priklad pouziti  - 
 *  var slider1 = new as4u_slider();
 *  slider1.init('as4u_slider',500,true);
 *
 */  


    $(document).ready(function(){

      var slider1 = new as4u_slider();

      slider1.init('as4u_slider',800,5000,true);  

    });

function as4u_slider() {
  var slides = [];    
  var aktivni = null;
  var next = null;
  var oneTimeDelayAdd = 0;
}


as4u_slider.prototype.init = function(id,animTime,delayTime,autoplay) {

  if ($('#'+id).length > 0) {
    this.oneTimeDelayAdd = 0;
    this.options = {
        kont: $('#'+id),
        animTime: animTime ? animTime : 1000,
        delayTime: delayTime ? delayTime :1000,
        autoplay: autoplay ? autoplay : true,
        buttons: null,
        buttons_a: null
      };
  
    this.make();
  }

}

as4u_slider.prototype.make = function() {
    //neudelame z jednoho elementu dva slidery
  if (!this.options.kont.hasClass('slider-ready')) {
    var toto = this;
    this.options.buttons_a = [];
    this.slides = this.options.kont.find('.slide');
    if (this.slides.length > 0) {
      this.options.buttons = $('<div>').addClass('slide_buttons').appendTo(this.options.kont);
      for (var i = 0; i < this.slides.length; i++ ) {
        
        this.options.buttons_a[i] = $('<a>').text(i+1).appendTo(this.options.buttons);
        this.options.buttons_a[i].attr('href','javascript:;');    
        this.options.buttons_a[i].data('id', i);    
        this.options.buttons_a[i].click(function(){toto.click(this);}); 
        if (i == 0) { 
          this.options.buttons_a[i].addClass('active');
          this.aktivni = i; 
        } else {
          $(this.slides[i]).css('opacity', 0);
        }
        
        $(this.slides[i]).css('position', 'absolute');
        $(this.slides[i]).css('width', '1000');
        $(this.slides[i]).css('height', '280');
        $(this.slides[i]).css('top', 0);
        $(this.slides[i]).css('left', 0);
        $(this.slides[i]).css('zIndex', '0');
          
      }
      this.next = this.aktivni + 1;
      
      if (this.options.autoplay)
        this.animate(true);
      
    }
    
    
    this.options.kont.addClass('slider-ready'); //vse je OK - slider je ready      
  }
}
  //po kliknuti na libovolny slide button 
as4u_slider.prototype.click = function(el) {
  var id = $(el).data('id');
  
  if (id != this.aktivni) {  
    
    
    this.next = id;
    this.oneTimeDealyAdd = 3500;
    if (this.animating != true) {
      $(el).addClass('active');
      this.options.buttons_a[this.aktivni].removeClass('active');
      clearTimeout(this.timeOut);
      this.sliding();
    }
  }
}

as4u_slider.prototype.animate = function() {

  var toto = this; 
  var fce = function() {              
              toto.sliding();
              toto.oneTimeDelayAdd = 0;
          };
  this.timeOut = setTimeout(fce, parseInt(this.options.delayTime + parseInt(this.oneTimeDelayAdd)));//);

}

as4u_slider.prototype.sliding = function() {
  var toto = this;
  if (this.animating != true) {
    
    this.animating = true; 
    toto.options.buttons_a[toto.aktivni].removeClass('active');
    $(this.slides[this.aktivni]).animate({opacity: 0},this.options.animTime, 
      function() {
        $(toto.slides[toto.aktivni]).css('display','none');    
      }
    ); 
    
    var nextAktivni = this.next;
    $(this.slides[this.next]).css('display','block');
    toto.options.buttons_a[nextAktivni].addClass('active');
    $(this.slides[this.next]).animate({opacity: 1},this.options.animTime, 
      function() {
        toto.aktivni = nextAktivni;
        toto.animating = true;
        
        if (nextAktivni == toto.next) {
          toto.next++;
        } 
        if (toto.next >= toto.slides.length) {
          toto.next = 0;
        } 
        toto.animating = false;        
        if (toto.options.autoplay)
          toto.animate();
      }
    );  
  }
}




