
function switchFilter(id,page,filter, mixed){

	if(filter=="type" && String(id)=="none"){
		window.location=page+"?"+filter+"=none";
		return;
	}

	if(mixed==0){
		window.location=page+"?"+filter+"="+id;
	}else{
	//var querystring = location.search;	
	var urlString=self.location.href.split("?");
		if(urlString[1]==undefined || urlString[1]=="" || urlString[1]=="type=none"){
			window.location=page+"?"+filter+"="+id;
		}else{
			//prima di procedere elimino il parametro pNum
			
			if(urlString[1].indexOf("Rs1pNum=")==-1){
				var paramString=urlString[1];
			}else{
				var strippingParamArray=urlString[1].split("Rs1pNum")
				// Se pNum è l'ultimo parametro...
				if(strippingParamArray[1].indexOf("&")==-1){
					var paramString=strippingParamArray[0];
				}else{
					var otherParams=strippingParamArray[1].split("&")
					otherParams=otherParams.slice (1,otherParams.length );
					
					var paramString=otherParams.join("&");

				}
				
				
			}
			
	
			var params=paramString.split("&")
			var totParams=params.length;
			var paramFound=false;

			for(i=0;i<params.length;i++){
				if(params[i].split("=")[0]==filter){
					var paramFound=true;
					if(id!=0){
						params[i]=filter+"="+id;
					}else{
						params.splice(i,1);
					}					
				}
			}
			if(paramFound==false){
				params.push(filter+"="+id)
			}
			
			var querystring=params.join("&");

			window.location=urlString[0]+"?"+querystring
		}
	}	

}




function sendMail (frmName,lang){
	
	
	 if (document.forms[frmName].nome.value == "") {
	   alert("Prego compilare il campo Nome e cognome")
	   document.forms[frmName].nome.focus();
	   return false;}   

	if (document.forms[frmName].txt.value  == "") {
	   alert("Prego compilare il campo Testo")
	   document.forms[frmName].txt.focus();
	   return false;}
	
	
	$('contatti').tween('opacity',1,0.4);
	
	   
	xmlHttp=GetXmlHttpObject() //See if it works with users browser.
	
	var url = RootPath + "www/ajaxindex.php?pag=../www/ajaxphp/mailSend.php";
	
	var params = Array();

	params.push('nome='+ document.forms[frmName].nome.value);
	params.push('txt=' + document.forms[frmName].txt.value);
	params.push('email=' + document.forms[frmName].email.value);
	var mypars=params.join("&");
	
	xmlHttp.open("POST", url, true);
	
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", mypars.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			//alert(xmlHttp.responseText);
			if(xmlHttp.responseText=='0'){
				alert("Attenzione: problemi di invio.\nRiprovare piu' tardi.");
				$('contatti').tween('opacity',0.4,1);
				
			}else{
				$('contatti').setStyle('opacity',0);
				$('contatti').set("html","&nbsp;&nbsp;La richiesta &egrave; stata inviata, sarete ricontattati al pi&ugrave; presto.");
				$('contatti').tween('opacity',0,1);
			}
		
		 } 
	 };
	xmlHttp.send(mypars);   
	
}




function sendLucarinaldiNewsletter(frmName){
	
	
	var alertMsg = confirm ("Attenzione: stai per inviare la newsletter selezionata. Vuoi continuare?")
	if (!alertMsg){
		$('waitClip').setStyle('display', 'none');
		return;
	}else{
		
		$('waitClip').setStyle('display', 'block');
		
		xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
		var url = RootPath + "www/ajaxindex.php?pag=../www/ajaxphp/newsletterSend.php";
		
		var params = Array();

		params.push('id='+ document.forms[frmName].id.value);
		params.push('idgruppo=' + document.forms[frmName].idgruppo_int.value);
		var mypars=params.join("&");
		
		xmlHttp.open("POST", url, true);
		
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", mypars.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange=function(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				//alert(xmlHttp.responseText);
				if(xmlHttp.responseText=='0'){
					alert("Attenzione: problemi di invio");
					$('waitClip').setStyle('display', 'none');
				}else{
					window.location = self.location;
				}
			
			 } 
		 };
		xmlHttp.send(mypars);
		
		
		
	}		
}

function openContent(fileName,height,projectType){

		$('whiteContent').set('html', "");
		$('whitePanel').setStyle('opacity',100);
		$('whiteContent').setStyle('height', height);

		var waitClip  = new Element('div', {id: 'waitClip'});
		$('whiteContent').grab(waitClip);
		
		var xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
		var url = RootPath + "www/ajaxindex.php?pag=../www/ajaxphp/getPageContent.php";
		
		var params = Array();
		

		tmpArray=fileName.split("?id=");
		fileName=tmpArray[0];
		id=tmpArray[1];

		params.push('fileName=' + fileName);
		params.push('id=' + id);		
		var mypars=params.join("&");
		
		xmlHttp.open("POST", url, true);
		
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", mypars.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange=function(){
			if (this.readyState==4 || this.readyState=="complete"){ 
				if(this.responseText=='0'){

				}else{
					$('waitClip').destroy();					
					$('whiteContent').setStyle('opacity',0);
					$('whiteContent').set('html', this.responseText);
					var scroller = $('leftScroller');
					if(scroller){
						setScrollers();
					}
					
					var thumb0 = $('thumb0');					
					if(thumb0){		
						//replacePic($('thumb0').get('imageFile'),$('thumb0').get('imageId'),1,projectType);
						$('whiteContent').tween('opacity', 0,1);
						milkbox=new Milkbox({ centered:true });
						milkbox.reloadPageGalleries();
						setMyScrollbar();
					}else{
						$('whiteContent').tween('opacity', 0,1);
					}
					
					hideShowNavBar(false);
					
				}
			
			 } 
		 };
		xmlHttp.send(mypars);
		


}

function itemClose(item){
	var myFx = new Fx.Tween('whitePanel', {property: 'opacity'}, {transition: 'linear'});	
	hideShowNavBar(true);
	myFx.start(1,0,0.2).chain(
	function(){
		$('whiteContent').setStyle('opacity',0);
		$('whiteContent').set('html','');
		
		if(undefined!==window.flashvars){
			swfobject.removeSWF("mainMenu");
			var flashPlaceholder  = new Element('div', {id: 'flashPlaceholder'});
			$('mainContainer').grab(flashPlaceholder);		
			swfobject.embedSWF("share/swf/topMenu.swf", "flashPlaceholder", "645", "580", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		}
		
		}
	);
}

		

function setScrollers(){

	$('leftScroller').addEvent('click', function() {
		getSlideSteps();
		if(currentSlidePercentage<100){
			currentSlidePercentage+=33;
			myProducts.set(currentSlidePercentage);
		}
	});
	
	$('rightScroller').addEvent('click', function() {
		getSlideSteps();
		if(currentSlidePercentage>0){
			currentSlidePercentage-=33;
			myProducts.set(currentSlidePercentage);
		}
	});
	

	  $('leftScroller').addEvent('mouseenter', function() {	
		$('leftScroller').setStyle('opacity',0.3);
		
	  });
	  
	  $('leftScroller').addEvent('mouseleave', function() {
		$('leftScroller').setStyle('opacity',1); 
	  });
	  
	  $('rightScroller').addEvent('mouseenter', function() {		  	
		$('rightScroller').setStyle('opacity',0.3);
		
	  });
	  
	  $('rightScroller').addEvent('mouseleave', function() {
		$('rightScroller').setStyle('opacity',1);
	  });
	  
}

function getSlideSteps(){
	
	if(myProducts.step<33){
		currentSlidePercentage=0;		
	}
	if(myProducts.step>=33 && myProducts.step<66){
		currentSlidePercentage=33;		
	}
	if(myProducts.step>=66 && myProducts.step<100){
		currentSlidePercentage=66;		
	}

}


function scaleSize(maxW, maxH, currW, currH){
	var ratio = currH / currW;
	if(currW >= maxW && ratio <= 1){
		// larga
		currW = maxW;
		currH = currW * ratio;
		if(currH>maxH){
			currH=maxH;
			currW = currH / ratio;
		}
	} else {
		// alta
		if(currH >= maxH){
		currH = maxH;
		currW = currH / ratio;
		}
	}
	
	return [currW, currH];
}

currentSlidePercentage=0;


function rollOverPic(elem){
	
	$(elem).set('tween', {
    duration: 'short'
	});
	
	
	if($(elem).getStyle('border')!="2px solid #fe8800"){
		$(elem).tween('opacity', 1,0.7);
		//$(elem).setStyle('opacity', 0.45);
	}
	
}

function rollOutPic(elem){
	
	if($(elem).getStyle('border')!="2px solid #fe8800"){
		$(elem).tween('opacity', 0.7,1);
		//$(elem).setStyle('opacity', 1);
	}
}



function getProject(id,projectType){
	
		var xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
		$('whiteContent').set('html', "");
		var waitClip  = new Element('div', {id: 'waitClip'});
		$('whiteContent').grab(waitClip);
		
		var url = RootPath + "www/ajaxindex.php?pag=../www/ajaxphp/getPageContent.php";
		
		var params = Array();

		params.push('fileName=project_popup.php');
		params.push('id=' + id);		
		var mypars=params.join("&");
		
		xmlHttp.open("POST", url, true);
		
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", mypars.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange=function(){
			//alert("loop "+this.readyState + "\n\n"+ this.status +"\n\n"+ this.responseText);
			if (this.readyState==4 || this.readyState=="complete"){ 
				if(this.responseText=='0'){

				}else{
					$('waitClip').destroy();
					$('whiteContent').setStyle('opacity',0);
					$('whiteContent').set('html', this.responseText);
					var scroller = $('leftScroller');
					if(scroller){
						setScrollers();
					}
					var thumb0 = $('thumb0');					
					if(thumb0){		
						//replacePic($('thumb0').get('imageFile'),$('thumb0').get('imageId'),1,projectType);
						milkbox=new Milkbox({ centered:true });
						milkbox.reloadPageGalleries();
						$('whiteContent').tween('opacity', 0,1);
					}
					hideShowNavBar(false);
					setMyScrollbar();

					
				}
			
			 } 
		 };
		xmlHttp.send(mypars);
}


function hideShowNavBar(show){
	
	var navBar = $('navBar');
	
	if(navBar){
	
		if(show==false){		
			$('navBar').setStyles({
			'visibility': 'hidden',
			'opacity': 0,
			'display': 'none'
			})
		}else{
			$('navBar').setStyles({
			'visibility': 'visible',
			'opacity': 100,
			'display': 'block'
			})
		}
	}
}


function setMyScrollbar(){
	
	
	var imageScroller = $('imageScroller');
	if(imageScroller){	

	
	currentSlidePercentage=0;

		myProducts = new ScrollBar('imageList', 'bar', 'knob', {
			offset: -1,
			scroll: {
				duration: 500,
				transition: 'Cubic:out'
			},
			knob: {
				duration: 500,
				transition: 'Cubic:out'
			}
		});
	
	}
	

}


