//navigazione a tab
jQuery(function( $ ){
$.localScroll.defaults.axis = 'xy';

	$('#nav,#logo').localScroll({
		target: '#contenuto_dx', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});




	
//menu delle palle
    $('#nav > div').hover(
    function () {
        var $this = $(this);
        $this.find('img').stop().animate({
            'width'     :'250px',
            'height'    :'250px',
            'top'       :'-45px',
            'left'      :'-30px',
            'opacity'   :'1.0'
        },500,'easeOutBack',function(){
            $(this).parent().find('ul').fadeIn(700);
        });

        $this.find('a:first,h2').addClass('active');
    },
    function () {
        var $this = $(this);
        $this.find('ul').fadeOut(500);
        $this.find('img').stop().animate({
            'width'     :'52px',
            'height'    :'52px',
            'top'       :'0px',
            'left'      :'0px',
            'opacity'   :'0.1'
        },5000,'easeOutBack');

        $this.find('a:first,h2').removeClass('active');
    }
);



// muovo le palle in base all'altezza
// altezza finestra monitor
ridimensiona();

function ridimensiona(){
//hack x altezza in explorer
 var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 // window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );





	//var sc_h = myHeight;
	//var sc_h = $('body div#corpo div#contenuto_dx').css('top')
	var sc_h = myHeight-510
	
	//sc_h = sc_h.replace('px','');
	//sc_h = parseInt(sc_h)
	
	

	
	
	//correzione menu e blocco testo 
	if(myHeight<680){
		sc_h = 150;
		$('body div#corpo div#contenuto_dx').css('top','118px')
		$('body div#corpo div#contenuto_dx').css('bottom','')
		
		
		$('body div#corpo div#contenuto_dx').css('height',myHeight-220)
	//	$('div.section .sub').css('height',myHeight-320)
		
	}else{
		$('body div#corpo div#contenuto_dx').css('top','')
		$('body div#corpo div#contenuto_dx').css('bottom','0')
	}


//alert(myHeight)
	if(myWidth<840){
		
		$('body div#corpo div#contenuto_dx').css('left','10px')
		$('body div#corpo div#contenuto_dx').css('right','')
		
	//	$('body div#corpo div#contenuto_dx').css('width',myWidth-20)
		$('div.section .sub').css('width',myWidth-70)
		
	}else{
		$('body div#corpo div#contenuto_dx').css('left','')
		$('body div#corpo div#contenuto_dx').css('right','0')
	}	
		
	
	//var altezza_max = ((sc_h / 2) - 90)
	var altezza_max = ((sc_h ) - 60)
	$('body div#corpo div#contenuto_dx').css('top')
	
	
	$('.m1').css('margin-top', ((altezza_max / 6) * 1) /6 + 'px')
	$('.m2').css('margin-top', ((altezza_max / 6) * 2) /5 + 'px')
	$('.m3').css('margin-top', ((altezza_max / 6) * 3) /4 + 'px')
	$('.m4').css('margin-top', ((altezza_max / 6) * 4) /3 + 'px')
	$('.m5').css('margin-top', ((altezza_max / 6) * 5) /2 + 'px')
	$('.m6').css('margin-top', ((altezza_max / 6) * 6) /1 + 'px')

	//$('div.section .sub').css('width',$('#contenuto_dx').width()-80+'px');
	//$('div.#footer').css('width',$('#contenuto_dx').width()-100+'px');

}



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





});




$(document).ready(function() {
	
	
//validazione	
	$("#form_contatti").validate({
		messages: {
			cognome: {
				required: 'Cognome obbligatorio!'
			},
			nome: {
				required: 'Nome obbligatorio!'
			},
			azienda: {
				required: 'Azienda obbligatoria!'
			},
			telefono: {
				required: 'Telefono obbligatorio!',
				number:'Puoi inserire solo numeri'
			},
			mail: {
				required: 'Indirizzo mail obbligatorio!',
				email:'Inserisci un indirizzo di posta valido'
			},
			messaggio: {
				required: 'Messaggio obbligatorio!'
			},
			privacy: {
				required: 'Privacy obbligatoria!'
			}
		}	
	});	
		
	$("#form_job").validate({
		 rules: {
		    cv_file: {
    		  required: true,
      			accept:"doc|pdf"
    		}
  		},

		
		messages: {
			job_cognome: {
				required: 'Cognome obbligatorio!'
			},
			job_nome: {
				required: 'Nome obbligatorio!'
			},
			job_telefono: {
				required: 'Telefono obbligatorio!',
				number:'Puoi inserire solo numeri'
			},
			job_mail: {
				required: 'Indirizzo mail obbligatorio!',
				email:'Inserisci un indirizzo di posta valido'
			},
			cv_file: {
				required: 'Curriculum obbligatorio!',
				accept:'Accettiamo solo pdf o doc'
			
			},
			privacy: {
				required: 'Privacy obbligatoria!'
			}
			
		}		
			

});
			new AjaxUpload('#cv', {
		action: 'lib/ajax/upload_file.php',
 		name: 'cv',
		data:{cosa:'',tab:''},
	//	autoSubmit: true,
		responseType: false,
  		onSubmit: function(file, extension) {
				$('#esito').html('')
			$('#caricamento').html('<img src="img/indicator_verybig.gif" width="22px" />')
					
		},
	
		
		onComplete : function(file,data){
		
		if(data==1){
				//errore limite massimo
				$('#caricamento').html('')
				$('#esito').html('<span>Il file supera la dimensione consentita (5MB) </span>')
				return false;
			}else if(data == 2){
				//errore estensione
				$('#caricamento').html('')
				$('#esito').html('<span>Le estensioni consentite sono DOC e PDF </span>')
				return false;
			}else if(data == 3){
				//errore estensione
				$('#caricamento').html('')
					$('#esito').html('<span>Le estensioni consentite sono DOC e PDF </span>')
				return false;
			}else{
				// ok 
				//img=data;
					
			$('#caricamento').html('')
			$('#esito').html('')
			$('#r_cv').html('<span><b>Upload eseguito correttamente</b></span>')
			$('input[name=cv_file]').val(file)
			}
		
		
			
		
				return false;
			
		}	
	});	

})



function invia_form_contatti(tipo){
		
		if (tipo == 'contatti') {
			var privacy = $('input[name=privacy]').val() ;
			

			var cognome = $('input[name=cognome]').val();
			var nome = $('input[name=nome]').val();
			var azienda = $('input[name=azienda]').val();
			var telefono = $('input[name=telefono]').val();
			var mail = $('input[name=mail]').val();
			var messaggio = $('textarea[name=messaggio]').val();
			var str = '&tipo=contatti&cognome=' + cognome + '&nome=' + nome + '&azienda=' + azienda + '&telefono=' + telefono + '&mail=' + mail + '&messaggio=' + messaggio;
		}else if(tipo == 'job'){
		//upload file
			//upload blocco immagine

	
	
		
		var privacy = document.form_newsletter.privacy.checked ;
		
			var cognome = $('input[name=job_cognome]').val();
			var nome = $('input[name=job_nome]').val();
			var telefono = $('input[name=job_telefono]').val();
			var mail = $('input[name=job_mail]').val();
			var cv = $('input[name=cv_file]').val();
			var str = '&tipo=job&cognome=' + cognome + '&nome=' + nome + '&telefono=' + telefono + '&mail=' + mail +'&cv='+cv;
	
		}
		
		
		$.ajax({
			type: "POST",
			url: "lib/ajax/contatti.php",
			data: str,
			//Evento di riuscita
				success: function(msg){				
					jAlert('Ti risponderemo nel minor tempo possibile.','Grazie');
					$('input[name=cognome]').val('')
					$('input[name=nome]').val('')
					$('input[name=mail]').val('')
					$('input[name=azienda]').val('')
					$('input[name=telefono]').val('')
					
					$('input[name=job_cognome]').val('')
					$('input[name=job_nome]').val('')
					$('input[name=job_telefono]').val('')
					$('input[name=job_mail]').val('')
						
						$('#caricamento').html('')
						$('#esito').html('')
						$('#r_cv').html('<label>Allega Curriculum  </span> </label><input type="file" name="job_curriculum" id="cv" /><span id="caricamento" >')
						$('input[name=cv_file]').vall()
		
					
					$('textarea').val('')
				},
				error:function(a,b,c,d){
					jAlert('Abbiamo riscontrato un errore. Riprova fra qualche minuto.','Errore');
				}
			})
			
			
			
			
}

