/*
* jQuery Mobile Framework : "mouse" plugin
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
// https://github.com/jquery/jquery-mobile/blob/master/js/jquery.mobile.vmouse.js
// This plugin is an experiment for abstracting away the touch and mouse
// events so that developers don't have to worry about which method of input
// the device their document is loaded on supports.
//
// The idea here is to allow the developer to register listeners for the
// basic mouse events, such as mousedown, mousemove, mouseup, and click,
// and the plugin will take care of registering the correct listeners
// behind the scenes to invoke the listener at the fastest possible time
// for that device, while still retaining the order of event firing in
// the traditional mouse environment, should multiple handlers be registered
// on the same element for different events.
//
// The current version exposes the following virtual events to jQuery bind methods:
// "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel"

(function($,window,document,undefined){var dataPropertyName="virtualMouseBindings",touchTargetPropertyName="virtualTouchID",virtualEventNames="vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),touchEventProps="clientX clientY pageX pageY screenX screenY".split(" "),activeDocHandlers={},resetTimerID=0,startX=0,startY=0,didScroll=false,clickBlockList=[],blockMouseTriggers=false,blockTouchTriggers=false,eventCaptureSupported="addEventListener" in document,$document=$(document),nextTouchID=1,lastTouchID=0;$.vmouse={moveDistanceThreshold:10,clickDistanceThreshold:10,resetTimerDuration:1500};function getNativeEvent(event){while(event&&typeof event.originalEvent!=="undefined"){event=event.originalEvent}return event}function createVirtualEvent(event,eventType){var t=event.type,oe,props,ne,prop,ct,touch,i,j;event=$.Event(event);event.type=eventType;oe=event.originalEvent;props=$.event.props;if(oe){for(i=props.length,prop;i;){prop=props[--i];event[prop]=oe[prop]}}if(t.search(/mouse(down|up)|click/)>-1&&!event.which){event.which=1}if(t.search(/^touch/)!==-1){ne=getNativeEvent(oe);t=ne.touches;ct=ne.changedTouches;touch=(t&&t.length)?t[0]:((ct&&ct.length)?ct[0]:undefined);if(touch){for(j=0,len=touchEventProps.length;j<len;j++){prop=touchEventProps[j];event[prop]=touch[prop]}}}return event}function getVirtualBindingFlags(element){var flags={},b,k;while(element){b=$.data(element,dataPropertyName);for(k in b){if(b[k]){flags[k]=flags.hasVirtualBinding=true}}element=element.parentNode}return flags}function getClosestElementWithVirtualBinding(element,eventType){var b;while(element){b=$.data(element,dataPropertyName);if(b&&(!eventType||b[eventType])){return element}element=element.parentNode}return null}function enableTouchBindings(){blockTouchTriggers=false}function disableTouchBindings(){blockTouchTriggers=true}function enableMouseBindings(){lastTouchID=0;clickBlockList.length=0;blockMouseTriggers=false;disableTouchBindings()}function disableMouseBindings(){enableTouchBindings()}function startResetTimer(){clearResetTimer();resetTimerID=setTimeout(function(){resetTimerID=0;enableMouseBindings()},$.vmouse.resetTimerDuration)}function clearResetTimer(){if(resetTimerID){clearTimeout(resetTimerID);resetTimerID=0}}function triggerVirtualEvent(eventType,event,flags){var ve;if((flags&&flags[eventType])||(!flags&&getClosestElementWithVirtualBinding(event.target,eventType))){ve=createVirtualEvent(event,eventType);$(event.target).trigger(ve)}return ve}function mouseEventCallback(event){var touchID=$.data(event.target,touchTargetPropertyName);if(!blockMouseTriggers&&(!lastTouchID||lastTouchID!==touchID)){var ve=triggerVirtualEvent("v"+event.type,event);if(ve){if(ve.isDefaultPrevented()){event.preventDefault()}if(ve.isPropagationStopped()){event.stopPropagation()}if(ve.isImmediatePropagationStopped()){event.stopImmediatePropagation()}}}}function handleTouchStart(event){var touches=getNativeEvent(event).touches,target,flags;if(touches&&touches.length===1){target=event.target;flags=getVirtualBindingFlags(target);if(flags.hasVirtualBinding){lastTouchID=nextTouchID++;$.data(target,touchTargetPropertyName,lastTouchID);clearResetTimer();disableMouseBindings();didScroll=false;var t=getNativeEvent(event).touches[0];startX=t.pageX;startY=t.pageY;triggerVirtualEvent("vmouseover",event,flags);triggerVirtualEvent("vmousedown",event,flags)}}}function handleScroll(event){if(blockTouchTriggers){return}if(!didScroll){triggerVirtualEvent("vmousecancel",event,getVirtualBindingFlags(event.target))}didScroll=true;startResetTimer()}function handleTouchMove(event){if(blockTouchTriggers){return}var t=getNativeEvent(event).touches[0],didCancel=didScroll,moveThreshold=$.vmouse.moveDistanceThreshold;didScroll=didScroll||(Math.abs(t.pageX-startX)>moveThreshold||Math.abs(t.pageY-startY)>moveThreshold),flags=getVirtualBindingFlags(event.target);if(didScroll&&!didCancel){triggerVirtualEvent("vmousecancel",event,flags)}triggerVirtualEvent("vmousemove",event,flags);startResetTimer()}function handleTouchEnd(event){if(blockTouchTriggers){return}disableTouchBindings();var flags=getVirtualBindingFlags(event.target),t;triggerVirtualEvent("vmouseup",event,flags);if(!didScroll){var ve=triggerVirtualEvent("vclick",event,flags);if(ve&&ve.isDefaultPrevented()){t=getNativeEvent(event).changedTouches[0];clickBlockList.push({touchID:lastTouchID,x:t.clientX,y:t.clientY});blockMouseTriggers=true}}triggerVirtualEvent("vmouseout",event,flags);didScroll=false;startResetTimer()}function hasVirtualBindings(ele){var bindings=$.data(ele,dataPropertyName),k;if(bindings){for(k in bindings){if(bindings[k]){return true}}}return false}function dummyMouseHandler(){}function getSpecialEventObject(eventType){var realType=eventType.substr(1);return{setup:function(data,namespace){if(!hasVirtualBindings(this)){$.data(this,dataPropertyName,{})}var bindings=$.data(this,dataPropertyName);bindings[eventType]=true;activeDocHandlers[eventType]=(activeDocHandlers[eventType]||0)+1;if(activeDocHandlers[eventType]===1){$document.bind(realType,mouseEventCallback)}$(this).bind(realType,dummyMouseHandler);if(eventCaptureSupported){activeDocHandlers.touchstart=(activeDocHandlers.touchstart||0)+1;if(activeDocHandlers.touchstart===1){$document.bind("touchstart",handleTouchStart).bind("touchend",handleTouchEnd).bind("touchmove",handleTouchMove).bind("scroll",handleScroll)}}},teardown:function(data,namespace){--activeDocHandlers[eventType];if(!activeDocHandlers[eventType]){$document.unbind(realType,mouseEventCallback)}if(eventCaptureSupported){--activeDocHandlers.touchstart;if(!activeDocHandlers.touchstart){$document.unbind("touchstart",handleTouchStart).unbind("touchmove",handleTouchMove).unbind("touchend",handleTouchEnd).unbind("scroll",handleScroll)}}var $this=$(this),bindings=$.data(this,dataPropertyName);if(bindings){bindings[eventType]=false}$this.unbind(realType,dummyMouseHandler);if(!hasVirtualBindings(this)){$this.removeData(dataPropertyName)}}}}for(var i=0;i<virtualEventNames.length;i++){$.event.special[virtualEventNames[i]]=getSpecialEventObject(virtualEventNames[i])}if(eventCaptureSupported){document.addEventListener("click",function(e){var cnt=clickBlockList.length,target=e.target,x,y,ele,i,o,touchID;if(cnt){x=e.clientX;y=e.clientY;threshold=$.vmouse.clickDistanceThreshold;ele=target;while(ele){for(i=0;i<cnt;i++){o=clickBlockList[i];touchID=0;if((ele===target&&Math.abs(o.x-x)<threshold&&Math.abs(o.y-y)<threshold)||$.data(ele,touchTargetPropertyName)===o.touchID){e.preventDefault();e.stopPropagation();return}}ele=ele.parentNode}}},true)}})(jQuery,window,document);

// CSS-Tricks Organic Tabs
// by: Chris Coyier - http://css-tricks.com/4530-organic-tabs/
(function($){$.organicTabs=function(el,options){var base=this;base.$el=$(el);base.$nav=base.$el.find(".nav");base.init=function(){base.options=$.extend({},$.organicTabs.defaultOptions,options);$(".hide").css({position:"relative",top:0,left:0,display:"none"});base.$nav.delegate("li > a","click",function(){var curList=base.$el.find("a.current").attr("href").substring(1),$newList=$(this),listID=$newList.attr("href").substring(1),$allListWrap=base.$el.find(".list-wrap"),curListHeight=$allListWrap.height();$allListWrap.height(curListHeight);if((listID!=curList)&&(base.$el.find(":animated").length==0)){base.$el.find("#"+curList).fadeOut(base.options.speed,function(){base.$el.find("#"+listID).fadeIn(base.options.speed);var newHeight=base.$el.find("#"+listID).height();$allListWrap.animate({height:newHeight});base.$el.find(".nav li a").removeClass("current");$newList.addClass("current")})}return false})};base.init()};$.organicTabs.defaultOptions={speed:300};$.fn.organicTabs=function(options){return this.each(function(){(new $.organicTabs(this,options))})}})(jQuery);

var utilities = {
	//jumpmenu
	jumpmenu:function() {
		
		$(".jumpmenu-holder .jumpmenu-title").bind('vclick', function() {
			
			$(this).toggleClass('open')
			.siblings('.jumpmenu').slideToggle(400, function() {
				
				// Animation complete.
			});;
		});
	},
	//close
	closemenu:function() {
		$(".jumpmenu-holder .jumpmenu-title").toggleClass('open')
			.siblings('.jumpmenu').slideToggle(400, function() {
				
				// Animation complete.
			});;
		
	},
	//toggle
	toggle:function() {
		
		$("a.toggle").bind('vclick', function() {
			$(this).toggleClass('open');
			$($(this).attr('href')).slideToggle(400, function() {
				
				// Animation complete.
			});;
		});
	},
	//tabs rete commerciale
	tabs:function() {
		$(".rete-commerciale #content").organicTabs();
	},
	//menu
	menuUtilizzo:function() {
		var html_text=""
		var str=location.hash
		var ar_hash=str.split('-')
		if($('#utilizzo'.length)){
			$.ajax({ type: "GET", url: "xml/utilizzo.xml", dataType: "xml",
			success: function(xml) {
			  $(xml).find('item').each(function() {
				  var id = $(this).attr('id');
				  var titolo =  $('titolo',this).text();
				  var foto =  $('foto',this).text();
				  html_text = '<li><a href="linea-utilizzo.html#!linea-'+id+'"><img src="'+foto+'" alt="'+titolo+'" /> '+titolo+'</a></li>'
				 //caso in cui sono nella pagina linea-utilizzo
				  if($('body').attr('class')=='utilizzo'){
					  if(id==ar_hash[1]){
					 	 var html_selezionato='<span class="title"><img src="'+foto+'" alt="'+titolo+'"/> '+titolo+'</span>'
						 $('.jumpmenu-title').append(html_selezionato);
					  }else{
						 $('#utilizzo').append(html_text);
					  }
				  }else if($('body').attr('class')=='prodotti'){
					 if(id==ar_hash[4]){
						  html_selezionato='<a href="linea-utilizzo.html#!linea-'+id+'"><img src="'+foto+'" alt="'+titolo+'" /> '+titolo+'</a>'
						 $('.back-utilizzo').append(html_selezionato);
					  }else{
						 $('#utilizzo').append(html_text);
					  }
				  }else{
					  $('#utilizzo').append(html_text);
				  }
			  });    
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
		}
	},
	//caricamento dei contenuti da menu utilizzo
	loadUtilizzo:function() {
		$('.macrocategoria').text("")
		var html_text=""
		var str=location.hash
		var ar_hash=str.split('-')
		//inizio if hash
		if(ar_hash[1]){ 
			$.ajax({ type: "GET", url: "xml/fromutilizzo.xml.php?lingua=1&utilizzo="+ar_hash[1], dataType: "xml",
			//$.ajax({ type: "GET", url: "xml/fromutilizzo.xml", dataType: "xml",
			success: function(xml) {
				//caricamento della macrocategorie
			 	$(xml).find('macrocategoria').each(function() {
					 var titolo_macrocategoria = $('titolo',this).text();
					 var id_macrocategoria=$(this).attr('id')
					 html_text = html_text+'<h2>'+titolo_macrocategoria+'</h2>'
					 //caricamento della categorie
					 $(xml).find('categoria').each(function() {
						 if($(this).attr('macrocategoriaID')==id_macrocategoria){
							 var id_categoria=$(this).attr('id')
							 var titolo_categoria = $('titolo',this).text();
							 html_text=html_text+'<h3>'+titolo_categoria+'</h3>'
							 html_text=html_text+'<ul class="products clearfix">'
							 //caricamento della linea
							 $(xml).find('linea').each(function() {
								 if($(this).attr('categoriaID')==id_categoria){
									 var id_linea = $(this).attr('id')
									 var titolo_linea = $('titolo',this).text();
									 var img_linea = $('img',this).text();
									 var str_prodotto=id_macrocategoria+"-"+id_categoria+"-"+id_linea+"-"+ar_hash[1]
									 html_text=html_text+'<li><a href="prodotti.html#!prodotto-'+str_prodotto+'" title="'+titolo_linea+'"><img src="../'+img_linea+'" alt="'+titolo_linea+'"></a></li>'
								 }
							 });
							  html_text=html_text+'</ul>'
						 }
					 });
					 $('.macrocategoria').html(html_text);
			  });     
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
		}
		//fine if hash
	},
	//fine caricamento dei contenuti da menu utilizzo
	//
	//caricamento dei prodotti
	loadProdotto:function() {
		
		var str=location.hash
		var ar_hash=str.split('-')
		//ar_hash[1] -> macrocategoria
		//ar_hash[2] -> categoria
		//ar_hash[3] -> linea
		//inizio if hash
		if(ar_hash[3]){ 
			$.ajax({ type: "GET", url: "xml/prodotti.xml.php?lingua=1&linea="+ar_hash[3], dataType: "xml",
			//$.ajax({ type: "GET", url: "xml/prodotto.xml", dataType: "xml",
			success: function(xml) {
				//caricamento della macrocategorie
			 	$(xml).find('prodotto').each(function() {
					var html_text='<div class="box">'
					var id_prodotto = $(this).attr('id');
					var titolo_prodotto = $('titolo',this).text();
					var foto_prodotto=$('img',this).text();
					html_text = html_text+'<h2>'+titolo_prodotto+'</h2>'
					html_text = html_text+'<img src="../'+foto_prodotto+'" alt="'+titolo_prodotto+'">'
					$(xml).find('versioneprodotto').each(function() {
						if($(this).attr('prodID')==id_prodotto){
							var dim_text=$('dimensione',this).text();
							var conf_text=$('confezione',this).text();
							html_text = html_text+'<table><tr><th scope="row">Diametro</th><td>'
							html_text = html_text+dim_text+'</td></tr><tr><th scope="row">Pz/Conf</th><td>'
							html_text = html_text+conf_text+'</td></tr></table>'
						}
					});
					html_text = html_text+'</div>'
					 $('#elencoprodotti').append(html_text);
				});
				
			 	
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
		  //caricamento dettaglio categoria e macrocategoria
		  $.ajax({ type: "GET", url: "xml/fromutilizzo.xml.php?lingua=1&utilizzo="+ar_hash[4], dataType: "xml",
		  //$.ajax({ type: "GET", url: "xml/fromutilizzo.xml", dataType: "xml",
		  success: function(xml) {
			 		var titolo_macrocategoria
					var titolo_categoria
					var titolo_linea
					var desc_linea
			 		$(xml).find('macrocategoria').each(function() {
						if($(this).attr('id')==ar_hash[1]){
							titolo_macrocategoria = $('titolo',this).text()
						}
					});
					$(xml).find('categoria').each(function() {
						if($(this).attr('id')==ar_hash[2]){
							titolo_categoria = $('titolo',this).text();
						}
					});
					var html_addlinea=''
					$(xml).find('linea').each(function() {
						if($(this).attr('categoriaID')==ar_hash[2]){
							if($(this).attr('id')==ar_hash[3]){
								titolo_linea = $('titolo',this).text();
								desc_linea = $('testo',this).text();
								html_addlinea=html_addlinea+'<li class="active"><a href="prodotti.html">'+titolo_linea+'</a></li>'
							}else{
								var titolo_addlinea=$('titolo',this).text();
								var str_prodotto=ar_hash[1]+"-"+ar_hash[2]+"-"+$(this).attr('id')+"-"+ar_hash[4]
								html_addlinea=html_addlinea+'<li><a href="prodotti.html#!prodotto-'+str_prodotto+'">'+titolo_addlinea+'</a></li>'	 
							}
						}
					});
					html_text='<p class="categoria">'+titolo_macrocategoria+'</p>'
					html_text=html_text+'<h1>'+titolo_categoria+' | <strong>'+titolo_linea+'</strong></h1>'
					$('#titoloprodotto').append(html_text);
					$('.description').append(desc_linea);
					//
					$('.jumpmenu').append(html_addlinea);
					
				},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
		}
		//fine if hash
	},
	//fine caricamento dei prodotti
	//caricamento novita
	loadNovita:function() {
			$.ajax({ type: "GET", url: "xml/novita.xml.php?lingua=1", dataType: "xml",
			//$.ajax({ type: "GET", url: "xml/novita.xml", dataType: "xml",
			success: function(xml) {
				//caricamento della macrocategorie
			 	$(xml).find('item').each(function() {
					 var data_novita = $('data',this).text();
					 var titolo_novita = $('titolo',this).text();
					 var testo_novita = $('testo',this).text();
					 var foto_novita=$('img',this).text();
					 var pdf_novita=$('pdf',this).text();
					 var pdfpeso_novita=$('pdf',this).attr('peso')
					 var html_text = '<div class="box"><h2><strong>'+data_novita+'</strong> | '+titolo_novita+'</h2>'
					 html_text=html_text+'<img src="../'+foto_novita+'" alt="'+titolo_novita+'">'
					 html_text=html_text+'<p>'+testo_novita+'</p>'
					 if(pdf_novita!=""){
						  html_text=html_text+'<p><a href="../'+pdf_novita+'" class="pdf">Scarica pdf ('+pdfpeso_novita+')</a></p>'
					 }
					  html_text=html_text+'</div>'
					 $('#content').append(html_text)
			  });     
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
	},
	//fine caricamento novita
	//caricamento cataloghi
	loadCataloghi:function() {
			$.ajax({ type: "GET", url: "xml/cataloghi.xml.php?lingua=1", dataType: "xml",
			//$.ajax({ type: "GET", url: "xml/cataloghi.xml", dataType: "xml",
			success: function(xml) {
				
				//caricamento della macrocategorie
			 	$(xml).find('catalogo').each(function() {
					
					 var titolo_catalogo = $('titolo',this).text();
					 var testo_catalogo = $('descrizione',this).text();
					 var foto_catalogo=$('img',this).text();
					 var pdf_catalogo=$('pdf',this).text();
					 var pdfpeso_catalogo=$('pdf',this).attr('peso')
					
					 var html_text = '<div class="box"><h2>'+titolo_catalogo+'</h2>'
					 html_text=html_text+'<img src="../'+foto_catalogo+'" alt="'+titolo_catalogo+'">'
					 html_text=html_text+'<p>'+testo_catalogo+'</p>'
					 if(pdf_catalogo!=""){
						  html_text=html_text+'<p><a href="../'+pdf_catalogo+'" class="pdf">Scarica pdf ('+pdfpeso_catalogo+')</a></p>'
					 }
					  html_text=html_text+'</div>'
					  
					 $('#content').append(html_text);
			  });     
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
	},
	//fine caricamento cataloghi
	//caricamento contatti
	loadContatti:function() {
			$.ajax({ type: "GET", url: "xml/contatti.xml.php?lingua=1", dataType: "xml",
			//$.ajax({ type: "GET", url: "xml/contatti.xml", dataType: "xml",
			success: function(xml) {
			 	$(xml).find('testoIT').each(function() {
					var testo_contatti = $(this).text();
					$('.box').append(testo_contatti);
			  });     
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
	},
	//fine caricamento contatti
	//creazione menu rete
	menuRete:function() {
		var str=location.hash
		var ar_hash=str.split('-')
		//ar_hash[0] -> retail
		//ar_hash[1] -> professional
		//ar_hash[2] -> vendor
		var tipo_rete=0
		if(ar_hash[1]==1){
			tipo_rete=1 //retail
		}
		if(ar_hash[2]==1){
			tipo_rete=2 //professional
		}
		if(ar_hash[3]==1){
			tipo_rete=3 //vendor
		}
		if(tipo_rete==0){
			tipo_rete=1
		}
		$('#menurete').text("")
		var html_text='<li><a href="rete-commerciale.html#!rete-1-0-0" id="p1">Retail</a></li><li><a href="rete-commerciale.html#!rete-0-1-0" id="p2">Professional</a></li><li><a href="rete-commerciale.html#!rete-0-0-1" id="p3">Vending</a></li>'
		$('#menurete').append(html_text);
		$('#p'+tipo_rete).css('color','#fff')
		$('#p'+tipo_rete).css('background','#ad0101')
		$('#p'+tipo_rete).css('background',' -moz-linear-gradient(45deg, #ad0101 0%, #ad0101 47%, #bc1010 52%, #d42828 59%, #e03434 63%, #e03434 100%)')
		$('#p'+tipo_rete).css('background','#-webkit-gradient(linear, left bottom, right top, color-stop(0%,#ad0101), color-stop(47%,#ad0101), color-stop(52%,#bc1010), color-stop(59%,#d42828), color-stop(63%,#e03434), color-stop(100%,#e03434))')
		$('#p'+tipo_rete).css('background','-webkit-linear-gradient(45deg, #ad0101 0%,#ad0101 47%,#bc1010 52%,#d42828 59%,#e03434 63%,#e03434 100%)')
		$('#p'+tipo_rete).css('background','-o-linear-gradient(45deg, #ad0101 0%,#ad0101 47%,#bc1010 52%,#d42828 59%,#e03434 63%,#e03434 100%)')
		$('#p'+tipo_rete).css('background','-ms-linear-gradient(45deg, #ad0101 0%,#ad0101 47%,#bc1010 52%,#d42828 59%,#e03434 63%,#e03434 100%)')
		$('#p'+tipo_rete).css('background','linear-gradient(45deg, #ad0101 0%,#ad0101 47%,#bc1010 52%,#d42828 59%,#e03434 63%,#e03434 100%)')
	},
	//fine creazione menu rete
	//caricamento rete
	loadRete:function() {
			//
			var ar_regioni=new Array()
			ar_regioni.push({nome:"aosta_mc",valore:"Valle d'Aosta",id:"16"})
			ar_regioni.push({nome:"piemonte_mc",valore:"Piemonte",id:"13"})
			ar_regioni.push({nome:"lombardia_mc",valore:"Lombardia",id:"19"})
			ar_regioni.push({nome:"liguria_mc",valore:"Liguria",id:"18"})
			ar_regioni.push({nome:"trentino_mc",valore:"Trentino-Alto Adige",id:"5"})
			ar_regioni.push({nome:"veneto_mc",valore:"Veneto",id:"17"})
			ar_regioni.push({nome:"friuli_mc",valore:"Friuli-Venezia Giulia",id:"15"})
			ar_regioni.push({nome:"romagna_mc",valore:"Emilia-Romagna",id:"14"})
			ar_regioni.push({nome:"toscana_mc",valore:"Toscana",id:"12"})
			ar_regioni.push({nome:"marche_mc",valore:"Marche",id:"1"})
			ar_regioni.push({nome:"umbria_mc",valore:"Umbria",id:"20"})
			ar_regioni.push({nome:"lazio_mc",valore:"Lazio",id:"9"})
			ar_regioni.push({nome:"abruzzo_mc",valore:"Abruzzo",id:"2"})
			ar_regioni.push({nome:"molise_mc",valore:"Molise",id:"4"})
			ar_regioni.push({nome:"campania_mc",valore:"Campania",id:"8"})
			ar_regioni.push({nome:"puglia_mc",valore:"Puglia",id:"6"})
			ar_regioni.push({nome:"basilicata_mc",valore:"Basilicata",id:"3"})
			ar_regioni.push({nome:"calabria_mc",valore:"Calabria",id:"7"})
			ar_regioni.push({nome:"sicilia_mc",valore:"Sicilia",id:"11"})
			ar_regioni.push({nome:"sardegna_mc",valore:"Sardegna",id:"10"})
			//
			var str=location.hash
			var ar_hash=str.split('-')
			//ar_hash[0] -> retail
			//ar_hash[1] -> professional
			//ar_hash[2] -> vendor
			var tipo_rete=0
			if(ar_hash[1]==1){
				tipo_rete=1 //retail
			}
			if(ar_hash[2]==1){
				tipo_rete=2 //professional
			}
			if(ar_hash[3]==1){
				tipo_rete=3 //vendor
			}
			if(tipo_rete==0){
				tipo_rete=1
			}
			
			var html_text="<h2>Agenti</h2>"
			$.ajax({ type: "GET", url: "xml/retailprofessionalmobile.xml.php?tipo="+tipo_rete+"&regione=all", dataType: "xml",
			//$.ajax({ type: "GET", url: "xml/rivenditori.xml", dataType: "xml",
			success: function(xml) {
				
			 	$(xml).find('regione').each(function() {
					for(var i=0;i<ar_regioni.length;i++){
						if($(this).attr('id')==ar_regioni[i].id){
							var nome_regione=ar_regioni[i].valore
							html_text=html_text+'<h3>'+nome_regione+'</h3>'
						}
					}
					$(this).find('agente').each(function() {
						var nome_agente=$('nome',this).text()
						var cognome_agente=$('cognome',this).text()
						var mail_agente=$('mail',this).text()
						var telefono_agente=$('telefono',this).text()
						var citta_agente=$('citta',this).text()
						
						html_text=html_text+'<p><strong>'+nome_agente+" "+cognome_agente+'</strong><br>'+citta_agente+'</p>'
						if(telefono_agente!=""){
							html_text=html_text+'<p><a href="tel:'+telefono_agente+'" class="contact tel">'+telefono_agente+'</a></p>'
						}
						if(mail_agente!=""){
							html_text=html_text+'<p><a href="mailto:'+mail_agente+'" class="contact mail">'+mail_agente+'</a></p>'
						}
					});  
			  });   
			  $('.list-wrap').append(html_text); 
			  ////////////////////////////////////////////////////////////////////////////////////
			  //caricamento rivenditori
			  //////////////////////////////////////////////////////////////////////////////////////
			  if(tipo_rete==1){
				  html_text='<h2>Rivenditori</h2>'
				  $('.list-wrap').append(html_text);
				  var str="Huhtamaki è un partner esperto e competente nel mercato del monouso, grazie alla capacità produttiva, alla completezza dell'offerta e alla flessibilità nel proporre soluzioni di prodotto e di merchandising in linea con le esigenze di ogni cliente.<br>Huhtamaki è presente con i propri prodotti a marchio Bibo o a marchio del cliente, in tutte le principali insegne della GDO.<br>Conad, Coop, Auchan, Carrefour, Esselunga, Finiper, Bennet, Sigma, Crai, Unes,Consilia, Sidis sono solo alcuni dei nostri partner della grande distribuzione italiana. <br><br>L'azienda dispone di una rete commerciale  capillare, in grado di garantire un contatto veloce ed efficace con tutti i clienti, anche medio-piccoli, dislocati sull'intero territorio nazionale.<br>Clicca sulla cartina di sinistra per ottenere i recapiti del referente a te più vicino. <br>"
				  $('.list-wrap').append(str)
			  	}else{
					$.ajax({ type: "GET", url: "xml/agentimobile.php?vending="+ar_hash[3]+"&professional="+ar_hash[2]+"&nazione=1", dataType: "xml",
					//$.ajax({ type: "GET", url: "xml/agenti.xml", dataType: "xml",
					success: function(xml) {
						html_prov=""
						html_reg=""
						html_riv=""
						html_text='<h2>Rivenditori</h2>'
						$('.list-wrap').append(html_text); 
						
						$(xml).find('regione').each(function() {
							var nome_regione=$(this).find('titolo_regione').text()
							html_reg='<h3>'+nome_regione+'</h3>'
							//
							$(this).find('provincia').each(function() {
								var nome_provincia=$(this).find('titolo_provincia').text()
								var sigla_provincia=$(this).find('sigla').text()
								html_prov='<h4>'+nome_provincia+" ("+sigla_provincia+')</h4>'
								if($(this).find('elemento').length>0){
									var html=html_reg+html_prov
									$('.list-wrap').append(html); 
									html_reg="<br>"
								}
								//
								$(this).find('elemento').each(function() {
									var titolo_rivenditore=$('titolo',this).text()
									var indirizzo_rivenditore=$('indirizzo',this).text()
									var citta_rivenditore=$('citta',this).text()
									var telefono_rivenditore=$('telefono',this).text()
									var fax_rivenditore=$('fax',this).text()
									var email_rivenditore=$('email',this).text()
									var sito_rivenditore=$('sito',this).text()
									var cap_rivenditore=$('cap',this).text()
									var sito_rivenditore=$('sito',this).text()
									var note_rivenditore=$('note',this).text()
									var cellulare_rivenditore=$('cellulare',this).text()
									var lat_rivenditore=$('x',this).text()
									var lng_rivenditore=$('y',this).text()
									html_riv=html_riv+'<p><strong>'+titolo_rivenditore+'</strong><br>'
									html_riv=html_riv+indirizzo_rivenditore+'<br>'
									html_riv=html_riv+cap_rivenditore+" "+citta_rivenditore+'</p>'
									if(telefono_rivenditore!=""){
										html_riv=html_riv+'<p><a href="tel:'+telefono_rivenditore+'" class="contact tel">'+telefono_rivenditore+'</a></p>'
									}
									if(fax_rivenditore!=""){
										html_riv=html_riv+'<p><a href="fax:'+fax_rivenditore+'" class="contact fax">'+fax_rivenditore+'</a></p>'
									}
									if(cellulare_rivenditore!=""){
										html_riv=html_riv+'<p><a href="tel:'+cellulare_rivenditore+'" class="contact mobile">'+cellulare_rivenditore+'</a></p>'
									}
									if(email_rivenditore!=""){
										html_riv=html_riv+'<p><a href="mailto:'+email_rivenditore+'" class="contact mail">'+email_rivenditore+'</a></p>'
									}
									if(sito_rivenditore!=""){
										html_riv=html_riv+'<p><a href="'+sito_rivenditore+'" class="contact www">'+sito_rivenditore+'</a></p>'
									}
									if(lat_rivenditore!=""){
										html_riv=html_riv+'<p><a href="http://maps.google.com/maps?q='+lat_rivenditore+','+lng_rivenditore+'&iwlocA" class="contact map">mappa</a></p>'
									}
									$('.list-wrap').append(html_riv);
									
									 html_riv=""
								}); 
								
								
							}); 
							
					  });   
					  
					},
					error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
				 });
			  }
			 ////////////////////////////////////////////////////////////////////////////////////
			  //fine caricamento rivenditori
			  //////////////////////////////////////////////////////////////////////////////////////
			},
			error: function(request, error, tipo_errore) {
						//alert(error+': '+ tipo_errore);
						}
		  });
	},
	//fine caricamento contatti
}

jQuery(document).ready(function($){
  MBP.hideUrlBar();
  utilities.jumpmenu();
  utilities.toggle();
  utilities.tabs();
  utilities.menuUtilizzo();
  if($('body').attr('class')=='utilizzo'){
	   utilities.loadUtilizzo();
  }
  if($('body').attr('class')=='prodotti'){
	utilities.loadProdotto();
  }
  if($('body').attr('class')=='novita'){
	   utilities.loadNovita();
  }
  if($('body').attr('class')=='cataloghi'){
	   utilities.loadCataloghi();
  }
  if($('body').attr('class')=='contatti'){
	   utilities.loadContatti();
  }
   if($('body').attr('class')=='rete-commerciale'){
	   utilities.menuRete();
	  utilities.loadRete();
  }
  $(window).bind('hashchange', function() {
	  
	  if($('body').attr('class')=='utilizzo'){
			$('.macrocategoria').text("")
			$('#utilizzo').text("")
			$('.back-utilizzo').text("")
			$('.jumpmenu-title').text("")
			utilities.closemenu()
			utilities.menuUtilizzo();
			utilities.loadUtilizzo();
			
		}
		
 	 	if($('body').attr('class')=='prodotti'){
			$('#titoloprodotto').text("")
			$('.description').text("")
			$('.jumpmenu').text("")
			$('#elencoprodotti').text("")
			utilities.loadProdotto();
			utilities.closemenu()
		}
		if($('body').attr('class')=='rete-commerciale'){
			$('.list-wrap').text("")
			utilities.menuRete();
			utilities.loadRete();
			
		}
  });

});

