

$(document).ready(function() {


	//MENU				
	$("#m_contatti").click(function() { 
								//$("#menu #m_prodotti").removeClass("on"); 
								//$(this).addClass("on"); 
								$("div.submenu").hide(); 
								$("#contatti-box").fadeIn(); 
							});
							
	
	//AREA SEARCH-CONNECT
	$("#mf_ricerca").click(function() {
									$("#mf_share").removeClass("on"); 
									$("#camposhare").fadeOut();
									$(this).toggleClass("on"); 
									$("#camporicerca").fadeIn();
									$("#camporicerca input").focus();
								});
	
	$("#mf_share").click(function() {
									$("#mf_ricerca").removeClass("on"); 
									$("#camporicerca").fadeOut();
									$(this).toggleClass("on"); 
									$("#camposhare").fadeIn(); 
								});
	
	$("#area_search-connect").mouseleave(function() { 
													$("#mf_ricerca, #mf_share").removeClass("on"); 
													$("#camporicerca, #camposhare").fadeOut(); 
													});
													
		
		
													
													
	//SET SCROLLABLE WALK DIV
	
		//HOME
	if($("#home-walk").length > 0) {
		home_walk_set();
	
		$(window).resize(function() { home_walk_set(); });
	}
	
	
	
	
		//PRODUCT / iDISPLAY
	if($("#idisplay-walk").length > 0) {
		
		idisplay_walk_set();
	
		$(window).resize(function() { idisplay_walk_set(); });

	}
	
	
	
		//NEWS
	if($("#news-walk").length > 0) {
		if($("#quadro").width() < 1250) 
					$("div.onair-product").hide();
	
		$(window).resize(function() { 
			if($("#quadro").width() < 1250) 
					$("div.onair-product").hide(); 
			else 
					$("div.onair-product").show(); 
		});
	
		
	
		$("div.new:eq(0)").css('width', '460px').css('height', '210px').css("cursor", "default");
		
		$("div.new").click(function() {
							if($(this).width() == 260 && $(this).height() == 70) {
								$("div.new").animate({ width:'260px', height:'70px' }); 
								$("div.new").css("cursor", "pointer");
								$(this).animate({ width:'460px', height:'210px' });
								$(this).css("cursor", "default");
							}
						});		
	}
	
	
													
	
	
	//MOUSEWHEEL, TOUCH SCROLL WALK
	var mw_step = 0;
	var mw_lock = false;
	var mw_scrolloffset;


				
	if($("div.walk").length > 0) {	
		mw_scrolloffset = $("#quadro")[0].scrollHeight - $("#quadro").height(); 
						/*$("div.walk")[0].scrollHeight - $("div.walk").height();*/
				
			
		$("div.walk").mousewheel(function(event, delta) {
										if(mw_lock) return;
										mw_lock = true;
		
										if(delta > 0 && Math.abs(parseInt($(this).css("top"))) > 0)
											  $(this).animate({ top: (++mw_step)*200+"px" }, 400, function(){mw_lock=false;});
										else if(delta < 0 && Math.abs(parseInt($(this).css("top"))) < mw_scrolloffset )
											  $(this).animate({ top: (--mw_step)*200+"px" }, 400, function(){mw_lock=false;});
										else	  
											mw_lock=false;
														
								});
								
								
		
		
		if(!$.browser.msie && navigator.userAgent.indexOf("Chrome")==-1) {
			$("div.walk").touchScroll({scrollHeight: $("#quadro")[0].scrollHeight});
		}
		
		
		
		
		$(window).resize(function() { 
			mw_step = 0; 
			$("div.walk").css("top", "0px"); 
			mw_scrolloffset = $("#quadro")[0].scrollHeight - $("#quadro").height();
							/*$("div.walk")[0].scrollHeight - $("div.walk").height();*/
		});
		
	}
	
	
						
		
						
						
	//TEAM
	var member_lock = false;
	
	$("#members_list li.members_names").mouseover(function() {
													faceid = "#"+$(this).attr("id")+"_face";
													
													if($(faceid).css("display") == 'none')	
														$(faceid).fadeIn();
												});
												
	$("#members_list li.members_names").mouseout(function() { 
													faceid = "#"+$(this).attr("id")+"_face";
													$(faceid).fadeOut(500);
												});
												
	$("#members_list li.members_names").click(function() {
													memberid = "#"+$(this).attr("id");
													$("#members_list li.members_names").unbind("mouseout").hide();
													$(memberid+"_face").css("background-position", "0 -100px").fadeIn();
													$(memberid+"_card").fadeIn();
												});
	
	$("#members_list div.members_cards div.close_card").click(function() {
													$("#members_list div.members_cards").fadeOut();
													$("#team_grid div.members_faces").css("background-position", "0 0").hide();
													
													$("#members_list li.members_names").bind("mouseout", function() { 
														faceid = "#"+$(this).attr("id")+"_face";
														$(faceid).fadeOut(500);
													}).fadeIn();
													
												});
		
		
												
												
	//PRODUCTS / MOBILE / APPS
	if($("#appg").length > 0) {
		screenshot_gallery_set();
		$("#appg-freccia-dx").click(function() { appg_dx(); });
		$("#appg-freccia-sx").click(function() { appg_sx(); });
		
		$(window).resize(function() { screenshot_gallery_set(); });
	}
	
	
	
	
	//CONTACT
	//$("#contatti-box #indirizzoemail").click(function() { $("form#email").fadeToggle(); });
	$("#contatti-box #mappa-btn").click(function() { $(this).toggleClass("on"); $("#mappa").fadeToggle(); });
	
	if($("#mappa").length > 0) {
		if(window.location.search.substr(1) == "map=1") {
			$("#mappa").fadeToggle();
			$("#contatti-box #mappa-btn").toggleClass("on");
		}
	}
	
	
	
	
	
//	//EMAIL
//		
//		//attiva stati focus campi testo
//	$('#email textarea#message').focus(function() { this.value = this.value=='write message' ? '' : this.value; });
//	$('#email input#from').focus(function() { this.value = this.value=='your email' ? '' : this.value; });
//	
//		//attiva stati blur campi testo
//	$('#email textarea#message').blur(function() { this.value = this.value !='' ? this.value : 'write message'; });
//	$('#email input#from').blur(function() { this.value = this.value !='' ? this.value : 'your email'; });
//	
//	//attiva pulsanti invio email
//	$("#send-btn").click(function() { 
//			if(isvalidform()) {
//				sendmail();
//			}
//	});
	
	
	
	
	
	//PRODUCT / LARGE EVENTS
	if($("#eventg-walk").length > 0) {
		
		if($("#quadro").width() < 1250) 
					$("#coldx").hide();
	
		$(window).resize(function() { 
			if($("#quadro").width() < 1250) 
					$("#coldx").hide(); 
			else 
					$("#coldx").show();
		});
			
		
		$("#eventg-walk img").click(function() {
							if($(this).width() == 300 && $(this).height() == 210) {
								$("#eventg-walk img").animate({ width:'300px', height:'210px' });
								$("#eventg-walk img").css("cursor", "pointer"); 
								$(this).animate({ width:'600px', height:'420px' });
								$(this).css("cursor", "default");
							}
						});
	}
	
	
	
	
	
	// Manifesto
	if($("#manifesto").length > 0)
		$("#manifesto img").animate({marginTop:'0px'}, 1500);
	
	
	
	
	
		
});





/* ### MOBILE / APP ### */


var nss, display=2, ss_index=0;


function screenshot_gallery_set() {
	
	nss = $("#appg_nastro div.screenshot").length;
	$("#appg_nastro").css("width", nss*210+"px");
	ss_index = 0;
	$("#appg_nastro").css("left", "0px");
	$("#appg-freccia-sx").hide();
	$("#appg-freccia-dx").show();
	
	

	xq = $("#quadro").width();
	
		if (xq > 950 && xq <= 1250) {
						$("#appg, #appg_display").css("width", "400px");
						display = 2;
		}
	
		else if(xq > 1250 && xq <= 1380) {
						$("#appg, #appg_display").css("width", "620px");
						display = 3;
		}
						
		else if(xq > 1380) {
						$("#appg, #appg_display").css("width", "840px");
						display = 4;
		}
					
}



function appg_dx() {
	$("#appg-freccia-sx").show();
	$("#appg_nastro").animate({left:++ss_index*(-210)});
	
	if(ss_index == (nss-display))
		$("#appg-freccia-dx").hide();	
}

function appg_sx() {
	$("#appg-freccia-dx").show();
	$("#appg_nastro").animate({left:--ss_index*(-210)});
	
	if(ss_index == 0)
		$("#appg-freccia-sx").hide();	
}





/* ########### CONTATTI EMAIL ################# */


//function isvalidform() {
//	warn = 0;
//	
//	if($("#from").val() == "your email" || $("#from").val() == "") {
//		warn++;
//	}
//	
//	if($("#message").val() == "write message" || $("#message").val() == "") {
//		warn++;
//	}
//	
//	if($("#tdp").val() != 1)
//		warn++;
//		
//		
//	if(warn > 0)
//		return false;
//	
//	return true;
//}
//
//
//function sendmail() {
//	
//	params = { from: $("#from").val(), 
//			   to: $("#to").val(), 
//			   subject: $("#subject").val(), 
//			   message: $("#message").val() };
//
//	exit = $.ajax({
//					type: 'POST', 
//					url: '../lib/sendmail.php', 
//					data: params, 
//					success:function(){ 
//										$("#send-btn").addClass("sent");	
//									}
//					}).responseText;
//
//}




/* ############# iDISPLAY-WALK ################## */
function idisplay_walk_set() {
	
		xq = $("#quadro").width();
		yq = $("#quadro").height();
		xidw = (xq/2-385)*2;
		nid = parseInt(xidw/113);
		nid = nid > 5 ? 5 : nid;
		
		$("#idisplay-walk").css("width", nid*113+"px");
		$("#idisplay-walk").css("margin-left", -(nid*113)/2+"px");
		$("#idisplay-walk").css("padding-top", (yq/2)-170+"px");
		$("#idisplay-parole").css("margin-left", (113*nid)/2+12+"px");
					
}



/* ####### HOME-WALK SET ####### */
function home_walk_set() {
	
		  xhw = $("#quadro").width() - 580;
				  
		  if(xhw > 350) 
				  $("#home-walk").css("width", xhw+"px");
		  else 
				  $("#home-walk").css("width", "350px");
				  
}
