/* =============================================================================================
   Nav
 =============================================================================================== */
			$('.menuLv1 .item').hover(function (){
				if ($(this).hasClass('on')) {
					tmp = true;
				} else {
					tmp = false;
					$(this).addClass("on");
				} 
			},function (){
				if (!tmp) {
					$(this).removeClass('on');
				} 	
			});
			
			$('.menuPhoto .item').hover(function (){
				if ($(this).hasClass('on')) {
					tmp = true;
				} else {
					tmp = false;
					$(this).addClass("on");
				} 
			},function (){
				if (!tmp) {
					$(this).removeClass('on');
				} 	
			});	
			
		$('.menuPhoto .item').click(
			function () {
					$('.menuPhoto .item').removeClass('on');
					$(this).addClass('on');
					tmp = true;
				}
			);
			

/* =============================================================================================
   Right Side
			- Requests
	  - SlideShow
 =============================================================================================== */
			
			$('.requests .item').hover(function (){
				$(this).addClass("on");
			},function (){
			 $(this).removeClass('on');
			});
			
			
			
			var stopAutoChange = false;
			var videoAlreadyStarted = false;
			var itemIdSelected ='';
			
			function changeSelected(t) {
				t.siblings('.itemTxt.on').removeClass('on');
				t.addClass('on'); 
				if (itemIdSelected != t.attr('id')){ 
					$('.slideShow .preview').html(t.prev('span').html());
				}
				itemIdSelected = t.attr('id');
			}
			
			$('.itemTxt').hover(function() {
					stopAutoChange = true;
					changeSelected($(this));
			}, function() {
				/* do nothing */
			});
			
			function autoChange() {
				if (!stopAutoChange) {	
					newBox = $('.slideShow').children('.itemTxt.on').next().next();
					if (newBox.length == 0) {
						newBox = $('.slideShow').children('.itemTxt').eq(0);
					}
					$('.slideShow').children('.itemTxt.on').removeClass('on');
					changeSelected(newBox);
					setTimeout('autoChange()', 3000);
				}
			}
		
			
/* =============================================================================================
   AkBox 
 =============================================================================================== */			
			var AkBoxWidth = 688;
			
			function obscureScreen2(){
				if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
					$("body","html").css({height: "100%", width: "100%"});
					$("html").css("overflow","hidden");
			
					if (document.getElementById("akBoxHideSelect2") === null) {//iframe to hide select elements in ie6
						$("body").append("<iframe id='akBoxHideSelect2'></iframe><div id='akBoxOverlay2'></div>");
					}
				} else {//all others
					if(document.getElementById("akBoxOverlay2") === null){
						$("body").append("<div id='akBoxOverlay2'></div>");
					}
				}
			
				overlay = $('#akBoxOverlay2');
		
				if(detectMacXFF2()){
					overlay.addClass("akBoxOverlayMacFFBGHack2");//use png overlay so hide flash
				} else {
					overlay.addClass("akBoxOverlayBg2");//use background and opacity
				}
			}
		
			function detectMacXFF2() {
				var userAgent = navigator.userAgent.toLowerCase();
				if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
			 	return true;
				}
			}

			function openAkBox2(){
				obscureScreen2();
				if($.browser.msie && $.browser.version == 6){
					p = $('#akBoxWindow2').offset();
					$('#akBoxWindow2').css('top',document.documentElement.scrollTop);
				}
				$('#akBoxWindow2').css({marginLeft: '-' + parseInt((AkBoxWidth / 2),10) + 'px'/*, width: width + 'px'*/}).show();
			}
			
			function closeAkBox2(){
				$('#akBoxWindow2').fadeOut("fast",function(){
					$('#akBoxOverlay2,#akBoxHideSelect2').trigger("unload").unbind().remove();
					$('#akBoxWindow2').hide();
				});
			
				if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
					$("body","html").css({height: "auto", width: "auto"});
					$("html").css("overflow","");
				}
			}
			
			function setAkBoxContent(ctn) { 
			 $('.akBoxContentInner1').hide();
				if (ctn == 'request2') { $('#akBoxAskSlc').fadeIn(1500);  }
				if (ctn == 'request3') { $('#akBoxBrochure').fadeIn(1500);  }
				if (ctn == 'photogallery') { $('#akBoxPhotoGallery').fadeIn(1500); }
				if (ctn == 'thankyou') { $('#akBoxThankYouMessage').fadeIn(1500); }
				if (ctn == 'video') { $('#akBoxVideo').fadeIn(1500); }
				if (ctn == 'newsletter') { $('#akBoxNewsletter').fadeIn(1500); }
				if (ctn == 'condizioni-generali') { $('#akBoxCondizioni').fadeIn(1500); }
				openAkBox2();
		 }
			
/* =============================================================================================
   Check Form Data
 =============================================================================================== */ 
			
			function isValidEmail(myemail){
				var status = false;     
				var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
					
				if (myemail.search(emailRegEx) == -1) {
					//status = false; 
				} else {
					status = true;
				}
								
				return status;
			}

			
			function checkSiteForm(formName, fieldNameRequired) {
				var fieldArray = fieldNameRequired.split(';'); 
				var isError = 0;
			 var tmp = '';
				
				for (x=0;x<fieldArray.length;x++) {
					
					if ($('#'+formName+' input[name='+fieldArray[x]+']').length != 0) {
						tmp = $('#'+formName+' input[name='+fieldArray[x]+']');
					} else if ($('#'+formName+' textarea[name='+fieldArray[x]+']').length != 0) {
					 tmp = $('#'+formName+' textarea[name='+fieldArray[x]+']');
					}
					
					
					if (tmp.val() == '') { 
						isError = 1; 
						tmp.addClass('inputOn');
					} else {
						tmp.removeClass('inputOn');
					}
					
					/* Check E-mail */
					if (fieldArray[x] == 'email') { 
					 if (!isValidEmail(tmp.val())) {
							isError = 1;
							tmp.addClass('inputOn');
						} else {
							tmp.removeClass('inputOn');
						}
					}
				}

				if (isError == 1) {
					return false;
				} else {
					return true;
				}
			}
			
/* =============================================================================================
   AkBox 
			- Request Brochure
 =============================================================================================== */ 
			function checkBrochureData(language) {
    
				//alert($('#frmRequestBrochure input[name=subscribeNewsletter]').is(':checked'));
				$('#akBoxBrochure .completeRequiredFields').hide();
				
				if(
							(
								checkSiteForm('frmRequestBrochure','firstname;lastname;email;zip;country;address;city') &&
							 $("#akBoxBrochure select[name=wheredidhear]").val() != '' &&
							 $('#frmRequestBrochure input[name=sendigModeEmail]').val() != 1
							 ) ||	(
								checkSiteForm('frmRequestBrochure','firstname;lastname;email') &&
							 $("#akBoxBrochure select[name=wheredidhear]").val() != '' &&
							 $('#frmRequestBrochure input[name=sendigModeEmail]').val() == 1
							 )
							) {
					// ok
					
					var data = $('#frmRequestBrochure').serialize();
					var randomnumber=Math.floor(Math.random()*1000000000);
					$.get(siteUrl+'/requests.php?siteFunction=frmRequestBrochure&randomNumber='+randomnumber, data , 
											function (result){
												 if (result == 1) {
														pageTracker._trackPageview('/'+language+'/request_brochure_thankyou');
														//setAkBoxContent('thankyou'); 
													 setTimeout("location.href = '/"+language+"/request-brochure-thankyou';",0);
													}
					      });

				} else {
				 $('#akBoxBrochure .completeRequiredFields').slideDown();
				}
				
				
			}
			
/* =============================================================================================
   AkBox 
			- Ask SLC
	=============================================================================================== */ 
			function checkAskSlcData(language) {

				//alert($('#frmRequestBrochure input[name=subscribeNewsletter]').is(':checked'));
				$('#frmAskSlc .completeRequiredFields').hide();
				if(checkSiteForm('frmAskSlc','firstname;lastname;email;remarks')) {
					// ok
					
					var data = $('#frmAskSlc').serialize();
					var randomnumber=Math.floor(Math.random()*1000000000);
					$.get(siteUrl+'/requests.php?siteFunction=frmAskSlc&randomNumber='+randomnumber, data , 
											function (result){
												 if (result == 1) {
														pageTracker._trackPageview('/'+language+'/ask_slc_thankyou');
														//setAkBoxContent('thankyou'); 
														setTimeout("location.href = '/"+language+"/ask-slc-thankyou';",0);
													}
					      });

				} else {
				 $('#akBoxAskSlc .completeRequiredFields').slideDown();
				}
			}		
			
	/* =============================================================================================
   AkBox 
			- Subscribe to newsletter
	=============================================================================================== */ 
			function checkNewsletterData(language) {

				//alert($('#frmRequestBrochure input[name=subscribeNewsletter]').is(':checked'));
				if(checkSiteForm('frmNewsletter','firstname;lastname;email')) {
					// ok
					
					var data = $('#frmNewsletter').serialize();
					var randomnumber=Math.floor(Math.random()*1000000000);
					$.get(siteUrl+'/requests.php?siteFunction=frmNewsletter&randomNumber='+randomnumber, data , 
											function (result){
												 if (result == 1) {
														pageTracker._trackPageview('/'+language+'/subscribe_newsletter_thankyou');
														//setAkBoxContent('thankyou'); 
														setTimeout("location.href = '/"+language+"/subscribe-newsletter-thankyou';",0);
													}
					      });

				} else {
				 // error	
				}
			}		
			
	/* =============================================================================================
   Photogallery
=============================================================================================== */
			function changePhotogallery(pGallery) {
				
				//alert($('#frmRequestBrochure input[name=subscribeNewsletter]').is(':checked'));			
				 var data = 'idGallery='+pGallery;
					var randomnumber=Math.floor(Math.random()*1000000000);
					$.get(siteUrl+'/requests.php?siteFunction=photogallery&randomNumber='+randomnumber, data , 
											function (result){
												 $('#akBoxPhotoGallery .akBoxContentInner2').html(result);
													//console.log(result);
													
					      });

			}	