
function ScreenManager(){}
ScreenManager.prototype={getSize:function(){var width=0;var height=0;if(window.innerWidth){width=window.innerWidth;height=window.innerHeight;}
else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){width=document.documentElement.clientWidth;height=document.documentElement.clientHeight;}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){width=document.body.clientWidth;height=document.body.clientHeight;}
return{width:width,height:height}},getScroll:function(){var scrollX=0;var scrollY=0;if(window.pageYOffset){scrollX=window.pageXOffset;scrollY=window.pageYOffset;}
else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){scrollX=document.body.scrollLeft;scrollY=document.body.scrollTop;}
else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){scrollX=document.documentElement.scrollLeft;scrollY=document.documentElement.scrollTop;}
return{scrollX:scrollX,scrollY:scrollY}}}
function ImagePopupManager(link,loadingText,displayText){link=Xu(link);if(link===null)return;this.upOffset=24;this.leftOffset=1;this.downOffset=40;this.rightOffset=1;this.link=link;this.loadingText=(loadingText?loadingText:'Loading...');this.displayText=(displayText?displayText:null);this.imagePath=null;this.description=null;this.image=null;this.loaded=false;this.working=false;this.subLinks=null;this.pos=null;this.updateLink();}
ImagePopupManager.prototype={updateLink:function(){var func=function(e,source,type){var main=source.getData('main');if(main.isWorking())return false;source.getData('main').loadImage();return false;};this.link.setTarget('_self').setData('main',this).addEvent('onclick',func);},setSubLinks:function(subLinks){this.subLinks=subLinks;},isWorking:function(){return this.working;},applyFullPanel:function(){var docSize=Xu().getSize();var func=function(e,source,type){source.getData('main').removeDisplay();return false;}
var a=Xu('a',true).setData('main',this).setHref(null).setID('FullPanel').append(Xu('text',true,'')).setStyles({position:'absolute',top:'0px',left:'0px',width:docSize.width+'px',height:docSize.height+'px'}).addEvent('onclick',func).appendTo(Xu().getBody());},loadImage:function(forceImagePath,forceDescription){if(this.working)return;this.image=null;this.imagePath=(forceImagePath?forceImagePath:this.link.getHref());this.description=(forceDescription?forceDescription:this.link.getTitle());this.working=true;this.removeDisplay();this.displayLoading();var selfObj=this;var func=function(){selfObj.imageLoaded();}
this.image=new Image();this.image.onload=func;this.image.src=this.imagePath;},imageLoaded:function(){this.loaded=true;this.displayImage();},displayLoading:function(){this.removeDisplay();this.applyFullPanel();Xu('div',true).setID('ImagePopupManagerDiv').append(Xu('p',true).append(Xu('text',true,this.loadingText)).get()).appendTo(Xu().getBody());this.centerDisplay();},displayImage:function(){this.removeDisplay();this.applyFullPanel();var image=Xu('img',true).setVar('src',this.imagePath);var func=function(e,source,type){source.getData('main').removeDisplay();}
var closeLink=Xu('a',true).setClass('close-link').setHref(null).setData('main',this).addEvent('onclick',func).append(Xu('text',true,''));var display=Xu('div',true).setID('ImagePopupManagerDiv').append(closeLink).append(image).appendTo(Xu().getBody());if(this.subLinks!==null){display.setClass('with-arrows');var leftFunc=function(e,source,type){source.getData('main').moveLeft();}
var rightFunc=function(e,source,type){source.getData('main').moveRight();}
display.append(Xu('a',true).setData('main',this).append(Xu('text',true,'')).setClass('sinistra').setHref(null).addEvent('onclick',leftFunc)).append(Xu('a',true).setData('main',this).append(Xu('text',true,'')).setClass('destra').setHref(null).addEvent('onclick',rightFunc));this.pos=null;for(var i=0;i<this.subLinks.length;++i){if(this.subLinks[i].getHref()===image.getSrc()){this.pos=i;break;}}}
if(this.description){display.append(Xu('p',true).append(Xu('text',true,this.description)));}
this.link.setHref(this.imagePath);this.working=false;this.centerDisplay();},moveLeft:function(){var pos=(this.pos===0?this.subLinks.length-1:this.pos-1);this.loadImage(this.subLinks[pos].getHref(),this.subLinks[pos].getTitle());},moveRight:function(){var pos=(this.pos===this.subLinks.length-1?0:this.pos+1);this.loadImage(this.subLinks[pos].getHref(),this.subLinks[pos].getTitle());},centerDisplay:function(){if(Xu('ImagePopupManagerDiv')===null)return;var display=Xu('ImagePopupManagerDiv');var SM=new ScreenManager();var size=SM.getSize();var scroll=SM.getScroll();var divWidth=parseInt(display.getStyle('width'));var divHeight=parseInt(display.getStyle('height'));if(!divWidth)divWidth=(this.image?this.image.width+this.leftOffset+this.rightOffset:0);if(!divHeight)divHeight=(this.image?this.image.height+this.upOffset+this.downOffset:0);if(divWidth)display.setStyle('width',divWidth+'px');var posX=scroll.scrollX+Math.round(size.width/2-(divWidth/2));if(posX<0)posX=0;var posY=scroll.scrollY+Math.round(size.height/2-(divHeight/2));if(posY<0)posY=0;display.setStyles({'zIndex':200,'left':posX+'px','top':posY+'px'});},removeDisplay:function(){if(Xu('ImagePopupManagerDiv')!==null){Xu('ImagePopupManagerDiv').removeSelf();Xu('FullPanel').removeSelf();}}}
function applyZoomOverLink(link){link=Xu(link);if(link===null)return;Xu('span',true).setClass('zoomOver').insertBeforeItem(link.childItem(0));}
function applyZoomOverToOffers(){var offerDiv=Xu('offerte');if(offerDiv===null)return;var offers=new Xf(offerDiv.getByTag('li')).getXu();for(var i=0;i<offers.length;++i)applyZoomOverLink(offers[i].getByTag('a',0));}
function applyPopupToImages(){var tmp=Xu('immagine-principale');if(tmp!==null){applyZoomOverLink(tmp);new ImagePopupManager(tmp);}
var picDiv=Xu('altre-immagini');if(picDiv===null)return;var pics=new Xf(picDiv.getByTag('li')).getXu();for(var i=0;i<pics.length;++i){tmp=pics[i].getByTag('a',0);applyZoomOverLink(tmp);new ImagePopupManager(tmp);}}
function applyZoomOverToRelateds(){var relatedDiv=Xu('articoli-correlati');if(relatedDiv===null)return;var relateds=new Xf(relatedDiv.getByTag('li')).getXu();for(var i=0;i<relateds.length;++i)applyZoomOverLink(relateds[i].getByTag('a',0));}
function applyLinksToProducts(){var main=Xu('lista-prodotti');if(main===null)return;var items=new Xf(main.getByTag('li')).getXu();for(var i=0;i<items.length;++i){applyZoomOverLink(Xu(items[i].getByTag('a',0)).append(Xu('span',true).setClass('pseudolink').append(Xu('text',true,'» ulteriori dettagli'))));}}
function applyBlankTargetLinks(){var links=Xu().getByTag('a');if(!links)return;links=new Xf(links).filterByVar('rel','external').getXu();for(var i=0;i<links.length;++i)links[i].setTarget('_blank');}
function applyFormErrorHighlighter(parent){parent=Xu(parent);if(parent===null)return;var tmp=new Xf(parent.getByTag('label')).getXu();var labels={};for(var i=0;i<tmp.length;++i)labels[tmp[i].getVar('htmlFor')]=tmp[i];var messageDivs={errore:Xu('Errori'),avvertimento:Xu('Avvertimenti'),messaggio:Xu('Messaggi')}
var div=null;var items=null;for(var type in messageDivs){div=messageDivs[type];if(div===null)continue;items=new Xf(div.getByTag('a')).getXu();if(items===null)continue;for(var i=0;i<items.length;++i){if(items[i].checkClass('inlink'))continue;labels[items[i].getHref().split('#')[1]].addClass(type);}}}
function EnlargedMapDisplayer(item){this.item=Xu(item);if(this.item===null)return;this.longitude=null;this.latitude=null;this.zoom=null;this.api_key=null;this.prepare();}
EnlargedMapDisplayer.prototype={prepare:function(){var link=Xu(this.item.getByTag('a',0));var img=Xu(link.getByTag('img',0))
var imgSrc=img.getSrc();var tmp=imgSrc.match(/markers=([-.0-9]+),([-.0-9]+)/);this.longitude=tmp[2]-0;this.latitude=tmp[1]-0;this.zoom=imgSrc.match(/zoom=([0-9]+)/)[1]-0;this.title=img.getVar('alt');var func=function(e,source,type){source.getData('EMD').mapClicked();return false;}
link.setData('EMD',this).addEvent('onclick',func);applyZoomOverLink(link);},mapClicked:function(){this.applyFullPanel();var func=function(e,source,type){source.getData('EMD').removeDisplay();}
Xu('div',true).setID('contenitore-contenitore-mappa').append(Xu('a',true).setData('EMD',this).setClass('close-link').setHref(null).append(Xu('text',true,'')).addEvent('onclick',func)).append(Xu('div',true).setID('contenitore-mappa')).appendTo(Xu().getBody());this.centerDisplay();this.prepareMap()},applyFullPanel:function(){var docSize=Xu().getSize();var func=function(e,source,type){source.getData('main').removeDisplay();return false;}
var a=Xu('a',true).setData('main',this).setHref(null).setID('FullPanel').append(Xu('text',true,'')).setStyles({position:'absolute',top:'0px',left:'0px',width:docSize.width+'px',height:docSize.height+'px'}).addEvent('onclick',func).appendTo(Xu().getBody());},centerDisplay:function(){var display=Xu('contenitore-contenitore-mappa');if(display===null)return;var SM=new ScreenManager();var size=SM.getSize();var scroll=SM.getScroll();var divWidth=parseInt(display.getStyle('width'));var divHeight=parseInt(display.getStyle('height'));if(!divWidth)divWidth=640;if(!divHeight)divHeight=504;if(divWidth)display.setStyle('width',divWidth+'px');var posX=scroll.scrollX+Math.round(size.width/2-divWidth/2);if(posX<0)posX=0;var posY=scroll.scrollY+Math.round(size.height/2-divHeight/2);if(posY<0)posY=0;display.setStyles({'zIndex':200,'left':posX+'px','top':posY+'px'});},prepareMap:function(){CurrentMapActive=this;google.load('maps','2',{language:this.language,callback:displayEnlargedMap});},displayMap:function(){var map=new GMap2(document.getElementById('contenitore-mappa'));var coords=new GLatLng(this.latitude,this.longitude);map.setCenter(coords,this.zoom);map.addOverlay(new GMarker(coords,{title:this.title,clickable:false}));map.addControl(new GSmallMapControl());map.addControl(new GMapTypeControl());},removeDisplay:function(){if(Xu('contenitore-contenitore-mappa')!==null){Xu('contenitore-contenitore-mappa').removeSelf();Xu('FullPanel').removeSelf();GUnload();}}}
function displayEnlargedMap(){CurrentMapActive.displayMap();}
function shoppingCartHighlight(){var shoppingCart=Xu('carrello');if(shoppingCart===null||!shoppingCart.checkClass('evidenza'))return;var cycles=5;var colors=['red','yellow'];var colorLength=colors.length;var path=[];for(var i=0;i<cycles;++i){for(var l=0;l<colorLength;++l)path.push(colors[l]);}
var definitions=[{item:shoppingCart,path:path,value:'backgroundColor',interval:200}];new Xa(definitions).start();}
function pageEnancher(page,param1){var path='';switch(page){case'home':applyLinksToProducts();break;case'articoli':path='../';applyZoomOverToRelateds();applyPopupToImages();case'categorie':applyLinksToProducts();break;case'marchi':applyLinksToProducts();break;case'ricerca':applyFormErrorHighlighter('ricerca');applyLinksToProducts();break;case'chiedi-preventivo':applyFormErrorHighlighter('modulo');break;case'contatti':CurrentMapActive=null;new EnlargedMapDisplayer('mappa');break;}
applyZoomOverToOffers();applyBlankTargetLinks();shoppingCartHighlight();}