$(document).ready(function() {
	$("#maggiore .scroller").click(function(ev) {
		sinistra=$("#maggiore .scroller").css('left');
		if(sinistra.indexOf('px') > 0 ) { sinistra=sinistra.substring(0,sinistra.length-2)}
		if(sinistra < 0) {
			$('#maggiore .scroller').animate({left: "0px"},1500);
		} else {
			$('#maggiore .scroller').animate({left: "-510px"},1500);

		}
	})
	$("#navigation li").each(function(){
		

		
		$('#' + this.id).click(function(ev) {
			$("#navigation li").each(function(ev){
				identif=this.id;
				identif=identif.replace(/nav-/g, "testo-");
				$('#' + identif).css({'display':'none'})
				$(this).hide(100);
				// this.css({'display': 'none'})
			});

			identif=this.id;
			identif=identif.replace(/nav-/g, "testo-");
			solo=this.innerHTML;
			if(trim(solo) =='contatti' || trim(solo) =='contacte') {
				$.get('/sites/contatti/' + $(this).attr('class'), function(data) { 
					$('#module').html(data);
					click_contatti(identif,solo);
				});
			}else {
				$.get('/sites/listWorks/' + $(this).attr('class'), function(data) { 
					$('#module').html(data); 
					click_menu(identif,solo,0);
				});
			}

		})		
	})


	$('#label_menu').click(function(){
		largh=$("#navigation").css('width');
		if(largh.indexOf('px') > 0 ) { largh=largh.substring(0,largh.length-2)}
		if(largh == 0) {
			$('#navigation').animate({width: "250px"},1500);
			// $('#wrapper').animate({left: "206px"},1500);
			// alert('a')
			$('.testi_menu').each(function(){
				$(this).hide();
			})
			$('#navigation li').each(function(){
				$(this).animate({opacity: 1},1500)
				$(this).show();
			})

		}
	})

	
	

	$('#home').click(function(){
		$('#home').hide(10, function () {
			$('.testi_menu').hide(10, function () {
					w_content=$("#content").width();
					w_header=$("#header").width();
					w_schermo=$(window).width();
					differenza=(w_schermo*1)-((w_header*1) + (w_content*1) + 20 );
					// alert('c ' + w_content + ' h ' + w_header + ' s ' + w_schermo + ' d ' + differenza);
					differenza=differenza+ 'px';
					// differenza='-740px';
				$('#wrapper').animate({left: differenza},1000, function () {
					$('#navigation').animate({width: "250px"},1000, function () {
						$('#navigation li').show(100, function () {
							$('#navigation li').animate({opacity:'1'},0, function () {
							});		
						});		
					});		
				});	
			});
		});
	})
	

	
	allinea_lato_sinistro();
	dimensione_footer()
	$("#header h1 a").hover(function() {
		$("#header h1 a").css({
			"backgroundImage": "url('/img/logo_3_girato.png')",
				'background-position': 'top left',
				'background-repeat': 'no-repeat'
			});
	} , function() {
		$("#header h1 a").css({
			"backgroundImage": "url('/img/logo_3.png')",
			'background-position': 'top left',
			'background-repeat': 'no-repeat'
		});	});

	$("#pageflip").hover(function() {
		$("#pageflip img , .msg_block").stop()
			.animate({ 
				width: '200px',
				height: '200px'
			}, 500);
		} , function() {
		$("#pageflip img").stop() 
			.animate({
				width: '50px',
				height: '50px'
			}, 220);
		$(".msg_block").stop() 
			.animate({
				width: '50px',
				height: '50px'
			}, 200); 
	});
	$("#curriculum").fancybox({
		hideOnContentClick: false	
	});
});
function click_menu(identif,solo,step) {
	// alert('identif ' + identif)
	// alert('solo '  + solo)
//	 alert('step ' + step)
	// devo capire perch passo quattro volte nell'utlima procedura dopo_scroll_2
	// qui passo una volta sola!!!!
	$("#module").css({
		"backgroundImage": "url('/img/bg_gallery_work.png')",
		'background-repeat': 'no-repeat'
	});
	contatore=0
	contatore2=0
	$('#navigation li').hide(100, function () {
		contatore=(contatore*1)+1;
		reset_module();
		// 4 volte!
		// alert('prima di tutto')
		if(contatore==1) {
			// alert('1');
			$('#navigation').animate({width: "0px"},1000, function () {
				$('#wrapper').animate({left: "-740px"},1000, function () {
					$('#home').show(100, function () {
						$('#' + identif).css({
							"backgroundImage": "url('/img/bg-" + trim(solo) + ".png')",
							'background-repeat': 'no-repeat',
							'background-position': 'bottom right'
						})
						$('#' + identif).show(300, function () {
							// passo  4 volte
							// alert('prima della i')
							if (contatore==$('#navigation li').length){
								$('#slide_big').animate({left: 444*step*-1},750*step,function(){
								//	alert('dopo_sc')
									// qui chiamo 4 volte
									dopo_scroll(contatore,contatore2)
								});
							}
						});
					});	
				});	
			});	
		}
	});
}

function dopo_scroll(){
// qui passo 4 volte!!!!!
	// alert('a');
	// stop();
	w_slide_big=$('#slide_big').width();
	w_slide=$('#slide').width();
	if(w_slide_big > w_slide ) {
		$('#freccia_dx').css({'background-color':'transparent'})
	} else {
		$('#freccia_dx').css({'background-color':'white'})
	}
}
function click_contatti(identif,solo) {
	$("#module").css({
			'background-image': "url('/img/bg_contatti.jpg')",
			'background-position': 'top right',
			'background-repeat': 'no-repeat'
	});
	$('#navigation li').hide(100, function () {
			reset_module();
			$('#navigation').animate({width: "0px"},1000, function () {
				$('#wrapper').animate({left: "-740px"},1000, function () {
					$('#home').show(100, function () {
						$('#' + identif).css({
							"backgroundImage": "url('/img/bg-" + trim(solo) + ".png')",
							'background-repeat': 'no-repeat',
							'background-position': 'bottom right'
						})
						$('#' + identif).show(300, function () {
						});
					});	
				});	
			});	
		});	

}
function dimensione_footer() {
	$('#footer').hide();
	var dim=$(window).width();
	var dim2=(dim-30)/2;
	// alert(dim2)
	$('#footer ul li').width(dim2)
	$('#footer ul').width(dim)
	$('#footer').width(dim);
	$('#footer .copyrights').width(dim);
	$('#footer').show();
}
function scorri_in_basso() {
}
function scendi_module(valore) {
	$.get('/sites/listMedia/' + valore , function(data) { $('#medias').html(data); 
		$('#module').animate({top: "-350"},1500);
	});
}
function reset_module() {
	$('#module').animate({top: "0"},1500);
}
function testo_descrizione(identif){
	
}
function chiudi_elementi_menu(){
	// alert('passo');
	
}  
function chiudi_menu(){
	largh=$("#navigation").css('width');
	if(largh.indexOf('px') > 0 ) { largh=largh.substring(0,largh.length-2)}
	if(largh > 0) {
		$('#navigation').animate({width: "0px"},1500);
		$('#wrapper').animate({left: "-740px"},1500);
	} else {
		$('#navigation').animate({width: "250px"},1500);
		$('#wrapper').animate({left: "206px"},1500);
	}

}
function allinea_lato_sinistro(){
	w_content=$("#content").width();
	w_header=$("#header").width();
	w_content=740;
	w_header=330;
	w_schermo=$(window).width();
	differenza=(w_schermo*1)-((w_header*1) + (w_content*1) + 20 );
	// alert('c ' + w_content + ' h ' + w_header + ' s ' + w_schermo + ' d ' + differenza);
	differenza=differenza+ 'px';
	// differenza='-740px';
	$("#wrapper").css("left", differenza );
	$('#wrapper').show();
}
// sezione="nav-Mosaico_Artistico";
// lavoro="";
// step=2;

// alert($('#nav-Mosaico_Artistico').attr('class'));
function apri_lavoro(sezione,lavoro,step) {
	sezione2 = 'nav-' + sezione;
	identif=sezione2.replace(/nav-/g, "testo-");
	solo=$('#' + 'nav-' + sezione).html();
		$.get('/sites/listWorks/' + $('#' + sezione2).attr('class'), function(data) { 
			$('#module').html(data);
			click_menu(identif,solo,step);
		});	
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
 