function resize(){
  var winWidth = $(window).width();
  var winHeight = $(window).height();

  $("#gallerySfondo img")
    .width(winWidth)
    .height(winWidth * .67);

  if($("#gallerySfondo img").height() <= winHeight){
    $("#gallerySfondo img")
      .width(winHeight * 1.5)
      .height(winHeight);
  }

  // centro l'immagine
  var imgHeight = $("#gallerySfondo img").height();
  var margin_top = (winHeight - imgHeight)/2;
  $("#gallerySfondo img").css( 'margin-top' , margin_top);

}


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

$(document).ready(function(){
	$("#loader").fadeOut();
	$("#gallerySfondo").fadeIn();
	resize();
    

    
    if($('#gallerySfondoPreview').length>0){
        $('#gallerySfondoPreview').galleryView({
            filmstrip_size: 4,
            frame_width: 100,
            frame_height: 100,
            background_color: 'transparent',
            nav_theme: 'dark',
            border: 'none',
            show_captions:true,
            caption_text_color: 'black'
        });
    }else{
        $('#gallerySfondo').cycle({
            fx:     'fade',
            speed:  3000,
            timeout:  1,
            pager: '#navgal',
            prev: '.gallery-prev',
            next: '.gallery-next',
            after: function(currSlideElement, nextSlideElement, options, forwardFlag){
                var pag = 13;
                var current = options.currSlide;
                var tot = options.slideCount;
                if(current%pag==0){
                    for(var i=current-1 ; i >=0 ; i--){
                        $('#prew_'+i).css( 'display' , 'none');
                    }
                    for(i=current ; i <current+pag && i<tot; i++){
                        $('#prew_'+i).css( 'display' , 'block');
                    }
                }
            },
            pagerAnchorBuilder: function(index, DOMelement){
                return "<a id='prew_"+index+"' href='#' ><img src='"+DOMelement.src+"' /></a>";
            }
        });
    }
});




