// Expand and Compress text (Expander Plugin)
/** jQuery Expander plugin* Version 0.4  (12/09/2008)* @requires jQuery v1.1.1+** Dual licensed under the MIT and GPL licenses:* http://www.opensource.org/licenses/mit-license.php* http://www.gnu.org/licenses/gpl.html**/
(function($){$.fn.expander=function(options){var opts=$.extend({},$.fn.expander.defaults,options);var delayedCollapse;return this.each(function(){var $this=$(this);var o=$.meta?$.extend({},opts,$this.data()):opts;var cleanedTag,startTags,endTags;var allText=$this.html();var startText=allText.slice(0,o.slicePoint).replace(/\w+$/,'');startTags=startText.match(/<\w[^>]*>/g);if(startTags){startText=allText.slice(0,o.slicePoint+startTags.join('').length).replace(/\w+$/,'')}if(startText.lastIndexOf('<')>startText.lastIndexOf('>')){startText=startText.slice(0,startText.lastIndexOf('<'))}var endText=allText.slice(startText.length);if(!$('span.details-expand',this).length){if(endText.replace(/\s+$/,'').split(' ').length<o.widow){return}if(endText.indexOf('</')>-1){endTags=endText.match(/<(\/)?[^>]*>/g);for(var i=0;i<endTags.length;i++){if(endTags[i].indexOf('</')>-1){var startTag,startTagExists=false;for(var j=0;j<i;j++){startTag=endTags[j].slice(0,endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>');if(startTag==rSlash(endTags[i])){startTagExists=true}}if(!startTagExists){startText=startText+endTags[i];var matched=false;for(var s=startTags.length-1;s>=0;s--){if(startTags[s].slice(0,startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>')==rSlash(endTags[i])&&matched==false){cleanedTag=cleanedTag?startTags[s]+cleanedTag:startTags[s];matched=true}}}}}endText=cleanedTag&&cleanedTag+endText||endText}$this.html([startText,'<span class="read-more">',o.expandPrefix,'<a href="#">',o.expandText,'</a>','</span>','<span class="details-expand">',endText,'</span>'].join(''))}var $thisDetails=$('span.details-expand',this),$readMore=$('span.read-more',this);$thisDetails.hide();$readMore.find('a').click(function(){$readMore.hide();if(o.expandEffect==='show'&&!o.expandSpeed){o.beforeExpand($this);$thisDetails.show();o.afterExpand($this);delayCollapse(o,$thisDetails)}else{o.beforeExpand($this);$thisDetails[o.expandEffect](o.expandSpeed,function(){$thisDetails.css({zoom:''});o.afterExpand($this);delayCollapse(o,$thisDetails)})}return false});if(o.userCollapse){$this.find('span.details-expand').append('<span class="re-collapse">'+o.userCollapsePrefix+'<a href="#">'+o.userCollapseText+'</a></span>');$this.find('span.re-collapse a').click(function(){clearTimeout(delayedCollapse);var $detailsCollapsed=$(this).parents('span.details-expand');reCollapse($detailsCollapsed);o.onCollapse($this,true);return false})}});function reCollapse(el){el.hide().prev('span.read-more').show()}function delayCollapse(option,$collapseEl){if(option.collapseTimer){delayedCollapse=setTimeout(function(){reCollapse($collapseEl);option.onCollapse($collapseEl.parent(),false)},option.collapseTimer)}}function rSlash(rString){return rString.replace(/\//,'')}};$.fn.expander.defaults={slicePoint:100,widow:4,expandText:'read more',expandPrefix:'&hellip; ',collapseTimer:0,expandEffect:'fadeIn',expandSpeed:'',userCollapse:true,userCollapseText:'[collapse expanded text]',userCollapsePrefix:' ',beforeExpand:function($thisEl){},afterExpand:function($thisEl){},onCollapse:function($thisEl,byUser){}}})(jQuery);
// Map Highlight
(function(f){var b,c,j,m,l,i,g,e,h,a,k;b=document.namespaces;has_canvas=!!document.createElement("canvas").getContext;if(!(has_canvas||b)){f.fn.maphilight=function(){return this};return}if(has_canvas){g=function(p,o,n){if(o<=1){p.style.opacity=o;window.setTimeout(g,10,p,o+0.1,10)}};e=function(n){return Math.max(0,Math.min(parseInt(n,16),255))};h=function(n,o){return"rgba("+e(n.substr(0,2))+","+e(n.substr(2,2))+","+e(n.substr(4,2))+","+o+")"};c=function(n){var o=f('<canvas style="width:'+n.width+"px;height:"+n.height+'px;"></canvas>').get(0);o.getContext("2d").clearRect(0,0,o.width,o.height);return o};j=function(q,n,t,p,o){var s,r=q.getContext("2d");r.beginPath();if(n=="rect"){r.rect(t[0],t[1],t[2]-t[0],t[3]-t[1])}else{if(n=="poly"){r.moveTo(t[0],t[1]);for(s=2;s<t.length;s+=2){r.lineTo(t[s],t[s+1])}}else{if(n=="circ"){r.arc(t[0],t[1],t[2],0,Math.PI*2,false)}}}r.closePath();if(p.fill){r.fillStyle=h(p.fillColor,p.fillOpacity);r.fill()}if(p.stroke){r.strokeStyle=h(p.strokeColor,p.strokeOpacity);r.lineWidth=p.strokeWidth;r.stroke()}if(p.fade){g(q,0)}};m=function(n){n.getContext("2d").clearRect(0,0,n.width,n.height)}}else{c=function(n){return f('<var style="zoom:1;overflow:hidden;display:block;width:'+n.width+"px;height:"+n.height+'px;"></var>').get(0)};j=function(o,r,s,v,n){var t,u,p,q;t='<v:fill color="#'+v.fillColor+'" opacity="'+(v.fill?v.fillOpacity:0)+'" />';u=(v.stroke?'strokeweight="'+v.strokeWidth+'" stroked="t" strokecolor="#'+v.strokeColor+'"':'stroked="f"');p='<v:stroke opacity="'+v.strokeOpacity+'"/>';if(r=="rect"){q=f('<v:rect name="'+n+'" filled="t" '+u+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+s[0]+"px;top:"+s[1]+"px;width:"+(s[2]-s[0])+"px;height:"+(s[3]-s[1])+'px;"></v:rect>')}else{if(r=="poly"){q=f('<v:shape name="'+n+'" filled="t" '+u+' coordorigin="0,0" coordsize="'+o.width+","+o.height+'" path="m '+s[0]+","+s[1]+" l "+s.join(",")+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+o.width+"px;height:"+o.height+'px;"></v:shape>')}else{if(r=="circ"){q=f('<v:oval name="'+n+'" filled="t" '+u+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(s[0]-s[2])+"px;top:"+(s[1]-s[2])+"px;width:"+(s[2]*2)+"px;height:"+(s[2]*2)+'px;"></v:oval>')}}}q.get(0).innerHTML=t+p;f(o).append(q)};m=function(n){f(n).find("[name=highlighted]").remove()}}l=function(o){var n,p=o.getAttribute("coords").split(",");for(n=0;n<p.length;n++){p[n]=parseFloat(p[n])}return[o.getAttribute("shape").toLowerCase().substr(0,4),p]};k=function(p,o){var n=f(p);return f.extend({},o,f.metadata?n.metadata():false,n.data("maphilight"))};a=function(n){if(!n.complete){return false}if(typeof n.naturalWidth!="undefined"&&n.naturalWidth==0){return false}return true};i={position:"absolute",left:0,top:0,padding:0,border:0};var d=false;f.fn.maphilight=function(p){p=f.extend({},f.fn.maphilight.defaults,p);if(f.browser.msie&&!d){document.namespaces.add("v","urn:schemas-microsoft-com:vml");var o=document.createStyleSheet();var n=["shape","rect","oval","circ","fill","stroke","imagedata","group","textbox"];f.each(n,function(){o.addRule("v\\:"+this,"behavior: url(#default#VML); antialias:true")});d=true}return this.each(function(){var v,s,z,r,u,w,y,t,x;v=f(this);if(!a(this)){return window.setTimeout(function(){v.maphilight(p)},200)}z=f.extend({},p,f.metadata?v.metadata():false,v.data("maphilight"));x=v.get(0).getAttribute("usemap");r=f('map[name="'+x.substr(1)+'"]');if(!(v.is("img")&&x&&r.size()>0)){return}if(v.hasClass("maphilighted")){var q=v.parent();v.insertBefore(q);q.remove();f(r).unbind(".maphilight").find("area[coords]").unbind(".maphilight")}s=f("<div></div>").css({display:"block",background:"url("+this.src+")",position:"relative",float:"left",padding:0,width:this.width,height:this.height});if(z.wrapClass){if(z.wrapClass===true){s.addClass(f(this).attr("class"))}else{s.addClass(z.wrapClass)}}v.before(s).css("opacity",0).css(i).remove();if(f.browser.msie){v.css("filter","Alpha(opacity=0)")}s.append(v);u=c(this);f(u).css(i);u.height=this.height;u.width=this.width;y=function(C){var A,B;B=k(this,z);if(!B.neverOn&&!B.alwaysOn){A=l(this);j(u,A[0],A[1],B,"highlighted");if(B.groupBy&&f(this).attr(B.groupBy)){var D=this;r.find("area["+B.groupBy+"="+f(this).attr(B.groupBy)+"]").each(function(){if(this!=D){var F=k(this,z);if(!F.neverOn&&!F.alwaysOn){var E=l(this);j(u,E[0],E[1],F,"highlighted")}}})}}};f(r).bind("alwaysOn.maphilight",function(){if(w){m(w)}if(!has_canvas){f(u).empty()}f(r).find("area[coords]").each(function(){var A,B;B=k(this,z);if(B.alwaysOn){if(!w&&has_canvas){w=c(v.get());f(w).css(i);w.width=v.width();w.height=v.height();v.before(w)}A=l(this);if(has_canvas){j(w,A[0],A[1],B,"")}else{j(u,A[0],A[1],B,"")}}})});if(z.alwaysOn){f(r).find("area[coords]").each(y)}else{f(r).find("area[coords]").trigger("alwaysOn.maphilight").bind("mouseover.maphilight",y).bind("mouseout.maphilight",function(A){m(u)})}v.before(u);v.addClass("maphilighted")})};f.fn.maphilight.defaults={fill:true,fillColor:"000000",fillOpacity:0.2,stroke:true,strokeColor:"ff0000",strokeOpacity:1,strokeWidth:1,fade:true,alwaysOn:false,neverOn:false,groupBy:false,wrapClass:true}})(jQuery);
// Left menu (CheckTree Plugin)
/** Project: CheckTree jQuery Plugin / Version: 0.2 / Project Website: http://static.geewax.org/checktree / Author: JJ Geewax <jj@geewax.org> / License: The CheckTree jQuery plugin is currently available for use in all personal or commercial projects under both MIT and GPL licenses. This means that you can choose the license that best suits your project, and use it accordingly.*/
(function(jQuery){jQuery.fn.checkTree=function(settings){settings=jQuery.extend({onExpand:null,onCollapse:null,onCheck:null,onUnCheck:null,onHalfCheck:null,onLabelHoverOver:null,onLabelHoverOut:null,labelAction:"expand",debug:false},settings);var $tree=this;$tree.find("li").find("ul").hide().end().find(":checkbox").change(function(){var $all=jQuery(this).siblings("ul").find(":checkbox");var $checked=$all.filter(":checked");if($all.length==$checked.length){jQuery(this).attr("checked","checked").siblings(".checkbox").removeClass("half_checked").addClass("checked");if(settings.onCheck)settings.onCheck(jQuery(this).parent())}else if($checked.length==0){jQuery(this).attr("checked","").siblings(".checkbox").removeClass("checked").removeClass("half_checked");if(settings.onUnCheck)settings.onUnCheck(jQuery(this).parent())}else{if(settings.onHalfCheck&&!jQuery(this).siblings(".checkbox").hasClass("half_checked"))settings.onHalfCheck(jQuery(this).parent());jQuery(this).attr("checked","").siblings(".checkbox").removeClass("checked").addClass("half_checked")}}).attr("checked","").hide().end().find("label").click(function(){var action=settings.labelAction;switch(settings.labelAction){case'expand':jQuery(this).siblings(".arrow").click();break;case'check':jQuery(this).siblings(".checkbox").click();break}}).hover(function(){jQuery(this).addClass("hover");if(settings.onLabelHoverOver)settings.onLabelHoverOver(jQuery(this).parent())},function(){jQuery(this).removeClass("hover");if(settings.onLabelHoverOut)settings.onLabelHoverOut(jQuery(this).parent())}).end().each(function(){var $arrow=jQuery('<div class="arrow"></div>');if(jQuery(this).is(":has(ul)")){$arrow.addClass("collapsed");$arrow.click(function(){jQuery(this).siblings("ul").toggle();if(jQuery(this).hasClass("collapsed")){jQuery(this).addClass("expanded").removeClass("collapsed");if(settings.onExpand)settings.onExpand(jQuery(this).parent())}else{jQuery(this).addClass("collapsed").removeClass("expanded");if(settings.onCollapse)settings.onCollapse(jQuery(this).parent())}})}var $checkbox=jQuery('');$checkbox.click(function(){jQuery(this).removeClass("half_checked").toggleClass("checked").siblings(":checkbox").click();if(jQuery(this).hasClass("checked")){if(settings.onCheck)settings.onCheck(jQuery(this).parent());jQuery(this).siblings("ul").find(".checkbox").not(".checked").removeClass("half_checked").addClass("checked").each(function(){if(settings.onCheck)settings.onCheck(jQuery(this).parent())}).siblings(":checkbox").attr("checked","checked")}else{if(settings.onUnCheck)settings.onUnCheck(jQuery(this).parent());jQuery(this).siblings("ul").find(".checkbox").filter(".checked").removeClass("half_checked").removeClass("checked").each(function(){if(settings.onUnCheck)settings.onUnCheck(jQuery(this).parent())}).siblings(":checkbox").attr("checked","")}jQuery(this).parents("ul").siblings(":checkbox").change()});jQuery(this).prepend($checkbox).prepend($arrow)});return $tree}})(jQuery);(function($){var cache=[];$.preLoadImages=function(){var args_len=arguments.length;for(var i=args_len;i--;){var cacheImage=document.createElement('img');cacheImage.src=arguments[i];cache.push(cacheImage)}}})(jQuery);
// Hover Intent plugin
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}
if(p==this){return false;}
var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}
if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// Preload Images [Caricamento Immagini]
jQuery.preLoadImages("/img/general/triangle-open.png");

// Fix zIndex Problem for internet explorer [Risolve il posizionamento del z-index per Internet Explorer]
$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	$("#bg-top").css("z-index","-10000");
	$(".sidebar-triangle").css("z-index","940");	
});

// Mega Drop Down Menu Delay [Impostazioni del Mega Menu a tendina]
$(document).ready(function(){function megaHoverOver(){$(this).find(".dropdown").stop().fadeTo('fast',1).show();(function($){jQuery.fn.calcSubWidth=function(){rowWidth=0;$(this).find("ul").each(function(){rowWidth+=$(this).width()})}})(jQuery);if($(this).find(".row").length>0){var biggestRow=0;$(this).find(".row").each(function(){$(this).calcSubWidth();if(rowWidth>biggestRow){biggestRow=rowWidth}});$(this).find(".dropdown").css({'width':biggestRow});$(this).find(".row:last").css({'margin':'0'})}else{$(this).calcSubWidth();$(this).find(".dropdown").css({'width':rowWidth})}}function megaHoverOut(){$(this).find(".dropdown").stop().fadeTo('fast',0,function(){$(this).hide()})}var config={sensitivity:2,interval:100,over:megaHoverOver,timeout:500,out:megaHoverOut};$("ul li .dropdown").css({'opacity':'0'});$("ul li").hoverIntent(config)});

// Tree menu + CodaSlider [Impostazioni del Menu verticale sulla sinistra, e dello Slide "Offerte del Mese" sulla destra in Home Page]
$(document).ready(function(){$("ul.navigation").checkTree({});$('#coda-slider').codaSlider({dynamicArrows: false,dynamicTabs: false,autoSlide: true,autoSlideInterval: 5000,autoSlideStopWhenClicked: true});});

// Effetto Overlay Mappa Sardegna [Impostazioni dell'animazione della Mappa della Sardegna]
$(function() {$('.map').maphilight({fade: false,stroke: false,groupBy: 'rel'});});

// Espandi / Collassa Descizione [Impostazioni per collassare e comprimiere il testo nelle pagine di dettaglio]
$(function() {$('.expandable').expander({slicePoint:520, expandText:'espandi descrizione', collapseTimer:0, userCollapseText:'[Comprimi Descrizione]' });});

// Tabs [Imposta i Tabs della pagina di dettaglio]
$(function() {$("ul.tabs").tabs("div.panes > div");});

// Datapicker [Imposta la classe alla quale applicare il Data Picker]
$(function() {$(".datepicker").dateinput({ trigger: true, format: 'dd mmmm yyyy', min: -1 });});

/* [FAQ] */	
$(document).ready(function(){$().ready(function() {$('#faq').makeFAQ({indexTitle: "My Index",displayIndex: false,faqHeader: "h3"});});});	
/* [/End FAQ] */
