  $(document).ready(function(){
    $(".toggle_container").hide();
    $("h3.trigger").click(function(){
      $(this).toggleClass("active").next().slideToggle("slow");
    });
  });
    $('form').bind('submit', function () {
      var inpSender = $('#sender'),
        inpEmail = $('#email'),
        inpMessage = $('#message'),
        status = $('#status'),
        error = false;

      if (inpSender.val().length <= 0 || inpSender.val() == inpSender.attr('placeholder')) {
        inpSender.addClass('error');
        if (!error) {
          inpSender.focus();
        }
        error = true;
      } else {
        inpSender.removeClass('error');
      }

      if (inpEmail.val().length <= 0 || inpEmail.val() == inpEmail.attr('placeholder')) {
        inpEmail.addClass('error');
        if (!error) {
          inpEmail.focus();
        }
        error = true;
      } else {
        inpEmail.removeClass('error');
      }

      if (inpMessage.val().length <= 0 || inpMessage.val() == inpMessage.attr('placeholder')) {
        inpMessage.addClass('error');
        if (!error) {
          inpMessage.focus();
        }
        error = true;
      } else {
        inpMessage.removeClass('error');
      }

      if (error) {
        status.removeClass('hidden').removeClass('sending');
      } else {
            if (location.host.split('.')[2] == "sk") {
              status.html('odosielám').removeClass('hidden').addClass('sending');
            } else if (location.href.split('.')[2].split('/')[1] == "en") {
              status.html('sending').removeClass('hidden').addClass('sending');
            } else {
              status.html('odesílám').removeClass('hidden').addClass('sending');
            }
        $.post('/', {
          email: inpEmail.val(),
          sender: inpSender.val(),
          message: inpMessage.val()
        }, function (j) {
          // TODO - ověřit odpověď ze serveru
          if (true) {
            if (location.host.split('.')[2] == "sk") {
              status.html('odoslané!');
            } else if (location.href.split('.')[2].split('/')[1] == "en") {
              status.html('sent!')
            } else {
              status.html('odesláno!')
            }

          inpMessage.add(inpSender).add(inpEmail).add($('#button')).attr('disabled', true);

        }
      }, 'json');
    }

    return false;
  });


  var nav = $('#scrollable');

  if (nav.length > 0) {
    nav.delegate('.scroll', 'click', function () {
      if (this.nodeName.toUpperCase() == 'A') {
        var a = $(this),
          scroll_to = $(a.attr('href'));
        if (scroll_to.length > 0) {
          $.scrollTo(scroll_to, 'slow');
        }
      }

      return false;
    });
  }

  var slideshow = $('#slideshow'),
    portfolio = $('#portfolio'),
    portfolio_list = $('#portfolio ul'),
    carousel = null,
    processing = false;

  if (portfolio.length > 0 && portfolio_list.length > 0) {
    portfolio_list.jcarousel({
      wrap: 'circular',
      animation: 1000,
      auto: 10,
      scroll: 1,
      itemFirstOutCallback: {
        onBeforeAnimation: function (e, s, i) {
          var anchor = $(s).find('a'),
            active = slideshow.find('div.active'),
            new_active = $(anchor.attr('href'));

          return switchPreview(active, new_active);
        },
        onAfterAnimation: function () {}
      }
    });

    carousel = portfolio_list.data('jcarousel');

    function switchPreview(active, new_active) {
      if (processing || new_active.length == 0 || active.length == 0) {
        return false;
      }

      if (active.attr('id') !== new_active.attr('id')) {
        processing = true;
        active.hide('fast', function () {
          active.removeClass('active');
          new_active.fadeIn('fast', function () {
            new_active.addClass('active');
            processing = false;
          });
        });
      }
      return false;
    }

    portfolio.delegate('a', 'click', function (e) {
      e.preventDefault();

      var new_active = $($(this).attr('href')),
        active = slideshow.find('div.active'),
        list = $(this).parent(),
        pos = list.attr('jcarouselindex') - 1;

      carousel.stopAuto();
      if (!carousel.animating) {
        switchPreview(active, new_active);
        carousel.scroll(pos, true);
      }
      return false;
    });
  }

  /* hover pre ie */
  $('.ie7 .hoverize, .ie6 .hoverize').bind('mouseover', function () {
    $(this).addClass('hover');
  });

  $('.ie7 .hoverize, .ie6 .hoverize').bind('mouseout', function () {
    $(this).removeClass('hover');
  });


