

$(function (){
    
    
   //altezza = $('.animationReady').attr('height');
   altezza = 340;
   a1 = parseInt(altezza/1.5);
   a2 = parseInt(altezza/6);
   a3 = parseInt(altezza/2);
   a4 = parseInt(altezza/4);
   
   $('.default').css({'z-index' : '3','left':($('#gallery').width()/2)-170+'px','top':'0px'});
   $('.animationReady').css({'height' : a1.toString()+'px' , 'top':  a2.toString()+'px', 'z-index' : '2'});
   $('.animationReady2').css({'height' : a3.toString()+'px' , 'top':  a4.toString()+'px','left': '-'+a4.toString()+'px','z-index' : '0'});
   $('.animationReady-1').css({'height' : a1.toString()+'px' , 'top':  a2.toString()+'px', 'left':($('#gallery').width()-a1)+'px', 'z-index' : '2'});
   $('.animationReady-2').css({'height' : a3.toString()+'px' , 'top':  a4.toString()+'px','right': '-'+a4.toString()+'px','z-index' : '1'}); 



        /*
         * da grande a medio
         */
        function ruota(){
           
            
            
     $('.default').animate({
        
    
        height :a1+'px',
        top : a2+'px',
        'margin-left' : 0+'px',
        left : 0+'px'
       
        },2000, function(){
           
         $(this).removeAttr('style');
           $(this).removeClass('default');
           $(this).addClass('animationReady');
           $(this).css({'height' : a1+'px' , 'top':  a2+'px', 'z-index' : '2'});
          /* $(this).animate({ });*/
            }     
        );
         

            
        /*
         * da medio a piccolo
         */
        $('.animationReady').animate({
        
        height : a3+'px',
        top :  a4+'px',
        //marginLeft : 0,
        left : '-'+a4+'px'
        } ,2000 , function(){
           $(this).removeAttr('style');
           $(this).removeClass('animationReady');
           $(this).addClass('animationReady2');
           $(this).css({'height' : a3+'px' , 'top':  a4+'px','left': '-'+a4+'px','z-index' : '0'});
            }
        );
        /*
        * da piccolo di sx a dx
        */
        $('.animationReady2').animate({
        
       left: 600
        } ,2000, function(){
         $(this).removeAttr('style');
           $(this).removeClass('animationReady2');
           $(this).addClass('animationReady-2');
           $(this).css({'height' : a3+'px' , 'top':  a4+'px','right': '-'+a4+'px','z-index' : '1'});
            }
        );
       /*
        * da piccolo di dx a medio di sx
        */
          $('.animationReady-2').animate({
            height : a1+'px',
            top : a2+'px',
            right : 0+'px'
        } ,2000, function(){
           $(this).removeAttr('style');
           $(this).removeClass('animationReady-2');
           $(this).addClass('animationReady-1');
           $(this).css({'height' : a1+'px' , 'top':  a2+'px','left':($('#gallery').width()-a1)+'px', 'z-index' : '2'});
            }
        );



            /*
         * da medio a grande
         */
         setTimeout(function(){
             $('.animationReady').css({'z-index' : '1'});
             $('.default').css({'z-index' : '2'});
             $('.animationReady-1').css({'z-index' : '3'});
             $('.animationReady-2').css({'z-index' : '2'});
         }, 500);

            $('.animationReady-1').animate({
            height : altezza+'px',
       //     marginRight : '-170px',
            left : ($('#gallery').width()/2)-170+'px',
            top : 0+'px'
            //left : 0
        } ,2500, function(){
        //   $(this).removeAttr('style');
           $(this).removeClass('animationReady-1');
           $(this).addClass('default');
           $(this).css({'z-index' : '3'});
        //   $(this).animate({ left :'50%'});
             controllo();
            }
        );
       
   }//////////////////////fine funzione ruota
       
    
       
       
       function ciclo(){
           $("#middle_content").fadeOut(1500);
           ruota();
         
           //setTimeout(ciclo, 5000);
       }
       controllo();
       //ciclo();
       setInterval(ciclo, 5000);
       
       
/*******************************************************************************/
        function controllo(){
        $id_contenuto = $('.default').attr('id');
        
      

        $("#middle_content").load("contenuto/home/contenuto_"+$id_contenuto+".php");
      
        $("#middle_content").fadeIn(500);
	//$("#middle").fadeOut(500, function(){$("#middle").load(id_contenuto+".php"); $(this).fadeIn()});
        }

/***********************************************************************************/		
/*
 * modulo news
 */	
  var ticker = function()
   {
     setTimeout(function(){
        
        var margin_now = $('.news div:first').css('margin-top');
        $('.news div:first').animate( {marginTop: '-93px', opacity:'0'}, 1000, function()
         {
        $(this).detach().appendTo('.news');
	$(this).css('margin-top',margin_now);
	$(this).css('opacity','1');
         });
         
         ticker();
      
    }, 3000);
   };
   
   var percorso = window.location.pathname;
   var pagina_visualizzata = percorso.substring(percorso.lastIndexOf('/') + 1); 
   
   num_news = $(".content_news").size();
   
   if(pagina_visualizzata=='' || pagina_visualizzata =='index.php'){
       if(num_news<=3){}
       else ticker();
   }
   else if (num_news <= 1 ){} else{ticker();}
  
   
 /*****************************************************************************************/
/*
 * modulo promo
*/
    
  var ticker2 = function()
   {
     setTimeout(function(){
	var margin_now = $('.content_promo div:first').css('margin-left');
        $('.content_promo div:first').animate( {marginLeft: '-490px', opacity: '0'},1500,  function()
         {
        $(this).detach().appendTo('.content_promo');
	$(this).css('margin-left',margin_now);
	$(this).css('opacity','1');
         });
         ticker2();
      }, 3000);
   };
   
    num_promo = $(".single_promo").size();
     if(num_promo<=1){}
       else ticker2();
   

////////////////////////////////////////////////////////////////////////////////       
/*
 * fade contenuto
 */
    $('.active').fadeIn(1000,
    function(){
         $('.deactive').fadeIn(1000,
         function (){
             $('#testo').fadeIn(1000)
              $("#mcs3_container").mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"fixed","yes","no",0);
             $('#menu_right').fadeIn(1000)
         }
     );
    });
    
 
 ///////////////////////////////////////////////////////////////////////////////
/*
 * select a discesa
 */

$(".webmenu").msDropDown(); //dd2 is your main CSS
   
 
 ///////////////////////////////////////////////////////////////////////////////////
 /*
 *hover barra laterale 
  */
$('#laterale').mouseenter(function(){
    $(this).animate({
         left:-1,
         opacity : 0.9
      
     
     },{duration:500,queue:false});
 });
 
 $('#laterale').mouseleave(function(){
      $(this).animate({
         left:-134,
         opacity : 0.6
     },{duration:500,queue:false});  
 });
 //////////////////////////////////////////////////////////////////////////////////////
 /*
  * menu mappa
  */
 $('#menu_mappa li').click(
    
    function(){
        top_pos = $(this).attr('position_top');
         left_pos = $(this).attr('position_left');
         $('.mappa img').animate({
             width:1000,
             top: top_pos,
             left: left_pos
        });
 });

       $('#reset').click(
       function(){
        
        $('.mappa img').animate({
             width:300,
             top:0,
             left:0
        }
        );}
        );

//////////////////////////////////////////////////////////////////////////////////
/*
 * funzione scrollbar
 */
$("#mcs3_container").mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"auto","yes","no",0);
$("#mcs30_container").mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"auto","yes","no",0);
$("#mcs2_container").mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"fixed","yes","no",0);

/////////////////////////////////////////////////////////////////////////////////
/*
 *modulo Mail amico
 */

$('.invia_amico').click(
		function(){
			
			/*visualizzo loader, shadow */
			
			$('#form_mail_amico').fadeOut(200);
                        $('#loader').fadeIn(100);
			var url = 'send_mail_amico.php';
                        
			var dati = $('#form_mail_amico').serialize();
                        //alert(dati);
			$.post( url, dati, function(data){
				//alert(data);
				if(data==1){
                                       $('#loader').fadeOut(500,function (){$('#msg_mail').fadeIn(500).html('<p style=\'font-size: 21px; text-align: center; margin-left:-25px; margin-top:45px; color: #000;\'>Messaggio Inviato</p>');
					setTimeout(chiudi_invio_mail_amico, 1500);} );
					
					
				}else{
                                        $('#loader').fadeOut(500,function (){ $('#msg_mail').fadeIn(500).html('<p style=\'font-size: 21px; text-align: center; margin-left:-25px; margin-top:40px; color: #000;\'>Problemi nell\' invio del messaggio... Riprova!</p>');
					setTimeout( problemi_invio_mail_amico, 1500);});
					
				}
			});
		});
////////////////////////////////////////////////////////////////////////////////
/*
 * hover news e promo
 */

$('.content_news').hover(
function (){
$(this).find('h3').css({'color':'#ff9900','border-bottom':'1px solid #ff9900'}); 

},function(){
$(this).find('h3').css({'color':'#000','border-bottom':'1px solid #000'});

});

$('.single_promo').hover(
function (){
$(this).find('h3').css({'color':'#ff9900','border-bottom':'1px solid #ff9900'}); 

},function(){
$(this).find('h3').css({'color':'#000','border-bottom':'1px solid #000'});

});

$('.content_tutte_news').hover(
function (){
$(this).find('p').css({'color':'#ff9900'}); 
},function(){
$(this).find('p').css({'color':'#fff'});    
});

////////////////////////////fine funzione///////////////////////////////////////
});


$(document).ready(function(e) {
try {
$("body select").msDropDown();
} catch(e) {
alert(e.message);
}
});



function page_next( pagina ){
    $("#portfolio_tutti").animate({right:980,opacity:0},1000,function(){
        $(this).css({'right':'-980px'});
        $(this).load("contenuto/portfolio/portfolio_"+id_menu_left+".php?pagina="+pagina);
        $(this).animate({right:0,opacity:1},1000);

    });
    
}

function page_next_ricerca( pagina, id_cliente, campo, sottocategoria ){
    $("#portfolio").load("contenuto/ricerca_portfolio/ricerca_portfolio_"+id_menu_left+".php?pagina="+pagina+"&id_cliente="+id_cliente+"&campo="+campo+"&sottocategoria="+sottocategoria);
}


function clear_text( action ){
    if( action == 'click'){
        if ( $('#cerca').val() == 'cerca...' ){
            $('#cerca').val('');
        }
    }
    if( action == 'blur'){
        if ( $('#cerca').val().length == 0 ){
            $('#cerca').val('cerca...');
        }
    }
}

function ricerca_portfolio_cliente( ){
    elemReg = document.getElementById('webmenu_cliente');
    id_cliente = elemReg[elemReg.selectedIndex].value;
    $("#portfolio").fadeOut(500,function(){
        $(this).load("contenuto/ricerca_portfolio/ricerca_portfolio_"+id_menu_left+".php?campo=cliente&id_cliente="+id_cliente);
        $(this).fadeIn();
    })
}

function ricerca_portfolio_categoria( ){
    elemReg = document.getElementById('webmenu_categoria');
    sottocategoria = elemReg[elemReg.selectedIndex].value;
    $("#portfolio").fadeOut(500,function(){
        $(this).load("contenuto/ricerca_portfolio/ricerca_portfolio_"+id_menu_left+".php?campo=categoria&sottocategoria="+sottocategoria);
        $(this).fadeIn();
    })
}


function problemi_invio_mail_amico(){
    
    $('#msg_mail').fadeOut(500,function(){
    apri_invio_mail_amico(); 
       });
    
}

function validate(){
        nominativo = $('#nominativo').val();
        mail = $('#mail').val();
        oggetto = $('#oggetto').val();
        richiesta = $('#richiesta').val();
        errore=0;
        $('#nominativo').css('background-image','url("images/input_contatti.png")');
        $('#mail').css('background-image','url("images/input_cerca.png")');
        $('#oggetto').css('background-image','url("images/input_contatti.png")');
        $('#richiesta').css('background-color','#FFFFFF');
       // alert(nominativo);
        if(nominativo.length==0){
            $('#nominativo').css('background-image','url("images/input_contatti_error.png")');
            errore=1;
            //alert('problema');
        }
        var espressione = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,4})$");
        if(mail.length==0 || !espressione.test(mail) ){
            $('#mail').css('background-image','url("images/input_error.png")');
            errore=1;
        }
        if(oggetto.length==0){
            $('#oggetto').css('background-image','url("images/input_contatti_error.png")');
            errore=1;
        }
        if(richiesta.length==0){
            $('#richiesta').css('background-color','#FFCC99');
            errore=1;
        }
        if(errore){
           // alert('I campi non sono stati compilati in modo corretto');
            return false;
        }
        if(!$('#pr1').attr('checked')){
            $('.privacy').css('background-color','#FFCC99');
            alert('Non e stato accettato il contrato per la privacy');          
            return false;
        }
        //alert('ok');
        return true;
    }
       

