var method = "easeOutBounce";
var gradBg = new Array();
var centerBg = new Array();
var aboutClass = new Array();

gradBg[0] = new Image();
gradBg[0].src = "img/grad-home-kuchyne.jpg";
centerBg[0] = new Image();
centerBg[0].src = "img/center-home-kuchyne.jpg";
aboutClass[0] = 'kuchyneAbout';

gradBg[1] = new Image();
gradBg[1].src = "img/grad-home-koupelny.jpg";
centerBg[1] = new Image();
centerBg[1].src = "img/center-home-koupelny.jpg";
aboutClass[1] = 'koupelnyAbout';

gradBg[2] = new Image();
gradBg[2].src = "img/grad-home-schody.jpg";
centerBg[2] = new Image();
centerBg[2].src = "img/center-home-schody.jpg";
aboutClass[2] = 'schodyAbout';

gradBg[3] = new Image();
gradBg[3].src = "img/grad-home-hroby.jpg";
centerBg[3] = new Image();
centerBg[3].src = "img/center-home-hroby.jpg";
aboutClass[3] = 'hrobyAbout';

function showBG(idx) {
  $('.grad').eq(0).css({'background-image':'url(' + gradBg[idx].src + ')'});
  $('.center').eq(0).css({'background-image':'url(' + centerBg[idx].src + ')'});
}

function moveArrow(id){
  vpos = id * 65;
  $('.arrow').animate({'top':(1*78+vpos)+'px'}, {duration: 750, easing: method});
}

$(function(){

   $("a[rel='external']").attr({target: "_blank"});
   $("ul.partneri li a").attr({target: "_blank"});

  // spusteni karuselu podobnych produktu
    var futureLeft = 0;
    function showNavig() {
      var left = parseInt($('#photoCarousel ul').css("left"));
      var size = -($('#photoCarousel ul').width() - 4 * 116);
      futureLeft = left;
      if(left != 0)
        $('.prevCarousel a').show();
      else
        $('.prevCarousel a').hide();
      if(left <= size + 580)
        $('.nextCarousel a').hide();
      else
        $('.nextCarousel a').show();
    }

    $('.prevCarousel a').click( function () { //posun doleva
      if(futureLeft < 0) {
        futureLeft += 580;
        $('#photoCarousel ul').animate({left: '+=580'}, 700, showNavig);
        var page = parseInt($('.countInfo span').text())-1;
        $('.countInfo span').text(page);
      }
      $(this).blur();
      return false;
    });
    $('.nextCarousel a').click( function () { //posun doprava
      var size = -($('#photoCarousel ul').width() - 4 * 116);
      if(futureLeft > size + 580) {
        futureLeft -= 580;
        $('#photoCarousel ul').animate({left: '-=580'}, 700, showNavig);
        var page = parseInt($('.countInfo span').text())+1;
        $('.countInfo span').text(page);
      }
      $(this).blur();
      return false;
    });
    $('#photoCarousel ul li a').click( function () {    //zmena velke fotky
      var href = $(this).children('img').attr('src');
      href = href.replace('_s.jpg','.jpg');
      $('#bigPhoto img').attr('src', (href));
      href = href.replace('.jpg','_f.jpg');
      $('.photoDownload a').attr('href', (href));
      $(this).blur();
      return false;
    });
  
  //pouze pro IE6, resi hover menu a polozek v contentu
    function IE6Hovers() {
      if ($.browser.msie && $.browser.version == '6.0') {
        $(".top ul li a").height('79px');   //zuzeni menu
        
        $(".top-btn a").hover(function () {   //hover butonu vzornik v menu
          $(this).children("img").css("margin-top","-115px");
        }, function () {
          $(this).children("img").css("margin-top","0px");
        });
      }
    }
    
  //zprovozneni hoveru pro IE6
    IE6Hovers();

  //zachytava zmenu velikosti okna
    $(window).resize(resizeGradByWindow);
  
  //uvodni velikost okna
    var win = $(window).height();
    resizeGrad();

  //funkce pro zjisteni celkove vysky (vcetne paddingu)
    function heightAndPadding(s) {
      return $(s).height() + parseInt($(s).css("padding-top")) + parseInt($(s).css("padding-bottom"));
    }
  
  //funkce pro prodluzovani ".grad" pri zmene obsahu
    function resizeGrad() {
      var sidebar = heightAndPadding(".sidebar") + heightAndPadding(".footer") + parseInt($('.sidebar').css("margin-top"));
      var content = heightAndPadding(".content") + heightAndPadding(".footer") + parseInt($('.content').css("margin-top"));
      $(".center").height(Math.max(sidebar, content, win)-1);
    }

  //funkce pro prodluzovani ".grad" pri zmene velikosti okna
    function resizeGradByWindow() {
      var sidebar = heightAndPadding(".sidebar") + heightAndPadding(".footer") + parseInt($('.sidebar').css("margin-top"));
      var content = heightAndPadding(".content") + heightAndPadding(".footer") + parseInt($('.content').css("margin-top"));
      win = $(window).height();
      $(".center").height(Math.max(sidebar, content, win)-1);
    }

  //kontakt - form
    $('#trap').val(7);
    $('#trap').parent('p').hide();
    //$('#trap').prev('label').hide();
    //$('#trap').hide();

    $('input.submit').hover(function () {
      $(this).css('background-position', 'bottom left');
    }, function () {
      $(this).css('background-position', 'top left');
    });

  //homepage
    $('.accordeon h3 a').click(function(){
      $(this).blur();
      if( !$(this).hasClass('unfolded') ){
        $('.card').removeClass('unfolded');
        $('.card-in').slideUp(500);
        $(this).parent().parent().addClass('unfolded');
        var idx = $('.accordeon h3 a').index(this);
        showBG(idx);
        moveArrow(idx);
        $('.card-in').eq(idx).slideDown(500);

        $('.content .about').addClass('no');
        $('.content .' + aboutClass[idx]).removeClass('no');
      }
      return false;
    });

    $('.card-in').hide();
    $('.card').eq(0).addClass('unfolded');
    $('.card-in').eq(0).slideDown(500);

    jQuery.fn.inicializeSlideShow = function() {
      var count = $(this).children('.step').size();
      var position = 1;
      $(this).children('.step').hide();
      $(this).children('.step1').show();

      $(this).children('.navig').children('.count').html('<span>1</span>/' + count);

      var thisSlideShow = $(this);

      $(this).children('.navig').children('.next').click(function (e) {
        position += 1;
        if(position > count) position = 1;
        $(thisSlideShow).children('.step').hide();
        $(thisSlideShow).children('.step' + position).show();
        $(thisSlideShow).children('.navig').children('.count').children('span').html(position);
        e.preventDefault();
      });

      $(this).children('.navig').children('.prev').click(function (e) {
        position -= 1;
        if(position < 1) position = count;
        $(thisSlideShow).children('.step').hide();
        $(thisSlideShow).children('.step' + position).show();
        $(thisSlideShow).children('.navig').children('.count').children('span').html(position);
        e.preventDefault();
      });
    }


    $('.slideShow').inicializeSlideShow();




});

