$(document).ready(function(){

//Aktuality
var aktcnt = $("#aktwhell .aktualita").length;
var aktwidth=310;
$("#aktwhell").width(aktcnt*aktwidth);
if (aktcnt>3)
  {
  //vytvorit prvky
  $('.aktuality').append('<DIV id="aktleft"><A href="" title="'+txt_predchozi+'"></A></DIV>');
  $('.aktuality').append('<DIV id="aktright"><A href="" title="'+txt_dalsi+'"></A></DIV>');
  $('#aktleft').click(function() { moveAkt(1); return false; });
  $('#aktright').click(function() { moveAkt(-1); return false; });
  }
function moveAkt(smer)
  {
  var pos = $("#aktwhell").position(); 
  posx=Math.ceil(-pos.left/aktwidth);
  if (smer==-1 && posx<aktcnt-3) $("#aktwhell").animate({left: (-posx-1)*aktwidth}, 1000 , 'swing' ); 
  if (smer==1 && posx>0) $("#aktwhell").animate({left: (-posx+1)*aktwidth}, 1000 , 'swing' ); 
  }


//akce ...roztazeni/zbaleni
var el=$('.akce > .cont');
if (el[0])
  {
  el.css('overflow','hidden');
  if (el[0].scrollHeight>el.innerHeight())
    {
    $('.akce').append('<DIV id="minmax"></DIV>');
    $('#minmax').css({
	  position:"absolute",
	  width:"13px",height:"14px",left:"147px",bottom:"3px",
	  backgroundImage: "url(images/minmax.gif)",backgroundPosition: '0px 0px',
	  cursor: 'pointer'
	  });
    var vsk=el.innerHeight();
    $('#minmax').click(function() { akceRoz(vsk); return false; });
	}
  }

function akceRoz(vyska)
  {
  var el=$('.akce > .cont');
  if (el[0].scrollHeight>el.innerHeight())
    {
    el.css('background-color','#fff');
    $('#minmax').css({backgroundPosition: '-30px 0px'});
    el.animate({height: el[0].scrollHeight}, 200 , 'swing' ); 
	}
  else
    {
    el.animate({height: vyska}, 200 , 'swing', function() {
		el.css('background-color','');
	    $('#minmax').css({backgroundPosition: '0px 0px'});
        } ); 
	}
  }


//Akce
var akcecnt = $("#akcewhell LI").length;
var akceto;
if (akcecnt>1)
  {
  //vytvorit prvky
  $("#akcewhell LI").each(function (index, domEle) { 
    $(this).css("display","none");
    $('#akceodkwhell').append('<A href="" id="akceodk'+index+'">0'+(index+1)+'</A>');
    $('#akceodk'+index).click(function() { showAkce(index,10000); return false; });
    });
  showAkce(0,6000);
  }

function showAkce(index,time)
  {
  var ii = $("#akcewhell LI").length;
  for (i=0;i<ii;i++)
    {
    if (i==index)
	  {
	  prv=$("#akcewhell LI").eq(i)
	  prv.css("display","block");
	  $("span",prv).css("display","none");
	  $("span",prv).delay(800).fadeIn(300, 'linear');
      $('#akceodkwhell A').eq(i).addClass("sel");
	  }
	else
	  {
	  $("#akcewhell LI").eq(i).css("display","none");
      $('#akceodkwhell A').eq(i).removeClass("sel");
	  }
    }
  if(akceto) clearTimeout(akceto);
  j=(index+1<ii)?index+1:0;
  akceto=setTimeout(function(){showAkce(j,6000);},time);
  }


//Akce2
//akcewhell
//akceodkwhell
var akce2cnt = $("#akce2whell LI").length;
var akce2width=180;
var akce2smer=-1;
var akce2to;
$("#akce2whell").width(akce2cnt*akce2width);
if (akce2cnt>1)
  {
  //vytvorit prvky
  $('.akce2').append('<DIV id="akceleft"><A href="" title="'+txt_predchozi+'"></A></DIV>');
  $('.akce2').append('<DIV id="akceright"><A href="" title="'+txt_dalsi+'"></A></DIV>');
  $('#akceleft').click(function() { moveAkce(1,8000); return false; });
  $('#akceright').click(function() { moveAkce(-1,8000); return false; });
  akce2to=setTimeout(function(){moveAkce(akce2smer,3000);},8000);
  }

function moveAkce(smer,time)
  {
  var pos = $("#akce2whell").position(); 
  posx=Math.ceil(-pos.left/akce2width);
  $("#motiv").html('<IMG src="data/img/mt'+a2pr[posx]+'bg.jpg"><SPAN></SPAN>');
  $("#motiv").css("display","block");
  if (smer==-1)
    {
	if (posx<akce2cnt-1) nposx=posx+1;
	else nposx=0;
	}
  if (smer==1)
    {
	if (posx>0) nposx=posx-1;
	else nposx=akce2cnt-1;
	}
  $("#motiv2").css("display","none");
  $("#motiv2").html('<IMG src="data/img/mt'+a2pr[nposx]+'bg.jpg"><SPAN></SPAN>');
  $("#akce2whell").animate({left: (-nposx)*akce2width}, 1000 , 'swing' ); 
  $("#motiv2").fadeIn(1000, 'linear');
  $("#motiv").fadeOut(1000, 'linear');

  if(akce2to) clearTimeout(akce2to);
  akce2to=setTimeout(function(){moveAkce(akce2smer,3000);},time);

  }


});





