$(document).ready(function() {
  // externi odkazy
  $("a[@href^=http]").each(function() {
    if(this.href.indexOf(location.hostname) == -1) {
      $(this).click(function(){window.open(this.href);return false;});
    }
  });
  
  // localScroll
  $('#page').localScroll();
  
  // toggle
  $('.toggle').wrapInner('<a href="#"></a>').next().hide().end().click(function() {
    $(this).next().slideToggle();
    return false;
  });
  
  // images with caption
  $('.figure-photo a > img').each(function() {
    $this = $(this);
    if ($this.attr('alt')) { var caption = $this.attr('alt') }
    else { var caption = '&nbsp;' }
    var width = parseInt($this.attr('width'));
    var figureClass = 'figure';
    if ($this.hasClass('right')) { figureClass = 'figure-right' }
    else if ($this.hasClass('left')) { figureClass = 'figure-left' };
    $this.parent().wrap('<div class="' + figureClass + '" style="width: '+ (width + 8) +'px"></div>').attr({'rel':'lightbox','title':caption}).after('<p>' + caption + '</p>');
  });
  
});

// lightbox
$(function() {
  $('a[@rel*=lightbox]').lightBox({
  	overlayBgColor: '#000',
  	overlayOpacity: 0.3,
  	imageLoading: 'cms/jquery/images/loading.gif',
  	imageBtnClose: 'cms/jquery/images/close.gif',
  	imageBtnPrev: 'cms/jquery/images/prev.gif',
  	imageBtnNext: 'cms/jquery/images/next.gif',
  	containerResizeSpeed: 350,
  	txtImage: 'Fotografie',
  	txtOf: 'z'
   });
});

