﻿// JScript File
  
        $(document).ready(function() {

                // carico i partner
                $('#partner').load('partner.htm');        
            
                $('.content #slideshow').cycle({
		            fx: 'fade', fit: '1' , timeout:'6000'// choose your transition type, ex: fade, scrollUp, shuffle, etc...
	            });
	        // rullo finale
            var $clickleft=Math.round(($('#scroller img').length)/5)-1 ;
            var $clickright=0;
            var $w = 0;
            var $boxpadre = 0;
            var $wrapper=$('#scroller img');
            var $left = 0 ;
            var leftanimator = function(imgblock) {
                if ($clickleft > 0) {
                    $left = $left-800;
                    imgblock.animate({left:$left}, 1000);
                    $clickleft = $clickleft - 1;
                    $clickright = $clickright + 1 ; 
                }
            }

            var rightanimator = function(imgblock) {
                if ($clickright > 0) {
                    $left = $left+800;
                    imgblock.animate({left:$left},1000);
                    $clickright = $clickright - 1 ; 
                    $clickleft = $clickleft + 1;
                }
            }
            
            $('.leftarrow').click(function(event){
                rightanimator($wrapper);
            event.preventDefault();
            });
    
            $('.rightarrow').click(function(event){
            leftanimator($wrapper);
            event.preventDefault();
            });
            

            $('.prodotto').click(function() {
            
                    var _src = $(this).attr('src').replace('thumb_4_','thumb_B_');
	                var _titolo = $(this).parent().find(".descrizione").html();
	                
	                _titolo = "<p class='descrizione' style='text-align:left;' >" + _titolo +"</p>";
	                var img = new Image();
	                
	                $(img).load(function() {

                        $(this).hide();

                        $('#container').removeClass('loading').html(this);
                        //			$('.fullSizeImage').wrap('<a class="fullImageLink"></a>');
                        $('#container a').attr('href', _src);
                        $(this).css({"height": 'auto', "width": 'auto'});
                        iHeight = $(this).height();
                        lHeight = $('#container').height();

                        ////alert("1) " + iHeight );
                        ////alert("2) " + lHeight );

                        if(lHeight == iHeight) {
                        $(this).fadeIn();
                        } else {
                        tempImg = $(this);
                        $('#container').animate({height: iHeight+50}, $(this).width()).animate({width:  $(this).width()}, 600+50, function() {
                        
                        $(tempImg).fadeIn();
                     //alert(_titolo);
                        $(_titolo).appendTo("#container");                         
                        });


                        }
                      

                        $('#container').css("margin","auto");
                        $("#container").css("border","solid 1px #c6c6c6");
                        $("#container").css("background-color","#ffffff");
                        

	                
	                }).attr('src',_src); //public/foto/DSCN3331.JPG');
                
                    $('#container').show;    
                    $("#preview").show("fast");
                    

                });

            
            $('#images img').click(function() {
                

                
                //----
                
                  var _src = $(this).attr('src').replace('thumb_4_','thumb_c_');
	                var _titolo = $(this).attr('alt');
	                
	                _titolo = "<p class='descrizione' style='text-align:left;' >" + _titolo +"</p>";
	                var img = new Image();
	                
	                $(img).load(function() {

                        $(this).hide();

                        $('#container').removeClass('loading').html(this);
                        //			$('.fullSizeImage').wrap('<a class="fullImageLink"></a>');
                        $('#container a').attr('href', _src);
                        $(this).css({"height": 'auto', "width": 'auto'});
                        iHeight = $(this).height();
                        lHeight = $('#container').height();

                        ////alert("1) " + iHeight );
                        ////alert("2) " + lHeight );

                        if(lHeight == iHeight)
                        {
                            $(this).fadeIn();
                        } 
                        else 
                        {
                            tempImg = $(this);
                            $('#container').animate({height: iHeight+50}, $(this).width()).animate({width:  $(this).width()}, 600+50, function() {
                            $(tempImg).fadeIn();
                            });
                         }
                      
                     

                        $('#container').css("margin","auto");
                        $("#container").css("border","solid 1px #c6c6c6");
                        $("#container").css("background-color","#ffffff");
                        

	                
	                }).attr('src',_src); //public/foto/DSCN3331.JPG');
                  $(_titolo).appendTo("#container");          
                    
                    $("#preview").show("fast");
                
                });
            
            $('#imagepreview #preview').click(function(){
            $('#imagepreview').hide('normal');
            });
            
            // se non ci sono foto nascondo tutto 
            if ($('#images img').length <=0 ) { $('#scroller').css('display','none'); }

   });
    

