RE_TIMESTAMP = "(<div class='pubDate'>)(.*?)(</div>)";
				
function adjustData(html) {
    var html = html.gsub(RE_TIMESTAMP, function(match) {
        match[2] = new Date(match[2]).toLocaleString();
        return match[1] + match[2] + match[3];
    });
   
    return html;
} // adjustData
function showIndicator() {
    with ($('indicator')) {
        update('');
        show();
    }
} // showIndicator

function hideIndicator() {
    $('indicator').hide();
} // hideIndicator

function safeUnescape(text) {
    TRANSITIONS = { 'lt': '<', 'gt': '>','quot': '"',
        'apos': "'", 'amp': '&' };
    for (var entity in TRANSITIONS) {
        var re = new RegExp('&' + entity + ';', 'mg');
        text = text.replace(re, TRANSITIONS[entity]);
    }
    return text;
} // safeUnescape

function getFeed(idModulo,start,idtag) {
		$.ajax({type: "GET",
			url: "/contenuti/inclusioni/legge-rss-modulo.asp?id_modulo="+idModulo+"&s="+start,
			success: function(text){$("#rss"+idtag).html(safeUnescape(text));}
			});				
		
	
} //getFeed

/*function getAnteprimaCategoria(idModulo,start,rnd) {
		//showIndicator();
		new Ajax.Request('/contenuti/inclusioni/moduli/legge-anteprima-categoria.asp', {
		method: 'get',
		parameters: 'id_modulo='+idModulo+'&p='+rnd+'&s='+start,
		onLoading: showIndicator,
		onComplete: passaAzione(),
		onFailure: function(t){alert('lettura fallita');alert(t.responseText)},
		onSuccess: function(requester) {
		$('anteprima'+rnd).innerHTML=safeUnescape(adjustData(requester.responseText));
		}
		});
} //getAnteprimaCategoria
*/
$.fn.panelSlider = function(settings) {
	settings = $.extend({
		btnPrev: null,
		btnNext: null,
		btnPlayPause: null,

		//menuTabs: null,
		tabsItems: [],
		//tabs: null,
		tabsColor: null,
		tabsBorderColor: null,
		tabsDim: 30,
		auto: null,
		time: 5000,
		speed: null,
		easing: null,
		vertical: true,         	// per il momento lo slide verticale non è implementato
		circular: true,				// per il momento non è implementato
		visible: 3,
		start: 0,
		scroll: 1,
		beforeStart: null,       	// per il momento non è implementato
		afterEnd: null           	// per il momento non è implementato
	}, settings || {});

	return this.each(function(){
		var container = $(this);
		var maxHeight=0;
		//se si ridimensiona  la finestra occorre ridimensionare le larghezze
		$(".panel", container).each(function(s){ var altTemp= $($(this)).height() ;if(altTemp>maxHeight) {maxHeight=0;maxHeight=altTemp}}	);
		//var largh=container.width();
		var largh=$("#colonnaCentrale").width();
		container.css({"height":maxHeight+5});//-23});
		container.css("width", largh);
		$(".panel", container).css("width", largh);
		var panelWidth = container.find(".panel").width();
		var panelCount = container.find(".panel").size();
		var totalWidth = panelWidth*panelCount;
		var cPanel = 1;
		var playInterval = null;
		var playStatus = true;

		container.css({"overflow": "hidden", "position": "relative","clear":"both"})
		$(".panel", container).css("float", "left");
		$("div.panelslider_container", container).css({"width": totalWidth, "position": "absolute"});


		function createMenuTabs() {
			//tabs html
			var tab_items = settings.tabItems;
			var htmltabs = '<ul class="panelslider_tabcontainer">';
			for (i=0; i<panelCount; i++) {
				htmltabs += '<li class="tab"><a href="javascript:void(0)"><span>' + tab_items[i] + '</span></a></li>'
			}
			htmltabs +='<br class="clear"></ul><div id="navigator"><a class="goleft" href="javascript:void(0)"></a><a class="playpause" href="javascript:void(0)"></a><a class="goright" href="javascript:void(0)"></a></div>'
			$(settings.tabs).html(htmltabs);
	
			//tabs css
			//$("li.tab", settings.tabs).css({"list-style-type": "none", "float": "left", "font-size": settings.tabsDim, "height": settings.tabsDim, "width": settings.tabsDim, "margin-right": (settings.tabsDim/2)+3, "color": "#FFF", "border": "1px solid", "border-color": settings.tabsBorderColor});
			$("li.tab", settings.tabs).css({"list-style-type": "none", "float": "left"});
			//$("li.tab a", settings.tabs).css({"display": "block", "width": settings.tabsDim, "height": settings.tabsDim});
			//$("li.tab a span", settings.tabs).css({"display": "none"});
			var firstTab = $("li.tab", settings.tabs).get(0);
			$(firstTab).addClass("selected");
	
			//tabs events
			$("li.tab a", settings.tabs).each(function(z) {
				$(this).click(function(){
					goToPanel(z)
				});
			});
		}

		function createTabs() {
			//tabs html
			var htmltabs = '<ul class="panelslider_tabcontainer">';
			for (i=0; i<panelCount; i++) {
				htmltabs += '<li class="tab"><a href="javascript:void(0)">&nbsp;<span>' + (i+1) + '</span></a></li>'
			}
			htmltabs +='<br class="clear"></ul>'
			$(settings.tabs).html(htmltabs);

			//tabs css
			$("li.tab", settings.tabs).css({"list-style-type": "none", "float": "left", "font-size": settings.tabsDim, "height": settings.tabsDim, "width": settings.tabsDim, "width": (panelWidth/panelCount), "color": "#FFF" ,"display":"block"
			});
			$("li.tab a", settings.tabs).css({"display": "block", "width": settings.tabsDim, "height": settings.tabsDim});
			//$("li.tab a span", settings.tabs).css({"display": "none"});
			var firstTab = $("li.tab", settings.tabs).get(0);
			$(firstTab).addClass("selected");

			//tabs events
			$("li.tab a", settings.tabs).each(function(z) {
				$(this).click(function(){
					goToPanel(z)
				});
			});
		}

		function setCurrentTab() {
			$("li.tab", settings.tabs).removeClass("selected");
			var currentTab = $("li.tab", settings.tabs).get(cPanel-1);
			$(currentTab).addClass("selected");
		}

		function manageAutoSlide() {
			if (playStatus) {
				clearInterval(playInterval)
				playInterval = setInterval(function() { 
					goNext() 
				}, settings.time);
			}
		}

		function goPrev() {
			if (cPanel == 1) {
				var cnt = - (panelWidth*(panelCount - 1));
				cPanel = panelCount;
			} else {

				cPanel -= 1;
				var cnt = - (panelWidth*(cPanel - 1));
			};
			$("div.panelslider_container", container).animate({ left: cnt}, settings.speed, settings.easing);
			setCurrentTab();
			manageAutoSlide();
			return false;
		};

		function goNext() {
			if (cPanel == panelCount) {
				var cnt = 0;
				cPanel = 1;
			} else {
				var cnt = - (panelWidth*cPanel);
				cPanel += 1;
			};
			$("div.panelslider_container", container).animate({ left: cnt}, settings.speed, settings.easing);
			setCurrentTab();
			manageAutoSlide();
			return false;
		};

		function goToPanel(z) {
			var cnt = - (panelWidth*z);
			cPanel = z + 1;
			$("div.panelslider_container", container).animate({ left: cnt}, settings.speed, settings.easing);
			setCurrentTab();
			manageAutoSlide();
			return false;
		};
		
		if (settings.menuTabs) {
			createMenuTabs();
		} else {
			createTabs()
		}
		
		$(settings.btnPrev).click(function(){
			goPrev()
		});

		$(settings.btnPlayPause).click(function(){
			if (playStatus) {
				clearInterval(playInterval)
				playStatus = false;
			} else {
				playInterval = setInterval(function() { 
					goNext() 
				}, settings.time);
				playStatus = true;
			}
		});

		$(settings.btnNext).click(function(){
			goNext()
		});

		if(settings.auto) {
			playInterval = setInterval(function() { 
				goNext() 
			}, settings.time);
		}

	});
}

//panelSlider


 
  
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}


/*
 * JTicker 0.5 Beta
 * By Jason Levine (http://www.jasons-toolbox.com)
 * A ticker plugin for the jquery library.
 */
$.JTickerObjArray = new Array();
$.fn.jticker = function(passedOptions) {
	var options = {
	    TickerID: "",
		delay: 1000,
		newwindow: false,
		url: "",
		transition: "slide",
		speed: "slow",
		/* saibal addon */
		wordsnumb: 40,
		titletag: "h4",
		desctag: "p",
		/* saibal addon */
		contentcounter: -1,
		ArrayIndex: -1,
		dataXML: {
		},
		timerid: -1,
		setRSS: function(ArrayIndex) {
			$("#" + options.TickerID).hide();
			// Load Data
			$.get(options.url, function(data){
				options.dataXML = data;
				options.contentcounter = -1;
				options.FillSlide();
			});
		},
		FillSlide: function() {
			var Item, TickerHTML, Title, URL, Desc;
			$("#" + options.TickerID).empty();
			options.contentcounter++;
			if (options.contentcounter == $("item", options.dataXML).length) {
				options.contentcounter = 0;
			}
			Item = $("item", options.dataXML).get(options.contentcounter);
			Title = $("title", Item).text();
			URL = $("link", Item).text();
			Desc = $("description", Item).text();
			/* saibal addon */
      Site = $("category", Item).text();
			Site = Site.substr(0,1).toUpperCase() + Site.substr(1);
			
			/* saibal addon */
			Desc 				= jQuery.trim(Desc);
			lenghtSplit = Desc.split(" ");
			lenghtDesc 	= lenghtSplit.length;
			var nwords 	= lenghtSplit.length-(options.wordsnumb-1);

			if (lenghtDesc > options.wordsnumb) {
					finalDesc 	= "";
				for(z = 0; z < options.wordsnumb; z++) {
					finalDesc += lenghtSplit[z] + ' ';
				}
				  
				last_word = lenghtSplit[lenghtSplit.length-nwords];
				last_lett = last_word.substring(last_word.length-1,last_word.length);
				if (last_lett.indexOf(".") == -1) {
				  finalDesc += '...';
				}
				
			} else {
			  	finalDesc = Desc;
			}

			TickerHTML = "<div class=\"JTickerTitle\"><" + options.titletag + " class=\"ticker_title\">";
			TickerHTML += "<a href=\"" + URL + "\"";
			
		if (options.newwindow) {
			TickerHTML += " onclick=\"window.open(this.href);return false\""
		}
			TickerHTML += ">" + Title + "</a></" + options.titletag + ">";
			TickerHTML += "<" + options.desctag + " class=\"ticker_desc\">" + finalDesc;
			TickerHTML += "</" + options.desctag + ">";
			TickerHTML += "</div>";
			/* saibal addon */
			
			$("#" + options.TickerID).append(TickerHTML);
			options.EnterSlide();
		},
	    ExitSlide: function() {
			if (options.contentcounter > -1) {
				clearTimeout(options.timerid);
				switch (options.transition.toLowerCase()) {
					case "slide":
						$("#" + options.TickerID).slideUp(
							options.speed,
							options.ExitSlideStep2()
						);
						break;
					default:
						$("#" + options.TickerID).fadeOut(
							options.speed,
							options.ExitSlideStep2()
						);
						break;
				}
			} else {
				options.ExitSlideStep2(ArrayIndex);
			}
	    },
	    ExitSlideStep2: function() {
			var tempid;
			
			tempid = setTimeout("$.JTickerObjArray[" + options.ArrayIndex + "].FillSlide();", 500);
		},
	    EnterSlide: function() {
			var ArrayIndex = options.ArrayIndex;
			switch (options.transition.toLowerCase()) {
				case "slide":
					$("#" + options.TickerID).slideDown(
						options.speed,
						options.EnterSlideStep2()
					);
					break;
				default:
					$("#" + options.TickerID).fadeIn(
						options.speed,
						options.EnterSlideStep2()
					);
					break;
			}
	    },
	    EnterSlideStep2: function() {
			options.timerid = setTimeout("$.JTickerObjArray[" + options.ArrayIndex + "].ExitSlide();", options.delay);
		}
	};
	if (passedOptions) {
		$.extend(options, passedOptions);
	}
	
	return this.each(function(){
		options.TickerID = this.id;
		$.JTickerObjArray.push(options);
		options.ArrayIndex = $.JTickerObjArray.length - 1;
		$("#" + options.TickerID).hover(function() {
			clearTimeout(options.timerid);
		}, function() {
			options.timerid = setTimeout("$.JTickerObjArray[" + options.ArrayIndex + "].ExitSlide();", options.delay);
		});
		$.JTickerObjArray[options.ArrayIndex].setRSS(options.ArrayIndex);
	});
};

var slideMenu=function(){
	var sp,st,t,m,sa,l,w,sw,ot;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s; st=sw; t=mt;
			m=document.getElementById(sm);
			sa=m.getElementsByTagName('li');
			l=sa.length; w=m.offsetWidth; sw=w/l;
			ot=Math.floor((w-st)/(l-1)); var i=0;
			for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)}
			if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)}
		},
		timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}},
		slide:function(s){
			var cw=parseInt(s.style.width,'10');
			if(cw<st){
				var owt=0; var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10');
						if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'}
						owt=owt+(ow-oi)}}
				s.style.width=(w-owt)+'px';
			}else{clearInterval(m.timer)}
		}
	};
}();


/* *****
 * See http://www.greywyvern.com/code/js/scroller.html for the page
 * which uses the example scrollers below
 *
 */
function scrollObject(main, width, height, direct, pause, speed) {
  var self = this;
  this.main = main;
  this.width = width;
  this.height = height;
  this.direct = direct;
  this.pause = pause;
  this.speed = Math.max(1.001, Math.min((direct == "up" || direct == "down") ? height : width, speed));
  this.slope = (direct == "up" || direct == "left") ? 1 : -1;
  this.prev = this.offset = 0;
  this.curr = 1;
  this.mouse = false;
  this.scroll = function() {
    this.main = document.getElementById(this.main);
    this.main.style.overflow = "hidden";
    this.main.style.position = "relative";
    this.main.style.width = this.width + "px";
    this.main.style.height = this.height + "px";
    var b = [], c;
    while (this.main.firstChild) if ((c = this.main.removeChild(this.main.firstChild)).nodeName == "DIV") b.push(c);
    for (var x = 0; x < b.length; x++) {
      var table = document.createElement('table');
          table.cellPadding = table.cellSpacing = table.border = "0";
          table.style.position = "absolute";
          table.style.left = table.style.top = "0px";
          table.style.width = table.style.height = "100%";
          table.style.overflow = table.style.visibility = "hidden";
        var tbody = document.createElement('tbody');
          var tr = document.createElement('tr');
            var td = document.createElement('td');
              while (b[x].firstChild)
                  td.appendChild(b[x].removeChild(b[x].firstChild));
              tr.appendChild(td);
            tbody.appendChild(tr);
          table.appendChild(tbody);
      this.main.appendChild(table);
    } b = c = null;
    if (this.main.childNodes.length > 1) {
      this.main.onmouseover = function() { self.mouse = true; };
      this.main.onmouseout = function() { self.mouse = false; };
      setInterval(function() {
        if (!self.offset && self.scrollLoop()) self.main.childNodes[self.curr].style.visibility = "visible";
      }, this.pause);
    } this.main.childNodes[this.prev].style.visibility = "visible";
  };
  this.scrollLoop = function() {
    if (!this.offset) {
      if (this.mouse) return false;
      this.offset = (this.direct == "up" || this.direct == "down") ? this.height : this.width;
    } else this.offset = Math.floor(this.offset / this.speed);
    if (this.direct == "up" || this.direct == "down") {
      this.main.childNodes[this.curr].style.top = (this.offset * this.slope) + "px";
      this.main.childNodes[this.prev].style.top = ((this.offset - this.height) * this.slope) + "px";
    } else {
      this.main.childNodes[this.curr].style.left = (this.offset * this.slope) + "px";
      this.main.childNodes[this.prev].style.left = ((this.offset - this.width) * this.slope) + "px";
    }
    if (!this.offset) {
      this.main.childNodes[this.prev].style.visibility = "hidden";
      this.prev = this.curr;
      if (++this.curr >= this.main.childNodes.length) this.curr = 0;
    } else setTimeout(function() { self.scrollLoop(); }, 30);
    return true;
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.scroll(); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.scroll(); });
}
/* questo disabilita o abilita il sottomenu del menu orizzontale*/
jQuery(function() {
   if ( jQuery("#navOrizontale").length>0){
    var sfEls = document.getElementById("navOrizontale").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" hoverMenu";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" hoverMenu\\b"), "");
			}
		}
	}
	}); 

 
/*  // Scroll to top animation*/
jQuery(function() { 
		   jQuery('.scroll-top').click(function(){ 
  jQuery('html, body').animate({scrollTop:0}, 'slow'); return false; 
 });
						   });
