  /**
   * 
   * @author Paweł Gruchociak, 2011
   * @link http://www.oneplusone.pl
   */    
            
jQuery(document).ready(function()
{

   //var $smallGallery = $("#smallGallery");
   $(".gallery").each(function(i,el)
    {

         var $bigPhotoContainer = $(this).find(".photoContainer");
           var $left = $(this).find(".prev");
           var $right = $(this).find(".next");
           //var $desc = $("#descriptions");
           var $navigation = $(this).find(".buttons");
           //var $loading = $bigPhotoContainer.find("#loading");
           var $current = $bigPhotoContainer.find(".image:first");




            $bigPhotoContainer.find(".image").hide();
            //$smallGallery.find("a").fadeTo(0, .5);

            if($left && $right)
            {
                $left.click(function(e){
                    $current.fadeOut();
                    $current = $current.prev();
                    if( !$current.size() ) $current = $bigPhotoContainer.find(".image:last");
                    $current.fadeIn();
                    e.preventDefault();
                })
                $right.click(function(e){
                    $current.fadeOut();
                    $current = $current.next();
                    if( !$current.size() ) $current = $bigPhotoContainer.find(".image:first");
                    //console.log($current);
                    $current.fadeIn();
                    e.preventDefault();
                })

                if($navigation)
                    {
                        if($bigPhotoContainer.find(".image").length>0)
                            $navigation.show();//setTimeout(enableHoverNavigation, 1000);// enableHoverNavigation();
                        else
                            $navigation.hide();
                    }


            }


            function enableHoverNavigation(){
                $bigPhotoContainer.hover(
                function(){
                   $navigation.stop(true,true).fadeIn(); 
                }
                ,
                function(){
                   $navigation.fadeOut("slow"); 
                });
                $bigPhotoContainer.trigger('mouseleave');
            }



            setTimeout(function(){$bigPhotoContainer.find(".image:first").fadeIn()}, 1000);
            //$smallGallery.find("a:first").trigger('click');

    })
  
   
  
  
  
  //---------------- footer
  
  $("#footer a[href^='mailto:']").addClass("mail");
  
  //------------------- animation
  
  var $images = $(".anim-photo").hide();
  var $img_current = $(".anim-photo:first").fadeIn();
      
    function playAnimation()
    {
       
        $img_current.stop().fadeOut(2000);
        $next = $img_current.next(".anim-photo");
        if($next.size()==0)
            $next = $(".anim-photo:first");
        
        //console.log($next);
        
//        $next.stop().css({
//            width: "500px",
//            height: "92px"
//        }).animate({
//                            width		: 600 + 'px',
//                            height		: 102 * 1.2 + 'px'
//                    },5000);
       
        $next.dequeue().fadeIn(2000);
        $img_current = $next;
        
        setTimeout(playAnimation, 11000);
    }
    
    setTimeout(playAnimation, 1000);
  

  
});
