// JavaScript Document
$(document).ready(
 function()
 {
  $("#przyciski dt#produkcja a").mouseover(
    function() {
      $("#menu_show").css({ top: '120px' });
      $("#menu_show").css({ left: '650px' });
      $("#menu_show").show(400);
    });
  $("body.film #przyciski dt#produkcja a").mouseover(
    function() {
      $("#menu_show").css({ top: '10px' });
      $("#menu_show").css({ left: '450px' });
      $("#menu_show").show(400);
    });
  $("#menu_show").mouseleave(
    function() {
      $("#menu_show").hide(300);
    }); 
  $("#stopkamenu dt#produkcja2").mouseover(
    function() {
        $("#menu_show").css({ top: '560px' });
        $("#menu_show").css({ left: '300px' });
        $("#menu_show").show(400);  
    });
    $("body.film #stopkamenu dt#produkcja2").mouseover(
    function() {
        $("#menu_show").css({ top: '540px' });
        $("#menu_show").css({ left: '300px' });
        $("#menu_show").show(400);  
    });
    $("body.rysiek #stopkamenu dt#produkcja2").mouseover(
    function() {
        $("#menu_show").css({ top: '640px' });
        $("#menu_show").css({ left: '300px' });
        $("#menu_show").show(400);  
    });
    $("body.kontakt #stopkamenu dt#produkcja2").mouseover(
    function() {
        $("#menu_show").css({ top: '600px' });
        $("#menu_show").css({ left: '300px' });
        $("#menu_show").show(400);  
    });
    $("body.galeria #stopkamenu dt#produkcja2").mouseover(
    function() {
        $("#menu_show").css({ top: '420px' });
        $("#menu_show").css({ left: '300px' });
        $("#menu_show").show(400);  
    });
    $("#jg").mouseenter(
    function() {
      $("#dymek").css({ top: '80px' });
      $("#dymek #dcialo p").html('małopolskie, kieleckie, śląskie, Zakopane, okręg Bielsko-Żywiecki');
      $("#dymek").show(300);
    });
    $("#jg").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
    $("#es").mouseenter(
    function() {
      $("#dymek").css({ top: '105px' });
      $("#dymek #dcialo p").html('podkarpackie, opolskie, dolnośląskie, zachodniopomorskie, Wadowice, Andrychów, Kęty');
      $("#dymek").show(300);
    });
    $("#es").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
    $("#pj").mouseenter(
    function() {
      $("#dymek").css({ top: '135px' });
      $("#dymek #dcialo p").html('mazowieckie, łódzkie, śląskie, Radom, Wrocław, Częstochowa');
      $("#dymek").show(300);
    });
    $("#pj").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
    $("#mm").mouseenter(
    function() {
      $("#dymek").css({ top: '155px' });
      $("#dymek #dcialo p").html('lubelskie, wielkopolskie');
      $("#dymek").show(300);
    });
    $("#mm").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
    $("#pij").mouseenter(
    function() {
      $("#dymek").css({ top: '185px' });
      $("#dymek #dcialo p").html('Częstochowa, Gliwice, Rybnik, Pszczyna, Cieszyn, Wieluń');
      $("#dymek").show(300);
    });
    $("#pij").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
    $("#mw").mouseenter(
    function() {
      $("#dymek").css({ top: '205px' });
      $("#dymek #dcialo p").html('Toruń, Kujawsko-Pomorski, Pomorski i Podlaski');
      $("#dymek").show(300);
    });
    $("#mw").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
    $("#mb").mouseenter(
    function() {
      $("#dymek").css({ top: '255px' });
      $("#dymek").css({ left: '200px' });
      $("#dymek #dcialo p").html('zachodniopomorskie');
      $("#dymek").show(300);
    });
    $("#mb").mouseleave(
    function() {
      $("#dymek").hide(100);
    });
    
 });
 
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 760;
  var slides = $('.slide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
    .append('<span class="control" id="rightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
  }	
});

$(document).ready(function() {
  lightbox();
});

function lightbox() {
  var links = $('a[rel^=lightbox]');
  var overlay = $(jQuery('<div id="overlay" style="display: none"></div>'));
  var container = $(jQuery('<div id="lightbox" style="display: none"></div>'));
  var close = $(jQuery('<a href="#close" class="close">Zamknij</a>'));
  var target = $(jQuery('<div class="target"></div>'));
  var prev = $(jQuery('<a href="#prev" class="prev">Poprzednie</a>'));
  var next = $(jQuery('<a href="#next" class="next">Następne</a>'));

  $('body').append(overlay).append(container);
  container.append(close).append(target).append(prev).append(next);
  container.show().css({'top': Math.round((($(window).height() > window.innerHeight ? window.innerHeight : $(window).height()) - container.outerHeight()) / 2) + 'px', 'left': Math.round(($(window).width() - container.outerWidth()) / 2) + 'px', 'margin-top': 0, 'margin-left': 0}).hide();
  close.click(function(c) {
    c.preventDefault();
    overlay.add(container).fadeOut('normal');
  });

  prev.add(next).click(function(c) {
    c.preventDefault();
    var current = parseInt(links.filter('.selected').attr('lb-position'),10);
    var to = $(this).is('.prev') ? links.eq(current - 1) : links.eq(current + 1);
    if(!to.size()) {
      to = $(this).is('.prev') ? links.eq(links.size() - 1) : links.eq(0);
    }
    if(to.size()) {
      to.click();
    }
  });

  links.each(function(index) {
    var link = $(this);
    link.click(function(c) {
      c.preventDefault();
      open(link.attr('href'));
      links.filter('.selected').removeClass('selected');
      link.addClass('selected');
    });
    link.attr({'lb-position': index});
  });
  
  var open = function(url) {
    if(container.is(':visible')) {
      target.children().fadeOut('normal', function() {
        target.children().remove();
        loadImage(url);
      });
    } else {
      target.children().remove();
      overlay.add(container).fadeIn('normal',function(){
      loadImage(url);
      });
    }
  }
  
  var loadImage = function(url) {
    if(container.is('.loading')) { return; }
    container.addClass('loading');
    var img = new Image();
    img.onload = function() {
      img.style.display = 'none';
      
      var maxWidth = ($(window).width() - parseInt(container.css('padding-left'),10) - parseInt(container.css('padding-right'), 10)) - 40;
      var maxHeight = (($(window).height() > window.innerHeight ? window.innerHeight : $(window).height()) - parseInt(container.css('padding-top'),10) - parseInt(container.css('padding-bottom'), 10)) - 40;
      
      if(img.width > maxWidth || img.height > maxHeight) { // One of these is larger than the window
        var ratio = img.width / img.height;
        if(img.height >= maxHeight) {
          img.height = maxHeight;
          img.width = maxHeight * ratio;
        } else {
          img.width = maxWidth;
          img.height = maxWidth * ratio;
        }
      }
      
      container.animate({'width': img.width,'height': img.height, 'top': Math.round((($(window).height() > window.innerHeight ? window.innerHeight : $(window).height()) - img.height - parseInt(container.css('padding-top'),10) - parseInt(container.css('padding-bottom'),10)) / 2) + 'px', 'left': Math.round(($(window).width() - img.width - parseInt(container.css('padding-left'),10) - parseInt(container.css('padding-right'),10)) / 2) + 'px'},'normal', function(){
        target.append(img);
        $(img).fadeIn('normal', function() {
          container.removeClass('loading');
        });
      })
    }
    img.src = url;
  }
}
 
function externalLinks()
{
if (!document.getElementsByTagName) return;

var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
  var anchor = anchors[i];
  var relvalue = anchor.getAttribute("rel");

  if (anchor.getAttribute("href")) {
    var external = /external/;
    var relvalue = anchor.getAttribute("rel");
    if (external.test(relvalue)) { anchor.target = "_blank"; }
  }
}
}

window.onload = externalLinks;
 

