// JavaScript Document
$(function(){
	try{
		
		// scroll  home
		$scroll = $('.scrollable');
		$scroll.each(function(i,val){
			$($scroll[i]).scrollable({
			  size:1,
			  speed:200,
			  prev:'.prev',
			  next:'.next',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev, .next').click(function(){ return false;});
		
		$scroll0 = $('.scrollable0');
		$scroll0.each(function(i,val){
			$($scroll0[i]).scrollable({
			  size:1,
			  speed:500,
			  prev:'.prev0',
			  next:'.next0',
			  disabledClass:'off',
			  clickable: false,
			  circular: true
			}).navigator().autoscroll({
				steps: 1,
				interval:8000
			});
		});	
		$('.prev, .next').click(function(){ return false;});
		
		
		// scroll  diving
		$scroll2 = $('.scrollable2');
		$scroll2.each(function(i,val){
			$($scroll2[i]).scrollable({
			  size:1,
			  speed:200,
			  prev:'.prev2',
			  next:'.next2',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev2, .next2').click(function(){ return false;});
		
		// scroll  nice
		$scroll3 = $('.scrollable3');
		$scroll3.each(function(i,val){
			$($scroll3[i]).scrollable({
			  size:1,
			  speed:200,
			  prev:'.prev3',
			  next:'.next3',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev3, .next3').click(function(){ return false;});
		
		//scroll nice small
		$scroll4 = $('.scrollable4');
		$scroll4.each(function(i,val){
							   
			$($scroll4[i]).scrollable({
			  size:4,
			  speed:200,
			  prev:'.prev4',
			  next:'.next4',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev4, .next4').click(function(){return false;});
		
		//scroll collaboratori
		$scroll5 = $('.scrollable5b');
		$scroll5.each(function(i,val){
							   
			$($scroll5[i]).scrollable({
			  size:1,
			  speed:200,
			  prev:'.prev5b',
			  next:'.next5b',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev5b, .next5b').click(function(){return false;});
		
		//scroll collaboratori
		$scroll5 = $('.scrollable5');
		$scroll5.each(function(i,val){
							   
			$($scroll5[i]).scrollable({
			  size:1,
			  speed:200,
			  prev:'.prev5',
			  next:'.next5',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev5, .next5').click(function(){return false;});
		
		
		//scroll wantsyou
		$scroll6 = $('.scrollable6');
		$scroll6.each(function(i,val){
							   
			$($scroll6[i]).scrollable({
			  size:3,
			  speed:200,
			  prev:'.prev6',
			  next:'.next6',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev6, .next6').click(function(){return false;});
		
		//scroll wantsyou
		$scroll7 = $('.scrollable7');
		$scroll7.each(function(i,val){
							   
			$($scroll7[i]).scrollable({
			  size:3,
			  speed:200,
			  prev:'.prev7',
			  next:'.next7',
			  disabledClass:'off',
			  clickable: false,
			  onSeek:function(event, index) {
			  }
			});
		});	
		$('.prev7, .next7').click(function(){return false;});
				
		
		// Scroll contenuti
		$("#scroll2, #scroll3").jScrollPane();
		
		// slideshow
		 $('#slideshow').cycle({
				fx: 'fade',
				speed:   1500,
				timeout: 3500
			});
		 
		 // hide-show struttura
		 $('#dettStrutt').toggle(
			function(){
		  		$('#dettStruttP').show('fast');
		 	},
			function(){
				$('#dettStruttP').hide('fast');
			}
		 );
		 
		 
		 $("#nav a.aa01[title]").tooltip({ 
									position: ['top','center'],
									offset: [15,0],
									tipClass: 'tooltip'
									});
		 
		 $("#nav a.aa02[title]").tooltip({ 
									position: ['top','center'],
									offset: [10,0],
									tipClass: 'tooltipSmall'
									});
			
		// form
		$('#formo').formValidation({
		  alias	: 'id',
		  required	: 'accept',
		  err_list	: true,
		  callback	: 'callback'
		}); 
		
		$('#formo_nl input[type=text]').focus(function(){ $(this).attr('value',''); })
		
		$('#formo_nl #send').click(function(){
			var email = $("#formo_nl input[name='email']").val();
			var lang = $("#formo_nl input[name='lang']").val();
			$.ajax({
				type: "POST",
				url: "_inc_add_user_newsletter.php",
				data: "email="+email+"&lang="+lang,
				dataType:"json",
				success: function(msg){
					var data = msg;
					if(data.stato == '1'){		
						// ok;
						alert(data.message);
						$('#formo_nl input[type=text]').attr('value',''); 
					}else{
						// ko
						alert(data.message);
					}
				}
			});								
		});
		
		$('a.thumb').click(function(){
			var linkImg = $(this).attr('rel');			
			$('#showImg').hide();
			$('#loader').removeClass('none');
			$('#showImg').attr('src',linkImg);
			$('#showImg').load(function(){ $('#loader').addClass('none'); $(this).fadeIn(300); });							
		});
		
		$('a[rel=credits]').toggle(function() {
			$('#credits').removeClass('none');
		}, function() {
			$('#credits').addClass('none');
		});
		
	}catch(e){}
});



// show brochure sfogliabile
function showPDF(){
	var title = "Click to close!";
	$("body").append('<div id="overlay" title="'+title+'"></div');
	$("body").append('<div id="lightbox01" ><a href="#null" id="close" class="a01" ></a><div id="swfBrochure"></div></div>');
	//$(".layer1").html($("#newsletterform").html());
	var w = $(document).width()/2;
	var wdiv = $('#lightbox01').width()/2;
	var l = w - wdiv;
	
	// calculate top and left offset for the lightbox
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
	var lightboxLeft = arrayPageScroll[0];
	$('#lightbox01').css({top: lightboxTop+'px', left: lightboxLeft+'px'});
	//
	$("#lightbox01").css("left", l)
	$("#overlay").width($(document).width());
	$("#overlay").height($(document).height());
							
	$("#overlay").fadeIn(400, function(){ 
									   $('#lightbox01').animate({width:"920px", left:"-=460px" },1000, "linear", function(){ 
																														  /*$("#swf").fadeIn(600);*/ 
																														  	var flashvars = { };
																															var params = {wmode:'transparent'};
																															var attributes = {};
																															swfobject.embedSWF("_flash/company_profile.swf", "swfBrochure", "920", "450", "9.0.0", false,  flashvars, params, attributes);$("#lightbox01 #close").show();
																														  } );
									   //$("#layer1").fadeIn(400); 
									   });
		
		
	$("#lightbox01 #close").click(function(){
		$("#lightbox01").fadeOut(200, function(){ $(this).remove(); })
		$("#overlay").fadeOut(200, function(){ $(this).remove(); })
	});
	$("#overlay").click(function(){
		$("#lightbox01").fadeOut(200, function(){ $(this).remove(); })
		$("#overlay").fadeOut(200, function(){ $(this).remove(); })
	});
}


// collaboratori

function setCollaboratori(){
	$("#full.collaboratori div.scheda").eq(0).show();
	
	/*$('#team div.item a').click(function(){
		var n = $(this).attr('rel');
		$("#full.collaboratori div.scheda").hide();  
		$("#full.collaboratori div.scheda").eq(n).show();
	});
	
	$('#team div.item img').load(function(){						   
		$(".lightbox").lightbox();
	});*/
}



// form validator

function callback() {
    if(confirm("Click OK to submit the request or Cancel to quit!")){
		send();
	}else{
		//return false;
	}
}








// utili per posizionare i lightbox

function getPageSize(){
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;

		if (self.innerHeight) { // all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}


		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}

		var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	};


function getPageScroll(){
		var xScroll, yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}

		var arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	};
