$(document).ready(function() {
var h2Active = false;

var lastUrlPole = window.location.href.split("/");
var lastUrl = lastUrlPole[ lastUrlPole.length - 2 ];
var lastUrlPatt = new RegExp( lastUrl + "/$", "i");

$('.menu-left h2.podkategorie a').each( function() {
  var thisUrl = $(this).attr("href"); 
  if( thisUrl.match(lastUrlPatt) != null ) {
        $(this).addClass("active");
        h2Active = true;
  }
});

if( h2Active == false ) {
  $('.menu-left h2 a').each( function() {
    var thisUrl = $(this).attr("href"); 
    if( thisUrl.match(lastUrlPatt) != null ) {
        $(this).addClass("active");
     }
  });
}

if( $('h1.detail').height() > 40 )
  $('.detail-hry').css("margin-top", "-200px");
$('.clanek').eq(0).css("background", "none");
$(".toggletext").hide();
$(".toggle").click(function(){

var element = $(this);
var I = element.attr("id");

$("#slidepanel"+I).slideToggle(300);
$(this).toggleClass("active"); 

return false;
});

$("#btnAddProduct").click(function(){
$('#pridatprodukt').append('<input type="text" name="produkt[]" value="CGD"/>');
return false;
});

$('.hledani form input.text').focus(function() {
  if ( $(this).val() == "...hledaný výraz" )
    $(this).val('');
});
$('.hledani form input.text').blur(function() {
  if ( $(this).val() == "" )
    $(this).val('...hledaný výraz');
});
$('input.text').focus(function() {
  if ( $(this).val() == "...hledaný název" )
    $(this).val('');
});
$('input.text').blur(function() {
  if ( $(this).val() == "" )
    $(this).val('...hledaný název');
  
  //$('#naseptavac').css('display','none');
});

$('.jqimg').mouseenter(function() {
  var obr = $(this).attr('src');
  obr = obr.replace(".png", "A.png");
  $(this).attr('src', obr);
});
$('.jqimg').mouseleave(function() {
  var obr = $(this).attr('src');
  obr = obr.replace("A.png", ".png");
  $(this).attr('src', obr);
});  
$('.jqbg').mouseenter(function() {
  var obr = $(this).css('background-image');
  obr = obr.replace(".png", "A.png");
  $(this).css('background-image', obr);
});
$('.jqbg').mouseleave(function() {
  var obr = $(this).css('background-image');
  obr = obr.replace("A.png", ".png");
  $(this).css('background-image', obr);
});
$('.jqpos').mouseenter(function () {
  $(this).css("background-position", "left bottom");
}).mouseleave(function() {
  $(this).css("background-position", "left top");
});


$('.stred img').each(function() {
  if( $(this).width() > 508 ){
    $(this).width(508);
    var heig = Math.ceil( (500/1003) * $(this).height());
    $(this).height(heig);
    $(this).wrap('<a href="'+$(this).attr('src')+'" />');
    //$(this).after('</a>');
  }
});

$('.login-odk').removeAttr('href').css({'cursor':'pointer', 'text-decoration':'underline'});

$('.filtr-odk').click(function() {
  $('.filtr-pozadi').css({'display':'block', 'top':0, 'left':0, 'width':document.body.clientWidth, 'height': document.body.clientHeight});
  var left = (document.body.clientWidth - 700) / 2;
  var top = (window.innerHeight - 385) / 2;
  $('.filtr').css({'display':'block', 'left':left, 'top': top});
});

$('.filtr-close').click(function() {
  $('.filtr-pozadi').css('display', 'none');
  $('.filtr').css('display', 'none');
  $('.login-popup').css('display', 'none');
});
$('.filtr-pozadi').click(function() {
  $('.filtr-pozadi').css('display', 'none');
  $('.filtr').css('display', 'none');
  $('.login-popup').css('display', 'none');
});

$('.login-odk').click(function() {
  $('.filtr-pozadi').css({'display':'block', 'top':0, 'left':0, 'width':document.body.clientWidth, 'height': document.body.clientHeight});
  var left = (document.body.clientWidth - 400) / 2;
  var top = (window.innerHeight - 270) / 2;
  $('.login-popup').css({'display':'block', 'left':left, 'top': top});
});


var inte;
$('.banner-b').eq(0).css({
  'left': '197px',
  'top':'26px',
  'z-index':'15',
  'width': '340px',
  'height': '267px'
});
$('.banner-b').eq(1).css({
  'left': '75px',
  'top':'120px',
  'z-index':'10',
  'opacity': '0.8',
  'width': '185px',
  'height': '145px'
});
$('.banner-b').eq(2).css({
  'left': '27px',
  'top':'90px',
  'z-index':'5',
  'opacity': '0.6',
  'width': '120px',
  'height': '94px'
});
$('.banner-b').eq(3).css({
  'left': '60px',
  'top':'40px',
  'z-index':'0',
  'opacity': '0.5',
  'width': '110px',
  'height': '86px'
});
$('.banner-b').eq(4).css({
  'left': '555px',
  'top':'40px',
  'z-index':'5',
  'opacity': '0.5',
  'width': '110px',
  'height': '86px'
});
$('.banner-b').eq(5).css({
  'left': '585px',
  'top':'90px',
  'z-index':'5',
  'opacity': '0.6',
  'width': '120px',
  'height': '94px'
});
$('.banner-b').eq(6).css({
  'left': '482px',
  'top':'120px',
  'z-index':'10',
  'opacity': '0.8',
  'width': '185px',
  'height': '145px'
});
$('.bannery .nazev').html("<a href=\""+$('a').eq(0).attr('href')+"\">"+$('.banner-b').eq(0).attr('alt')+"</a>");

$('.vpravo').click(function() {
clearInterval(inte);
if($(this).attr('alt') == 'enable'){
  var eqa = 1;
  var popis = '';
  $(this).attr('alt', 'disable');
  $('.banner-b').each(function() {
    if (eqa > 6) eqa = 0;
    var left = $('.banner-b').eq(eqa).css('left');
    var top = $('.banner-b').eq(eqa).css('top');
    var bwid = $('.banner-b').eq(eqa).css('width');
    var height = $('.banner-b').eq(eqa).height();
    var op = 1; 
    var z =5;
    if ( top == '26px') {
      z = 15;
      op = 1;
      popis = "<a href=\"" + $(this).parent('a').attr('href') + "\">" + $(this).attr('alt') + "</a>";      
    }
    if ( top == '120px'){
      z = 10;
      op = 0.8;
    }
    if (top == '90px'){
      z = 5;
      op = 0.6;
    }
    if ( top == '40px'){
      z = 0;  
      op = 0.5;
    }
    $(this).css('z-index', z);
    $(this).animate({ 
      'left':left, 
      'top': top,
      'height': height,
      'opacity': op,
      'width': bwid
      }, 500, 
      function() { 
        //$('.vlevo').attr('alt', 'enable');
        setTimeout( function() { enable ('.vpravo'); }, 1000 );

 
        $('.bannery .nazev').html(popis);
      });
    eqa += 1;
  });
  }
  inte = setInterval("otoceni()", 5000);
  });
  
$('.vlevo').click(function() {
clearInterval(inte);
if($(this).attr('alt') == 'enable'){

  var eqa = 6;
  $(this).attr('alt', 'disable');
  $('.banner-b').each(function() {
    var left = $('.banner-b').eq(eqa).css('left');
    var top = $('.banner-b').eq(eqa).css('top');
    var bwid = $('.banner-b').eq(eqa).css('width');
    var height = $('.banner-b').eq(eqa).height();
    var op = 1;
    var z = 5;
    if ( top == '26px') {
      z = 15;
      op = 1;
      popis = "<a href=\"" + $(this).parent('a').attr('href') + "\">" + $(this).attr('alt') + "</a>"; 
    }
    if ( top == '120px'){
      z = 10;
      op = 0.8;
    }
    if (top == '90px'){
      z = 5;
      op = 0.6;
    }
    if ( top == '40px'){
      z = 0;  
      op = 0.5;
    }
    $(this).css('z-index', z);

    $(this).animate({ 
      'left':left, 
      'top': top,
      'height': height,
      'opacity': op,
      'width': bwid
      }, 500, 
      function() { 
        $('.bannery .nazev').html(popis);
         //$('.vpravo').attr('alt', 'enable');
         setTimeout( function() { enable ('.vlevo'); }, 1000 ); 
      });
    if(eqa == 6)
      eqa = 0;
    else
    eqa += 1;
  });
  }
   

inte = setInterval("otoceni()", 4000);
});


inte = setInterval("otoceni()", 4000);

$('.clanek .obsah img').each(function() {
	if( $(this).height() > 60)
	  $(this).parent().css("height" ,  "70px");
});
});

function otoceni() {
if($('.vlevo').attr('alt') == 'enable'){
  var eqa = 1;
  var popis = '';
  $('.vlevo').attr('alt', 'disable');
  $('.vpravo').attr('alt', 'disable');
  $('.banner-b').each(function() {
    if (eqa > 6) eqa = 0;
    var left = $('.banner-b').eq(eqa).css('left');
    var top = $('.banner-b').eq(eqa).css('top');
    var bwid = $('.banner-b').eq(eqa).css('width');
    var height = $('.banner-b').eq(eqa).height();
    var op = 1; 
    var z =5;
    if ( top == '26px') {
      z = 15;
      op = 1;
      popis = "<a href=\"" + $(this).parent('a').attr('href') + "\">" + $(this).attr('alt') + "</a>";      
    }
    if ( top == '120px'){
      z = 10;
      op = 0.8;
    }
    if (top == '90px'){
      z = 5;
      op = 0.6;
    }
    if ( top == '40px'){
      z = 0;  
      op = 0.5;
    }
    $(this).css('z-index', z);
    $(this).animate({ 
      'left':left, 
      'top': top,
      'height': height,
      'opacity': op,
      'width': bwid
      }, 500, 
      function() { 
        //$('.vlevo').attr('alt', 'enable');
        //$('.vpravo').attr('alt', 'enable'); 
        setTimeout( function() { enable ('.vlevo'); }, 600 );
        setTimeout( function() { enable ('.vpravo'); }, 600 );
        $('.bannery .nazev').html(popis);
      });
    eqa += 1;
  });
  }
}
function enable (kde){
  $(kde).attr('alt', 'enable');
}



