/*
	***Ignacy Tokarczyk***
	author: Gosia Kmieć, http://mkmiec.pl/

*/

(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);		
 
    function resizeImg() {
 
      var imgwidth = bgImg.width();
      var imgheight = bgImg.height();
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var newwidth = winwidth * 0.36;
      
      bgImg.aeImageResize({height: newwidth, width: newwidth});      
      
      bgImg.parents('li').css({'width': newwidth+30+'px'});
      
      var margin = newwidth-0.1*newwidth;
      
      $('.gallery').css({'left': margin+'px'}); 
      
      var b = (newwidth-bgImg.width())/2;
      var c = bgImg.width()-30;
      bgImg.parents('span.wrap1').css({'margin-left': b+'px'});
      if (jQuery.browser.msie && (jQuery.browser.version == 6 || jQuery.browser.version == 7)) {
        bgImg.next('.caption').css({'width': c+4+'px'}); 
      }else{
        bgImg.next('.caption').css({'width': c+'px'}); 
      }
      $('.gallery .last a').css({'width': newwidth+'px', 'height': newwidth+'px'}); 
      

    } 
    
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)

/*--------------------*/

function highlight(carousel, obejctli,liindex,listate){
     $('ul.gallery li:nth-child('+ liindex +')').addClass('selected');
     $('ul.gallery li:nth-child('+ liindex +')').find('.caption').show();
     $('ul.gallery li:nth-child('+ liindex +')').ImageOverlay({ 
      overlay_color: "#fff", 
      overlay_origin: "top", 
      overlay_text_color: "#000", 
      overlay_speed: 'slow', 
      overlay_speed_out : 'slow' 
    });
    if($('.gallery .last').hasClass('selected')){ 
     $('.jcarousel-next-horizontal').hide();
    }else{
     $('.jcarousel-next-horizontal').show();
    }
};

function removehighlight(carousel, obejctli,liindex,listate){
     $('ul.gallery li:nth-child('+ liindex +')').find('.caption').hide();
     $('ul.gallery li:nth-child('+ liindex +')').removeClass('selected');     
    if($('.gallery .last').hasClass('selected')){ 
     $('.jcarousel-next-horizontal').hide();
    }else{
     $('.jcarousel-next-horizontal').show();
    }
};

/*  --------------------------  */


$(document).ready(function() {
  
  $(".page-template-mainpage-php #content").hide();
  
  $(".page-template-mainpage-php #content").before('<img src="wp-content/themes/ignacy/images/loading.png" alt="Ładowanie ... " id="loading">');
    
  $(window).load(function() {
   
    var block = document.body.offsetWidth;

    $("#content").show();
    
    $("#loading").hide();
    
    $("#loading").remove();
     
   $('ul.gallery').jcarousel({
        scroll: 1,
        animation: 700,
        itemFirstInCallback :  highlight,
	      itemFirstOutCallback : removehighlight,
	      size: $('ul.gallery li').size()+2
   });
   
   var w = $('ul.gallery').width();
   $('ul.gallery').css({'width': w*100+'px'}); 
   
   $('ul.gallery img').each(function(index) {
     $(this).fullBg();
   });

if (jQuery.browser.msie && (jQuery.browser.version == 6)) {
  Cufon('h2', {
  	letterSpacing  : '-2px'
  });
  
}else{  
  Cufon('h2', {
  	textShadow: '0 1px 1px #FFFFFF',
  	letterSpacing  : '-2px'
  });
}

  Cufon('#motto', {
  	//textShadow: '0 0 0px #ffffff'
  });
  
  $('#top-menu > li').each(function(index) {
    var a = $(this).width()-2;
    $(this).find('ul').css({'width': a+'px'}); 
  });
  
  $('#top-menu > li').each(function(index) {
    $(this).hover(
        function () {
          $(this).find('ul').hide();
          $(this).find('ul').stop(true, true).slideDown();
        },
        function () {
          $(this).find('ul').stop(true, true).slideUp();
        }
      );
  });
  
  
  });
  
  if (jQuery.browser.msie){}else{
    $('.blog .article img, .category .article img, .single .article img').each(function(index) {
      $(this).wrap('<div class="foto"><span class="wrap1"><span class="wrap">');
    });
  }
  
});



