// JavaScript Document

//$(function() {
$(document).ready(function() { 
	$('#software').hover(
		function(){
			$("#software").rotate({angle:5, animateTo:0, 
				callback: function(){
					$('#softwareHover').animate( {left:'0px'} , 300, 'swing');
				}
			});
		},
		function(){
			$("#software").rotate({angle:0, animateTo:5, 
				callback: function(){
					$('#softwareHover').animate( {left:'-500px'} , 300, 'swing');
				}
			});
		}
	);
	$('#web').hover(
		function(){
			$("#web").rotate({angle:-3, animateTo:0, 
				callback: function(){-
					$('#webHover').animate( {left:'0px'} , 300, 'swing')
				}
			});
		},
		function(){
			$("#web").rotate({angle:0, animateTo:-3, 
				callback: function(){
					$('#webHover').animate( {left:'-500px'} , 300, 'swing');
				}
			});
		}
	);
	
	$('#software').rotate(5);
	$('#web').rotate(-3);
	
	
	$('.scrollToBlock').click(function(){

		// recupera l'id e la distanza del blocco verso cui eseguire lo scroll
		var nomebox = $( $(this).attr("href") );
		var position = nomebox.offset().top;
	
		// ANIMAZIONE
		// (in alcuni browser funziona "body" in altri "html")
		// not(:animated) evita che un altro click su un'altra voce del menù abbia effetto quando il precedente scroll non si è concluso
		$("body:not(:animated), html:not(:animated)").animate(
			{ scrollTop:position }, // parametri dell'animazione
			1000,                   // durata animazione (in millisecondi)
			'swing',
			function(){
				nomebox.animate({backgroundColor:'#e8856a'}, 100, function(){
					nomebox.animate({backgroundColor:'#fff'}, 100);
				});
			}
		);
		// evita che la url venga "sporcata" con l'aggiunta di "#bloccoX"
		return false;
  	});
	
	
	
	// banner animato
	$('#ca_banner1').banner({
		steps : [
			[
				//1 step:
				[{"to" : "2"}, {"effect": "slideOutBottom-slideInTop"}],
				[{"to" : "1"}, {}],
				[{"to" : "1"}, {"effect": "slideOutRight-slideInRight"}]
			],
			[
				//2 step:
				[{"to" : "2"}, {}],
				[{"to" : "1"}, {"effect":"slideOutTop-slideInTop"}],
				[{"to" : "1"}, {}]
			],
			[
				//3 step:
				[{"to" : "1"}, {"effect": "slideOutBottom-slideInTop"}],
				[{"to" : "2"}, {}],
				[{"to" : "2"}, {"effect": "zoomOut-zoomIn"}]
			],
			[
				//4 step:
				[{"to" : "1"}, {"effect": "slideOutBottom-slideInTop"}],
				[{"to" : "2"}, {}],
				[{"to" : "2"}, {"effect": "zoomOut-zoomIn"}]
			]
		],
		total_steps	: 4,
		speed : 3000
	});
});
