$(document).ready(function(){

	activity = new Home();
	actualPage = 'test';

	BrowserDetect.init()
	
	setTimeout(function(){
		retro(BrowserDetect.browser, BrowserDetect.version);
	}, 600);

	var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() )   ) );
	$('#page-wrap').css({height: maxVerticalSpace - ( parseInt( $('#page-wrap').css('padding-top') ) * 2 ) +'px'});

	resizeLayout.general();
	//resizeLayout.footer();	
		
	var intervalID = window.setInterval(function(){resizeLayout.general();}, 1000);
	var intervalID = window.setInterval('resizeLayout.footer()', 1000);
				
	$(window).resize(function() {
		resizeLayout.general();
		resizeLayout.footer();
	});


	$('a').live('click', function(){

		if(isAnimating){
			return false;
		}

			var page = $(this).attr('href').replace(base_url, ''),
				image = $(this).attr('alt'),
				idWork = $(this).attr('idWork');		
				var pages = page.split('/');
				

				if( pages[1] == actualPage || isAnimating == true){
					return false;
				}
				
				actualPage = pages[1];
				$('.work').removeClass('work');
				$(this).addClass('work');

				changePage.change(page, image, actualPage, idWork);				

				$.address.value($(this).attr('href'));  					
				
				return false;					

	});

	$('.lang').click(function(){
		var lang = $(this).html();
		var a = $.address.pathNames();   			

		if( a && a.length > 0)
		{

            if(a[0] == "ita" && lang != "ita")
            {
            	var to = base_url+"en/url";
            	for(var i=1; i < a.length; i++)
            	{
            		to += '/'+a[i];	
            	}

               window.location = to;                    
            }
            else if(a[0] == "en" && lang != "en")   
            {
                var to = base_url+"ita/url";
            	for(var i=1; i < a.length; i++)
            	{
            		to += '/'+a[i];	
            	}

               window.location = to;
            } 

        } else {
            
            var url = $.address.baseURL();

            if( url.match('/ita/') && lang != "ita")
            {
            	var to = url.replace("/ita/", "/en/"); 	

            	window.location = to;                    
            }
            else if( url.match('/en/') && lang != "en" )                    
            {
            	var to = url.replace("/en/", "/ita/"); 	

            	window.location = to;                    
            }
            else if( url == base_url )
            {
            	var to = url + 'en/';

            	window.location = to;                    	
            }   
            else if( url == base_url+'en/' )
            {
            	var to = base_url;

            	window.location = to;
            } 
            else 
            {
            	lang = $.trim(lang.toLowerCase());
            	var to = base_url + lang + '/';

            	window.location = to;
            }
        }				
	});

	$('#slideLeft').live('click', function(){
		changePage.footerWorkSlide( $(this) , -1);		
	});

	$('#slideRight').live('click', function(){
		changePage.footerWorkSlide( $(this) , 1);		
	});

	$('#BigSlideLeft').live('click', function(){
		//activity.changeContent( $(this) );
		
		var id = parseInt( $(this).attr('alt') );
		indexArrFooter = id;
		idWork = id;
		
		var cont = activity.getArrContent();
			
		activity.setIdwork(idWork);

		activity.generateContentHtml();

		changePage.setContent( activity.getContentHtml(), cont[idWork].background ); 

		changePage.slideInternal('work/'+cont[idWork].background, '', function(){
			setTimeout("activity.getJavascript()", 600);			
			try
			{
				activity.getJavascript();	
			} catch(e) {
				setTimeout("activity.getJavascript()", 500);
			}			
		}, -1);


		var old = $.address.value();
		old = old.split('/');

		if( $.address.baseURL().match('/ita/') )
		{
			$.address.value('ita/'+'ajaxWork'+'/'+cont[idWork].name);			
		}
		else if( $.address.baseURL().match('/en/') )
		{
			$.address.value('en/'+'ajaxWork'+'/'+cont[idWork].name);				
		}
		else
		{
			$.address.value(old[1]+'/'+'ajaxWork'+'/'+cont[idWork].name);				
		}		

		var intervalID = window.setTimeout('resizeLayout.general()', 600);
			intervalID = window.setTimeout('resizeLayout.footer()', 600);
		

	});

	$('#BigSlideRight').live('click', function(){
		var id = parseInt( $(this).attr('alt') );
		indexArrFooter = id;
		idWork = id;
		
		var cont = activity.getArrContent();
			
		activity.setIdwork(idWork);

		activity.generateContentHtml();

		changePage.setContent( activity.getContentHtml(), cont[idWork].background ); 

		changePage.slideInternal('work/'+cont[idWork].background, function(){
			setTimeout("activity.getJavascript()", 600);			
			try
			{
				activity.getJavascript();	
			} catch(e) {
				setTimeout("activity.getJavascript()", 500);
			}			
		}, 1);


		var old = $.address.value();
		old = old.split('/');

		if( $.address.baseURL().match('/ita/') )
		{
			$.address.value('ita/'+'ajaxWork'+'/'+cont[idWork].name);			
		}
		else if( $.address.baseURL().match('/en/') )
		{
			$.address.value('en/'+'ajaxWork'+'/'+cont[idWork].name);				
		}
		else
		{
			$.address.value(old[1]+'/'+'ajaxWork'+'/'+cont[idWork].name);				
		}				


		var intervalID = window.setTimeout('resizeLayout.general()', 600);
			intervalID = window.setTimeout('resizeLayout.footer()', 600);		

		// activity.changeContent( $(this) );
		// var intervalID = window.setTimeout('resizeLayout.general()', 600);
		// 	intervalID = window.setTimeout('resizeLayout.footer()', 600);
		// 	intervalID = window.setTimeout('activity.getJavascript()', 600);
	});	

	$('.foot').live('click', function(){
		activity.changeContentFromFooter( $(this) );
		var intervalID = window.setTimeout('resizeLayout.general()', 1000);
			intervalID = window.setTimeout('resizeLayout.footer()', 1000);
			intervalID = window.setTimeout('activity.getJavascript()', 1000);
	});

	/* Tracking Login */
	var isOpenBox = false;

	// $('#tracking').click(function(){		
	// 	if(!isOpenBox)
	// 	{
	// 		$('#tracking_box, #tracking_box iframe').animate({height:'163px'}, 600, function(){
	// 			$('#tracking_login').css({visibility:'visible'});
	// 			$('#tracking_login iframe').css({display:'block'});
	// 			isOpenBox = true;
	// 		});			
			
	// 	} 
	// 	else 
	// 	{
	// 		$('#tracking_box, #tracking_box iframe').animate({height:'0px'}, 600, function(){
	// 			$('#tracking_login').css({visibility:'hidden'});
	// 			$('#tracking_login iframe').css({display:'none'});
	// 			isOpenBox = false;
	// 		});				
	// 	}
			
	// });
	

});

var actualPage = "home",
	isAnimating = false;
			


function retro(browser_name, browser_version){
	var version = parseInt(browser_version);
	switch(browser_name)
	{
		case 'Explorer':
			if(version < 9)
				$('#anim-page-wrap, #page-wrap').css({zIndex:'-2'});
				$('.imageID, .imageID2').css({display:'block'});
		break;

	}
}

var resizeLayout = {

	ratioh : 0,

	testSize: function(){
		if(actualPage == 'contact' || actualPage == 'clienti') {

			var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#footer').outerHeight() - $('#content').outerHeight() ) / 2;
			
			if(newMarginVertical <= 5){newMarginVertical = 0}

			//Serve per determinare il margin orizontale
			var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() )   ) );

			var nonso = maxVerticalSpace * 2.411;
						
			return maxVerticalSpace;
		}
	},
	
	general: function(){

		if(isAnimating == true){
			return false;			
		}
			
		isAnimating == true;
		$('#content').css({cursor:"auto"});

		

		switch(actualPage) {

			case 'ajaxWork':										
					
					//Serve per determinare il margin top AGGIUNGERE IL PADDING
					var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#footer').outerHeight() - $('#content').outerHeight() ) / 2;
					
					if(newMarginVertical <= 5){newMarginVertical = 0}

					//Serve per determinare il margin orizontale
					var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() )   ) );

					var nonso = maxVerticalSpace * 2.411;

					$('#page-wrap').css({
						padding: '1% 0%',
						width: '100%',
						top: '0px',
						backgroundSize: '100% auto'					
					});

					$('#page-wrap, #content').css({ 
						height: maxVerticalSpace - ( parseInt( $('#page-wrap').css('padding-top') ) * 2 )
					});
					
					$('#page').css({
						margin: '0%'
					});

					$('#content').css({
						width: '100%',
						height: $('#page-wrap').height()+'px'
						//background: 'url('+base_url+'img/bg_opa.png)'    				
					});
					

					//Interno contenuto work {

						var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() )  + ( parseInt( $('#page').css('margin-top') ) * 2 ) ) );

						//prendo larghezza pagina

						var pw_w = $('#work').width(),
							pw_h = $('#work').height();
						
						/*	Su webkit porzioni di codice tipo ( parseInt($('#box').css('top')) * 2 )
							se il valore top è espresso in percentuale
							non funzionano quindi vanno calcolati i margini manualmente
							rispetto al contenitore
						*/

						var marginMedia_v = ( ( pw_h / 100 ) * 5 ) * 2,  // VERTICALE  ( parseInt($('#media').css('top')) * 2 )
							marginMedia_h = ( pw_w / 100 * 5 ) * 2;      // HORIZONTAL ( parseInt($('#media').css('top')) * 2 )						

						//calcolo la percentuale di margine decisa

						var pw_m_p = ( pw_w - marginMedia_h ) /100 * 5; //pw_m_p -> pagewrap_margin_percentage


						//calcolo spazio disponibile per le larghezze dei box
						var t = ( pw_w / 100 * 2 ) * 2;  // il primo * 2, rappresenta il margine impostat0 al div #work
						var newWidthBox = ( pw_w - t ) / 2 - pw_m_p;

						//calcolo spazio disponibile per le altezza dei box

						var newHeightMedia = (newWidthBox/1.2) * 0.56,
							newWidthMedia  = newWidthBox/1.2;

						//alert('marginMedia_v: '+marginMedia_v+'   /   marginMedia_h: '+marginMedia_h);

						var newHeightBox = ( pw_h - marginMedia_v - ( parseInt($('#box').css('padding-top')) * 2 ) );

						//alert('newWidthBox: '+newWidthBox+'   /   newHeightBox: '+newHeightBox);

						//Se l'altezza del div media + i suoi margini è maggiore dell'altezza di pw_h
						//allora ridimesiono il div media in base all'altezza rispetto che alla larghezza

						if( ( newHeightMedia + marginMedia_v ) >= pw_h ){
							var ph_m_p = ( pw_h - marginMedia_v ); //var ph_m_p = ( pw_h - ( parseInt($('#box').css('top')) * 2 ) ); //ph_m_p -> pagewrap height _margin_percentage
							newHeightMedia = ph_m_p;
							newWidthMedia = newHeightMedia / 0.56; //Proporzione contenuto media 300px X 240px ratio 0.8							

						}

						//imposto le larghezze finali
						$('#media, #workSlide, #workSlide img').css({
							width: Math.round(newWidthMedia)+'px',
							height:  Math.round(newHeightMedia) + 'px'		//Proporzione contenuto media 300px X 240px ratio 0.8							
						});

						$('#workSlide iframe').css({
							width: newWidthMedia+'px',
							height:  newHeightMedia + 'px'		//Proporzione contenuto media 300px X 240px ratio 0.8							
						});

						$('#box').css({
							width: newWidthBox+'px',
							height:  newHeightBox + 'px'		//Proporzione contenuto media 300px X 240px ratio 0.8							
						});

						this.scrollBar();

						if( $('#content').height() >= $('#box').height() ){							

							$('#box').css({					
								height:'100%' //300px
							});		
										
						}							
						
						$('#footer').css({backgroundRepeat: 'repeat-x'});	

						$("#BigSlideLeft, #BigSlideRight").css({top: $('#content').height() / 2+'px'});								
					
					isAnimating == false;
			break;

			case 'contact':
				//Serve per determinare il margin top AGGIUNGERE IL PADDING
				var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#footer').outerHeight() - $('#content').outerHeight() ) / 2;
				
				if(newMarginVertical <= 5){newMarginVertical = 0}

				//Serve per determinare il margin orizontale
				var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() )   ) );

				var nonso = maxVerticalSpace * 2.411;

				$('#page-wrap').css({
					padding: '1% 0%',
					width: '100%',
					top: '0px',
					backgroundRepeat: 'no-repeat',
					height: maxVerticalSpace ,//- ( parseInt( $('#page-wrap').css('padding-top') ) * 2 ),
					backgroundSize: '100%'				
				});				
				
				$('#page').css({
					margin: '0%'
				});

				$('#content').css({
					width: '100%' 				
				});

				this.scrollBar();
						
			break;

			case 'clienti':

				$('#content').css({
					width: '100%',
					height: '100%' 				
				});
							
				//Serve per determinare il margin top AGGIUNGERE IL PADDING
				var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#content').outerHeight() ) / 2;								

				if(newMarginVertical <= 5){newMarginVertical = 0}

				//Serve per determinare il margin orizontale
				var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() ) )   ) ;

				var nonso = maxVerticalSpace * 2.411;

				$('#page-wrap').css({
					padding: '1% 0%',
					width: '100%',
					top: '0px',
					backgroundSize: '100%'				
				});

				$('#page-wrap, #content').css({
					height: maxVerticalSpace - Math.round( parseInt( $('#page-wrap').css('padding-top') ) * 2 )
				});
				
				$('#page').css({
					margin: '0%',
					height: '100%'
				});

				if( myscreen.getW() >= myscreen.getH() )
				{
					var tb = parseInt(myscreen.getW() * 50 / 100);
					//alert( tb );

					$('#tableClient').css({width: tb+'px'});

					var cella_w = Math.round( tb / 7 );
					var cella_h = Math.round( cella_w * 0.89 );

					$('.tdClienti, .tdClienti > .camera > .log > a > img').css({
						width: cella_w+ 'px',
						height: cella_h + 'px'
					});
													
					if( $('#clienti table').height() >=  $('#content').outerHeight() )
					{				

						// var cella_h = Math.round( $('#content').outerHeight() / 5 ); //Cambiare 4 con count di tr						
						// var cella_w = Math.round( cella_h * 0.89 );		

						// $('#clienti table td').css({
						// 	width: cella_w-20 + 'px',
						// 	height: cella_h-20 + 'px'
						// });
					
						// var marginTable = Math.round( ( $('#content').width() - Math.round( $('#content').outerHeight() * 1.93) ) * .5 ) + 40;				

						// $('#page').css({
						// 	marginLeft: marginTable + 'px',
						// 	marginRight: marginTable + 'px'
						// });

					}				
				
				} else {
					var cella_w = $('#clienti table').width() / 9;
					var cella_h = cella_w * 0.89;


					$('#clienti table td').css({
						width: cella_w-20 + 'px',
						height: cella_h-20 + 'px'
					});
													
					if( $('#clienti table').width() >= $('#content').width() )
					{					
					
					}
				}			
				
				/*
				var marginTable = ( Math.round( $('#content').outerHeight() - $('#clienti').height() ) / 2 );						
				
				$('#page').css({
					marginTop: marginTable + 'px',
					marginBottom: marginTable + 'px'
				});
				*/
				
													
				this.scrollBar();			
			break;

			case 'tracking':

				$('#content').css({
					width: '100%',
					height: '100%' 				
				});
							
				//Serve per determinare il margin top AGGIUNGERE IL PADDING
				var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#content').outerHeight() ) / 2;								

				if(newMarginVertical <= 5){newMarginVertical = 0}

				//Serve per determinare il margin orizontale
				var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() ) )   ) ;

				var nonso = maxVerticalSpace * 2.411;

				$('#page-wrap').css({
					padding: '1% 0%',
					width: '100%',
					top: '0px',
					backgroundSize: '100%'				
				});

				$('#page-wrap, #content').css({
					height: maxVerticalSpace - Math.round( parseInt( $('#page-wrap').css('padding-top') ) * 2 )
				});
				
				$('#page').css({
					margin: '0%',
					height: '100%'
				});
											
													
				this.scrollBar();			
			break;


			// case 'clienti':

			// 	$('#content').css({
			// 		width: '100%',
			// 		height: '100%' 				
			// 	});
							
			// 	//Serve per determinare il margin top AGGIUNGERE IL PADDING
			// 	var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#content').outerHeight() ) / 2;								

			// 	if(newMarginVertical <= 5){newMarginVertical = 0}

			// 	//Serve per determinare il margin orizontale
			// 	var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() ) )   ) ;

			// 	var nonso = maxVerticalSpace * 2.411;

			// 	$('#page-wrap').css({
			// 		padding: '1% 0%',
			// 		width: '100%',
			// 		top: '0px',
			// 		backgroundSize: '100%'				
			// 	});

			// 	$('#page-wrap, #content, #clienti').css({
			// 		height: maxVerticalSpace - Math.round( parseInt( $('#page-wrap').css('padding-top') ) * 2 )
			// 	});
				
			// 	$('#page').css({
			// 		margin: '0%',
			// 		height: '100%'
			// 	});

			// 	if( myscreen.getW() >= myscreen.getH() )
			// 	{

			// 		var cella_w = Math.round( $('#clienti table').width() / 9 );
			// 		var cella_h = Math.round( cella_w * 0.89 );


			// 		$('#clienti table td').css({
			// 			width: cella_w-20 + 'px',
			// 			height: cella_h-20 + 'px'
			// 		});
													
			// 		if( $('#clienti table').height() >=  $('#content').outerHeight() )
			// 		{				

			// 			var cella_h = Math.round( $('#content').outerHeight() / 5 ); //Cambiare 4 con count di tr						
			// 			var cella_w = Math.round( cella_h * 0.89 );		

			// 			$('#clienti table td').css({
			// 				width: cella_w-20 + 'px',
			// 				height: cella_h-20 + 'px'
			// 			});
					
			// 			var marginTable = Math.round( ( $('#content').width() - Math.round( $('#content').outerHeight() * 1.93) ) * .5 ) + 40;				

			// 			$('#page').css({
			// 				marginLeft: marginTable + 'px',
			// 				marginRight: marginTable + 'px'
			// 			});

			// 		}				
				
			// 	} else {
			// 		var cella_w = $('#clienti table').width() / 9;
			// 		var cella_h = cella_w * 0.89;


			// 		$('#clienti table td').css({
			// 			width: cella_w-20 + 'px',
			// 			height: cella_h-20 + 'px'
			// 		});
													
			// 		if( $('#clienti table').width() >= $('#content').width() )
			// 		{					
					
			// 		}
			// 	}			
				
			// 	/*
			// 	var marginTable = ( Math.round( $('#content').outerHeight() - $('#clienti').height() ) / 2 );						
				
			// 	$('#page').css({
			// 		marginTop: marginTable + 'px',
			// 		marginBottom: marginTable + 'px'
			// 	});
			// 	*/
				
													
			// 	this.scrollBar();			
			// break;

			case 'about':

				$('#page-wrap').css({
					padding: '1% 0%',
					width: '100%',
					top: '0px',
					backgroundSize: '100% auto' // Niu '100% auto'			
				});				

				$('#content').css({
					width: '100%',
					height: '100%' 				
				});


							
				//Serve per determinare il margin top AGGIUNGERE IL PADDING
				var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#content').outerHeight() ) / 2;								

				//Serve per determinare il margin orizontale
				var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() ) )   ) ;				

				$('#page-wrap, #content').css({
					height: maxVerticalSpace - Math.round( parseInt( $('#page-wrap').css('padding-top') ) * 2 )
				});

				this.scrollBar();						
			break;

			case 'about':
				$('#footer').css({backgroundColor:'#fff'});
			break;			

			default:
				$('#content').css({cursor:"pointer"});

				//$('#footer').css({height: '25%'});
				//Serve per determinare il margin orizontale
				var maxVerticalSpace = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() )  + ( parseInt( $('#page').css('margin-top') ) * 2 ) ) );
				this.ratioh = maxVerticalSpace;

				//Se non c'è un immagine a dare la dimensione la do io				
				var nuova = maxVerticalSpace * 2.411;

				$('#page-wrap').css({
					padding: '0% 0%',
					top: '0px', //*
					backgroundSize: 'auto 100%'
					
				});

				$('#nav').css('z-index', 9999);

				//Serve per determinare il margin top AGGIUNGERE IL PADDING
				var newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - parseInt( $('#page-wrap').css('padding-top') ) - $('#footer').outerHeight() - $('#content').outerHeight() ) / 2;
				
				if(newMarginVertical <= 5){newMarginVertical = 0}
		
				this.scrollBar();

				if( myscreen.getW() >= myscreen.getH() ){						

					$('#page-wrap').css({height: Math.round( maxVerticalSpace )+'px'});
					$('#content, #slide, #slide img').css({height: Math.round( maxVerticalSpace )+'px', width:Math.round( nuova )+'px'});

					if( $('#content').outerHeight() >= maxVerticalSpace ){

						newMarginVertical = 0;
						var z = ( myscreen.getW() - $('#content').width() ) / 2;

						var ratioh = maxVerticalSpace / $('#content').outerHeight();
						var newMarginHorizontal = Math.round( ( myscreen.getW() - ( $('#content').width() * ratioh) ) / 2 );

						$('#page').css('margin-left', newMarginHorizontal+'px');
						$('#page').css('margin-right', newMarginHorizontal+'px');			
										
						this.ratioh = newMarginHorizontal;
						this.footer();

					} else {

						$('#page').css('margin-left', '9%');
						$('#page').css('margin-right', '9%');	
						// $('.foot-wrap').css('margin-left', '9%');	
						// $('.foot-wrap').css('margin-right', '9%');			
													
						$('.foot').css('width', '33.33%');													
						
					}

					if( $('#content').outerWidth() >=  myscreen.getW() ){
						
						var maxVertical = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() ) ) );
						var marginVerticale = Math.round( ( maxVertical - ( myscreen.getW() / 2.411 ) ) / 2 );
						

						var uu = Math.round( myscreen.getW() - ( myscreen.getW() / 100 * 18 ) );

						$('#content, #slide, #slide img').css({height: Math.round( uu/2.411 )+'px', width:uu+'px'});
						
						newMarginVertical = ( myscreen.getH() - $('#header').outerHeight() - $('#footer').outerHeight() - $('#content').height() ) / 2;
						
						//console.log(newMarginVertical);
						
						$('#page').css('margin-left', '9%');
						$('#page').css('margin-right', '9%');	
						// $('.foot-wrap').css('margin-left', '9%');	
						// $('.foot-wrap').css('margin-right', '9%');							

					}
						
				} else {								
																									
						var maxVertical = Math.floor( ( myscreen.getH() - ( $('#header').outerHeight() )  - ( $('#footer').outerHeight() ) ) );

						var marginVerticale = Math.round( ( maxVertical - ( myscreen.getW() / 2.411 ) ) / 2 );

						var uu = Math.round( myscreen.getW() - ( myscreen.getW() / 100 * 18 ) );

						$('#content, #slide, #slide img').css({height: Math.round( uu/2.411 )+'px', width:uu+'px'});

						$('#page').css('margin-left', '9%');
						$('#page').css('margin-right', '9%');	
						// $('.foot-wrap').css('margin-left', '9%');	
						// $('.foot-wrap').css('margin-right', '9%');	
					
					this.footer()

				}
					//Il discorso dei margini come fini?
					//$('#page').css('margin-top', newMarginVertical+'px');
					//$('#page').css('margin-bottom', newMarginVertical+'px');					


			break;
		}
		isAnimating == false;
	},

	footer: function() {		
	
		if(isAnimating == true)
			return false;	

		//console.log(actualPage);
		isAnimating == true;
		switch(actualPage) {

			case 'ajaxWork':


				var k = ( $('#footer').outerHeight() - $('.foot').outerHeight() ) -10;
				var marginType = "px";

				var bo = ( myscreen.getW() - parseInt($('#work').width()) ) / 2;

				var x= $('#work').css('margin-left');

				//NON MENO SE NO SI ACCAVALLANO LE FRECCIE
				$('.foot-wrap').css('margin-left', '5%');
				$('.foot-wrap').css('margin-right', '5%'); 

				//2,289

				$('.foot-wrap').css('height', $('.foot').height() );

				//$('.foot-wrap').css('bottom', -k+'px' );
				
				//$('.foot').css('width', '30.33%');

				if( Math.round( parseInt( $("#footer").css('height') ) ) <=  $('.foot').outerHeight()  ){
					$("#footer").css({height: $('.foot').outerHeight()+'px'});	
				} else {
					$("#footer").css('height', '25%')
				}				

				$("#slideLeft, #slideRight").css({top: $('.foot').height() / 2+'px'});								

			break;

			case 'clienti':
				$('#footer').hide();

			break;		
			
			case 'about':
				$('#footer').css({backgroundColor:'#fff'});
			break;			

			default:
				
				/*/Versione con margini 
				var b = Math.round( parseInt( $('#page').css('margin-left') ) );
				var k = ( $('#footer').outerHeight() - $('.foot img').outerHeight() ) -10;

				var marginType = "px";

				if(b == '9'){
					marginType = '%';
				} else {
					marginType = 'px';
				}

				$('.foot-wrap').css('margin-left', b+marginType);
				$('.foot-wrap').css('margin-right', b+marginType);
				
				///*/

				// $('.foot-wrap').css('height', $('.foot').outerHeight() );
				// //$('.foot-wrap').css('bottom', -k+'px' );

				// $('.foot-wrap').css('margin-left', 0);
				// $('.foot-wrap').css('margin-right', 0);
				
				$('.foot img').css('width', '90%');
				$('.foot').css('width', '30.96%');
				//$('.foot-wrap').css('height', $('.foot').outerHeight() );


				if( Math.round( parseInt( $("#footer").css('height') ) ) <=  $('.foot').outerHeight()  ){
					$("#footer").css({height: $('.foot').outerHeight()+'px'});	
				} else {
					$("#footer").css('height', '25%')
				}
				
				


			
			break;

		}
		isAnimating == false;

	},

	scrollBar: function(){
		$('body, #wrapper, html').css({
				overflowX: 'hidden',
				overflowY: 'hidden'
		});
		//Controllo le scroll bar
		if( parseInt( $('#wrapper').width() ) < 750){
			$('#wrapper').css({
				width: '750px'						
			});
			$('body').css({
				overflowX: 'scroll',
				overflowY: 'hidden'
			});
		} 
		if(myscreen.getW() > 750){
			$('#wrapper').css({
				width: '100%'						
			});
			$('body').css({
				overflowX: 'hidden'
			});

			$('#footer').css({
				position:'fixed'
			});			
		}

		//Scrollbar verticale solo per la sezione work
		// if( actualPage == 'ajaxWork'){
			
		// 	//controllare se il box è più largo del content

		// 	if( parseInt( $('#wrapper').height() ) < 469 ){// ||  $('#content').height() <= $('#box').height() ){ //if( parseInt( $('#wrapper').height() ) < 469){
		// 		$('#page-wrap').css({
		// 			overflowY: 'scroll'											
		// 		});				

		// 		$('#content').css({
		// 			minHeight: '300px',
		// 			height:'100%' //300px
		// 		});

		// 		$('#footer').css({
		// 			position:'fixed'
		// 		});

		// 	} 
		// 	else if( $('#content').height() <= $('#box').height() ){
				
		// 		$('#page-wrap').css({
		// 			overflowY: 'scroll'											
		// 		});

		// 		$('#content').css({					
		// 			height:'100%' //300px
		// 		});		

		// 		$('#footer').css({
		// 			position:'fixed'
		// 		});

							
		// 	}	
		// 	else if( $('#footer').css('position') == 'relative' &&  parseInt( $('#wrapper').height() ) < 500){
				
		// 		$('#page-wrap').css({
		// 			overflow: 'scroll'						
		// 		});
										
		// 	} else {
		// 		$('#page-wrap').css({
		// 			overflow: 'hidden'						
		// 		});

		// 		$('#work').css({
		// 			height: '100%'
		// 		});

		// 	}			
		// }
		if( actualPage == 'ajaxWork'){
			//console.log("$('#box').height()  :  "+$('#box table').height());
			//console.log("$('#content').height()  :  "+$('#content').height());

			if( $('#box table').height() > $('#content').height() ){
				$('#box').css({
					overflowY: 'scroll'
				});
			} else {
				$('#box').css({
					overflowY: 'hidden'
				});			
			}

		}
		
	}

}



