﻿// IMPLEMENTAZIONE DI Array_indexOf
var Array_indexOf = function( array, obj ) {
	for( var i = 0; i < array.length; i++ )
		if( array[ i ] == obj ) return i;
	return -1
}
// IMPLEMENTAZIONE DI appendEvent
var appendEvent = function( element, event, callback ) {
	var evt = "on" + event;
	var fnc = element[ evt ];
	if( typeof fnc != undefined ) {
		if( fnc )
			element[ evt ] = function() {
				fnc();
				callback();
			}
		else element[ evt ] = callback;
	}
}
// IMPLEMENTAZIONE DI NodeList2Array
var NodeList2Array = function( nl, append ) {
	var arr = [];
	for( var i = 0; i < nl.length; i++ ) arr.push( nl[ i ] );
	if( ! ( append instanceof Array ) ) append = [ append ];
	for( var i = 0; i < append.length; i++ ) arr.push( append[ i ] );
	return arr;
}
// IMPLEMENTAZIONE DI getFirstChild
var getFirstChild = function( el ) {
	return el.firstElementChild || el.getElementsByTagName("*")[0];
}
// IMPLEMENTAZIONE DI getElementsByClassName
var getElementsByClassName = function( elm, cls, ci, tag, num ) {
	var list = [];
	if( ! cls ) return list;
	if( ! elm ) elm = document;
	var ci = ci ? "i" : "";
	if( ! tag ) var tag = "*";
	if( ! num ) var num = -1;
	var all = elm.getElementsByTagName( tag );
	var reg = new RegExp( "\\b" + cls + "\\b", ci );
	for( var i = 0; i < all.length; i++ ) {
		if( num >= 0 && list.length >= num ) break;
		if( all[i].className && reg.test( all[i].className ) )
			list.push( all[i] ); // inserisce elemento trovato in lista
	}
	return num > 1 ? list : ( list.length ? list[0] : false );
}
// IMPLEMENTAZIONE DI ajaxObject
function ajaxObject() {
	var XHR = null, browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();
	else if (window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
		if(browserUtente.indexOf("MSIE 5") < 0) XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XHR;
}
// IMPLEMENTAZIONE DI call_user_func_array
function call_user_func_array( cb, parameters ) {
	// http://kevin.vanzonneveld.net
	var func;
	if (typeof cb === 'string')
		func = (typeof this[cb] === 'function') ? this[cb] : func = (new Function(null, 'return ' + cb))();
	else if (Object.prototype.toString.call(cb) === '[object Array]')
		func = (typeof cb[0] == 'string') ? eval(cb[0] + "['" + cb[1] + "']") : func = cb[0][cb[1]];
	else if (typeof cb === 'function')
		func = cb;
	if (typeof func !== 'function')
		throw new Error(func + ' is not a valid function');
	if( typeof cb[0] === 'string' ) what = eval( cb[0] );
	else if( typeof cb[0] !== 'object' ) what = null;
	else what = cb[0];
	return func.apply( what, parameters );
}
// IMPLEMENTAZIONE DI http_build_query
function http_build_query( array ) {
	if( ! array || ! ( array instanceof Object ) ) return "";
	var ret = [];
	for( var k in array ) {
		var v = escape( array[ k ] );
		ret.push( escape( k ) + "=" + v );
	}
	var str = ret.join( "&" );
	return str;
}
// IMPLEMENTAZIONE DI utf8_decode
var utf8_decode = function( srctext ) {
	var ret = unescape( srctext );
	ret = ret.replace(/\n\r|\r\n|\r/g,"\n");
	ret = ret.replace(/\+/g,' ');
	return ret;
}
// IMPLEMENTAZIONE DI $_COOKIE
function global_cookievar() {
	_COOKIE = {};
	var cookie = document.cookie;
	if( ! cookie.length ) return false;
	cookie = cookie.split( /\s*;\s*/ );
	for( var i = 0; i < cookie.length; i++ ) {
		var c = utf8_decode( cookie[ i ] ).split( "=" );
		if( c.length > 2 )
			for( var x = 2; x < c.length; x++ )
				c[1] += "=" + c[ x ];
		_COOKIE[ c[0] ] = c[1];
	}
	return true;
}
global_cookievar();
// VECCHIO POPUP
function popup(url) {
	return QN.popup( url );
}
// IE DETECTION
function isIE() {
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
var QN = {
	init : function( what, vars ) {
		var fn = this[ "init_" + what ];
		var ar = [];
		if( vars && typeof vars != "array" ) ar.push( vars );
		else if( vars ) ar = vars;
		if( typeof fn == "function" ) call_user_func_array( fn, ar );
	},
	init_homePage : function() {
		QN.set_environment( "context", "hp" );
	},
	init_page : function() {
		QN.set_environment( "context", "page" );
	},
	init_citta : function() {
		QN.set_environment( "context", "ed" );
	},
	set_environment : function( k, v ) {
		QN[ k ] = v;
	},
	cookiePrefix : "QNetCookie",
	set_cookieTestata : function() {
		var setTestata = QN.getNumTestata( false, 0 );
		if( QN.get_cookieQnet( "Testata" ) == setTestata ) return false;
		if( setTestata ) return QN.set_cookieQnet({ "testata" : setTestata });
		return false;
	},
	set_cookieEdition : function() {
		var edition = location.pathname.match( /^\/?(\w+)/ );
		if( ! edition || ! edition[1] ) return false;
		if( QN.get_cookieQnet( "Edition" ) == edition[1] ) return false;
		return QN.set_cookieQnet({ "edition" : edition[1] });
	},
	set_cookieQnet : function( postdata ) {
		if( ! postdata ) return false;
		for( var k in postdata ) {
			var cname = QN.cookiePrefix + k.substr( 0, 1 ).toUpperCase() + k.substr( 1 );
			_COOKIE[ cname ] = postdata[ k ];
		}
		var post = http_build_query( postdata );
		var body = document.getElementsByTagName( "body" )[0];
		var id = "QNetSetCookie";
		var div = document.getElementById( id );
		if( ! div ) {
			div = document.createElement( "div" );
			div.style.display = "none";
			div.id = id;
			body.insertBefore( div, body.firstChild );
		}
		var testate = [
			"http://qn.quotidiano.net",
			"http://www.ilrestodelcarlino.it",
			"http://www.lanazione.it",
			"http://www.ilgiorno.it"
		];
		var url = "/file_generali/include/liz/thor.png.php?";
		for( var i = 0; i < testate.length; i++ ) {
			var im = document.createElement( "img" );
			im.alt = "";
			im.src = testate[ i ] + url + post;
			div.appendChild( im );
		}
		return true;
	},
	get_cookieTestata : function() {
		var testata = QN.get_testataCookie();
		if( ! testata ) return false;
		var logoPre = "headerLogo";
		var logoId = logoPre + testata.id;
		var headerSrc = document.getElementById( logoPre + "1" );
		var headerNew = document.getElementById( logoId );
		if( headerNew ) return true;
		if( ! headerSrc ) return false;
		headerSrc.id = logoId;
		var a = headerSrc.getElementsByTagName( "a" );
		if( a ) a[0].href = testata.url;
		var span = headerSrc.getElementsByTagName( "span" );
		if( span ) span[0].innerHTML = testata.text;
		return true;
	},
	get_testataCookie : function() {
		var cookie = QN.get_cookieQnet( "Testata" );
		if( ! cookie ) return false;
		var testate = {
			1 : [ "http://qn.quotidiano.net", "Quotidiano.net, Quotidiano Nazionale" ],
			2 : [ "http://www.ilrestodelcarlino.it", "Il Resto del Carlino" ],
			3 : [ "http://www.lanazione.it", "La Nazione" ],
			4 : [ "http://www.ilgiorno.it", "Il Giorno" ]
		};
		var testata = testate[ cookie ];
		if( ! testata ) return false;
		return { id: cookie, url: testata[0], text: testata[1] };
	},
	get_cookieQnet : function( name ) {
		var cname = QN.cookiePrefix + name;
		if( ! _COOKIE || ! _COOKIE[ cname ] ) return false;
		return _COOKIE[ cname ];
	},
	addScript : function( id, src, whereTag ) {
		if( ! QN.jsSet ) QN.jsSet = {};
		if( QN.jsSet[ id ] ) return;
		if( ! whereTag ) whereTag = "body";
		var where = document.getElementsByTagName( whereTag );
		if( ! where.length ) return;
		var script = document.createElement( "script" );
		script.id = "QNJsSet_" + id;
		script.type = "text/javascript";
		script.src = src;
		where[0].appendChild( script );
		QN.jsSet[ id ] = script;
	},
	addThisScrip : function() {
		var id = "addThisHeadScript";
		var src = "http://s7.addthis.com/js/250/addthis_widget.js#pubid=quotidianonet";
		QN.addScript( id, src, "head" );
	},
	getNumTestata : function( map, def ) {
		if( ! QN.numTestata ) {
			var test = def !== undefined ? def : 1;
			var tests = {
				1 : /^(?:\w+\.)?quotidiano.net/i,
				2 : /^(?:\w+\.)?ilrestodelcarlino.it/i,
				3 : /^(?:\w+\.)?lanazione.it/i,
				4 : /^(?:\w+\.)?ilgiorno.it/i
			};
			for( var t in tests )
				if( location.hostname.match( tests[ t ] ) )
					test = t;
			QN.numTestata = test;
		}
		if( map ) return map[ QN.numTestata ];
		return QN.numTestata;
	},
	init_navBar : function() {
		QN.init( 'sottomenu' );
		var altro = document.getElementById( "navBar_altro" );
		var nav = document.getElementById( "navBarMain" ).getElementsByTagName( "li" );
		nav = NodeList2Array( nav, altro );
		//if( QN.context != "hp" ) nav = [ altro ];
		for( var i = 0; i < nav.length; i++ ) {
			var li = nav[ i ];
			if( li != altro ) {
				var ul = document.createElement( "ul" );
				ul.id = li.id + "_sub";
				li.appendChild( ul );
			} else
				var ul = li.getElementsByTagName( "ul" )[0];
			var a = getFirstChild( li );
			if( a && a.tagName != "A" ) {
				var a_wrap = document.createElement( "a" );
				a_wrap.href = "javascript:void(0)";
				li.insertBefore( a_wrap, a );
				a_wrap.appendChild( a );
				var a = a_wrap;
			}
			QN.submenu( ul );
			if( li != altro ) QN.ajaxmenu( ul );
		}
		// SWITCH TESTATA
		switch( QN.context ) {
			case "hp":
				QN.set_cookieTestata();
				break;
			case "ed":
				//QN.set_cookieEdition();
				break;
			case "page":
				QN.get_cookieTestata();
				break;
			default: break;
		}
	},
	submenu : function( ul ) {
		var cont = ul.parentNode;
		cont.submenu = ul;
		ul.isSubMenu = true;
		appendEvent( cont, "mouseover", function(){ QN.mouseAction( this, false ) } );
		appendEvent( cont, "mouseout", function(){ QN.mouseAction( this, true ) } );
		appendEvent( ul, "mouseover", function(){ QN.mouseAction( this, false ) } );
		appendEvent( ul, "mouseout", function(){ QN.mouseAction( this, true ) } );
		var a = getFirstChild( cont );
		if( a.tagName == "A" && a.parentNode == cont ) {
			var aas = cont.getElementsByTagName( "a" );
			for( var i = 0; i < aas.length; i++ ) {
				aas[ i ].submenu = ul;
				appendEvent( aas[ i ], "focus", function(){ QN.mouseAction( this ); } );
				appendEvent( aas[ i ], "blur", function(){ QN.mouseAction( this, true ); } );
			}
		}
	},
	ajaxmenu : function( ul ) {
		var id = ul.id.replace( /^[^_]+_|_[^_]+$/g, '' ),
			xhttp = ajaxObject();
		var uri = "/file_generali/include/liz/" + id + "_menu_top.shtml";
		if( ! xhttp ) return false;
		xhttp.open( "GET", uri, true );
		xhttp.setRequestHeader("content-type", "text/plain; charset=utf-8");
		//xhttp.setRequestHeader("connection", "close");
		xhttp.onreadystatechange = function() {
			if (xhttp.readyState == 4) {
				if( xhttp.status == 200 ) {
					ul.innerHTML = xhttp.responseText;
					if( ul.id == "navBar_local_sub" ) {
						var lis = ul.getElementsByTagName( "li" );
						var nTs = QN.getNumTestata();
						if( nTs == 3 )		// NAZIONE
							ul.appendChild( lis[0] );
						else if( nTs == 4 )	// GIORNO
							ul.insertBefore( lis[2], lis[0] );
					}
				} else {
					ul.parentNode.submenu = null;
					ul.parentNode.getElementsByTagName( "a" )[0].className += " empty";
					ul.parentNode.removeChild( ul );
				}
			}
		}
		xhttp.send();
	},
	init_headline : function() {
		var cont = document.getElementById( "homeHeadline_news" );
		QN.headline_social( cont );
		if( QN.context != "ed" ) QN.plusOneTestata();
		QN.carousel( cont );
	},
	headline_social : function( cont ) {
		var boxes = cont.getElementsByTagName( "div" );
		// Cicla sugli articoli in homepage
		for( var i = 0; i < boxes.length; i++ ) {
			var art = boxes[ i ];
			if( art.className.indexOf("headlineArt") < 0 ) continue;
			//alert( "ROTFL " + i );
			// Comprime i link correlati
			var uls = art.getElementsByTagName( "ul" );
			for( var u = 0; u < uls.length; u++ ) {
				var list = uls[ u ];
				if( list.className.indexOf("link") < 0 ) continue;
				var lis = list.getElementsByTagName( "li" );
				if( ! lis.length ) continue;
				var btn = document.createElement( "a" );
				btn.href = "javascript:void(0);";
				btn.list = list;
				btn.innerHTML = "Foto, video e altri contenuti correlati <small>&#x25BC;</small>";
				appendEvent( btn, "mouseup", function(){
					var l = this.list;
					if( ! l ) return;
					var c = l.style.display == "none";
					this.getElementsByTagName("small")[0].innerHTML = c ? "(nascondi)" : "&#x25BC;";
					l.style.display = c ? "" : "none";
					var cn = this.parentNode.className;
					this.parentNode.className = c ? cn + " active" : cn.replace( " active", "" );
				});
				list.parentNode.insertBefore( btn, list );
				list.style.display = "none";
			}
			// Inserisce gli strumenti di condivisione
			QN.art_social( art );
		}
	},
	init_ultimora : function() {
		var ult = document.getElementById("ultimora");
		if( ! ult ) return;
		var tit = getElementsByClassName( ult, "titleSuperBig" );
		var abs = getElementsByClassName( ult, "abstract_ultimora" );
		if( ! tit || ! abs ) return;
		abs.style.display = "none";
		var a = document.createElement( "a" );
		a.innerHTML = tit.innerHTML.replace( /<[^>]+>/g, '' );
		a.abs = abs;
		tit.innerHTML = "";
		tit.appendChild( a );
		appendEvent( a, "click", function(){
			this.abs.style.display = this.abs.style.display == "none" ? "" : "none";
		} );
	},
	init_midslide : function() {
		if( QN.context == "ed" ) QN.plusOneTestata( true );
		var conts = [];
		var all = document.getElementsByTagName( "div" );
		var cont = document.getElementById( "homePageMidSlide" );
		conts.push( cont );
		for( var i = 0; i < all.length; i++ )
			if( all[ i ].className.match( /\bhomePageMidSlide\b/ )
				&& all[ i ] != cont )
				conts.push( all[ i ] );
		for( var b = 0; b < conts.length; b++ ) QN.carousel( conts[b] );
		QN.init( 'boxtabs' );
	},
	init_sottomenu : function( what ) {
		var menu = document.getElementById( "navBarMain" );
		if( menu ) {
			var item = false;
			var locs = {
				"news" : [ "qn.quotidiano.net", "www.quotidiano.net" ],
				"local" : [ "www.ilrestodelcarlino.it", "www.lanazione.it", "www.ilgiorno.it" ],
				"sport" : [ "qn.quotidiano.net/sport", "qn.quotidiano.net/canali_paginati_liz.php?nc=sport" ],
				"mmc" : [ "multimedia.quotidiano.net" ],
				"blog" : [ "club.quotidiano.net" ]
			};
			var href = location.href;
			for( var k in locs ) {
				var re = locs[ k ].join( "|" ).replace( '?', '\\?' );
				re = new RegExp( "\\b(?:" + re + ")\\b", "i" );
				if( href.match( re ) ) item = k;
			}
			var li = document.getElementById( "navBar_" + item );
			if( li ) li.className += " current";
		}
		var menu = document.getElementById( "sottomenu" );
		if( what && menu ) {
			var lis = menu.getElementsByTagName( "li" );
			var re = new RegExp( "\\b" + what + "\\b", "i" );
			for( var i = 0; i < lis.length; i++ ) {
				if( lis[i].parentNode != menu ) continue;
				var a = lis[i].getElementsByTagName( "a" );
				if( ! a.length ) continue;
				if( a[0].href.match( re ) ) {
					lis[i].className += " current";
					break;
				}
			}
		}
	},
	init_articoli : function() {
		var cont = document.getElementById( "homePage_main" );
		var boxes = cont.getElementsByTagName( "div" );
		// Cicla sugli articoli in homepage
		for( var i = 0; i < boxes.length; i++ ) {
			var art = boxes[ i ];
			if( art.parentNode != cont || art.className.indexOf("article") < 0 ) continue;
			// Comprime i link correlati
			var uls = art.getElementsByTagName( "ul" );
			for( var u = 0; u < uls.length; u++ ) {
				var list = uls[ u ];
				if( list.className.indexOf("link") < 0 ) continue;
				var lis = list.getElementsByTagName( "li" );
				if( ! lis.length ) {
					list.parentNode.style.display = "none";
					continue;
				}
				var h = 0, h2 = list.clientHeight;
				for( var l = 0; l < lis.length; l++ ) {
					var h3 = lis[l].offsetTop + lis[l].clientHeight;
					h = Math.max( h, h3 );
				}
				if( h <= h2 ) {
					list.className += " singleLine";
					continue;
				}
				var btn = document.createElement( "a" );
				btn.href = "javascript:void(0);";
				btn.list = list;
				btn.innerHTML = "<span>Foto, video e altri contenuti correlati</span>";
				btn.className = "listControl";
				var clickevent = function(){
					var l = this.list;
					if( ! l ) return;
					var p = l.parentNode;
					var cl = " expandList";
					var c = p.className.indexOf( cl ) >= 0;
					p.className = c ? p.className.replace( cl, "" ) : p.className + cl;
				}
				//appendEvent( btn, "mouseup", clickevent );
				list.parentNode.insertBefore( btn, list );
				list.parentNode.list = list;
				appendEvent( list.parentNode, "mouseup", clickevent );
			}
			// Inserisce gli strumenti di condivisione
			QN.art_social( art );
		}
	},
	art_social : function( art ) {
		return "sticazzi";
		QN.addThisScrip();
		var h1 = getElementsByClassName( art, "titleArticle", false, false, 1 );
		if( ! h1 ) return;
		var link = h1.getElementsByTagName( "a" );
		if( ! link.length ) return;
		var types = [ "comm", "fb", "tw", "google" ];
		var divs = art.getElementsByTagName( "div" );
		var cont = false;
		for( var d = 0; d < divs.length; d++ )
			if( divs[ d ].className.indexOf( "toolsSocial" ) >= 0 )
				var cont = divs[ d ];
		if( ! cont ) return false;
		var ret = '<div class="addthis_toolbox" addthis:url="' + link[0] + '">';
		for( var t = 0; t < types.length; t++ ) {
			var span = QN.socialSpan( types[ t ] );
			ret += "\n\t" + span;
		}
		ret += "\n</div>\n";
		cont.innerHTML = ret;
	},
	socialSpan : function( type ) {
		var cln = "", attrs = "", txt = "";
		var span = '<a class="toolsSocialBtn _cln_" _attrs_></a>';
		switch( type ) {
			case "fb":
				//cln = "addthis_button_facebook_like";
				cln = "addthis_button_facebook";
				attrs = 'fb:like:layout="button_count"';
				attrs += ' fb:like:width="100"';
				attrs += ' title="Mi Piace su Facebook"';
				break;
			case "tw":
				//cln = "addthis_button_tweet";
				//attrs = 'tw:count="horizontal"';
				cln = "addthis_button_twitter";
				attrs += ' title="Condividi su Twitter"';
				break;
			case "google":
				cln = "addthis_button_google_plusone";
				attrs += ' g:plusone:size="small"';
				attrs += ' g:plusone:width="24"';
				break;
			case "comm":
				cln = "comingsoon_commentcount";
				break;
			default:
				span = false;
				break;
		}
		if( ! span ) return "";
		span = span.replace( "_cln_", cln );
		span = span.replace( "_attrs_", attrs );
		span = span.replace( "_txt_", txt );
		return span;
	},
	init_liveBar : function() {
		var scegli = document.getElementById( "liveBar_cambia" );
		if( scegli ) {
			var ul = scegli.getElementsByTagName( "ul" );
			if( ul[0] ) {
				// SWITCH LISTA TESTATA
					var lis = ul[0].getElementsByTagName( "li" );
					var nTs = QN.getNumTestata();
					if( nTs == 3 )		// NAZIONE
						ul[0].appendChild( lis[0] );
					else if( nTs == 4 )	// GIORNO
						ul[0].insertBefore( lis[2], lis[0] );
					lis[2].className += "liveBar_last";
				// END SWITCH LISTE
				QN.submenu( ul[0] );
				var aas = ul[0].getElementsByTagName( "a" );
				for( var i = 0; i < aas.length; i++ ) {
					var m = aas[i].href.match( /\/([-\w ]+)$/ );
					if( ! m ) continue;
					aas[i].href = "javascript:void(0)";
					aas[i].switchTo = m[1];
					appendEvent( aas[i], "click", function(){
						QN.set_cookieQnet({ "edition" : this.switchTo });
						QN.init( "liveBar_locale", this.switchTo );
						QN.init( "liveBar_meteo", this.switchTo );
					});
				}
			}
		}
		QN.init( "liveBar_locale" );
		QN.init( "liveBar_meteo" );
	},
	init_liveBar_locale : function( ed ) {
		var ed = ed || QN.get_cookieQnet( "Edition" ) || false;
		var msg = "Scegli un'edizione dal menu a sinistra per visualizzarne le news in tempo reale.";
		if( ed ) {
			msg = "Caricamento delle news in tempo reale in corso...";
			var xhttp = ajaxObject();
			var uri = "/file_generali/news_pag/liz/livebar/news_citta_" + ed + ".shtml";
			if( ! xhttp ) return false;
			xhttp.open( "GET", uri, true );
			xhttp.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
			//xhttp.setRequestHeader("connection", "close");
			xhttp.onreadystatechange = function() {
				if (xhttp.readyState == 4) {
					var msg = "Non sono presenti notizie per l'edizione scelta.";
					if( xhttp.status == 200 && xhttp.responseText ) {
						msg = xhttp.responseText;
						var m = msg.match( /^\s*([^|]+)\|\s*([\w\W]+)\s*$/ );
						if( m ) {
							QN.liveBar_local( m[1] );
							msg = m[2];
						}
						msg = msg.replace( /<li[^>]+>(.+)<\/li>/gi, '<p>$1</p>' );
					}
					return QN.liveBar_message( msg );
				}
			}
			xhttp.send();
		}
		return QN.liveBar_message( msg );
	},
	init_liveBar_meteo : function( ed ) {
		var ed = ed || QN.get_cookieQnet( "Edition" ) || false;
		if( ! ed ) return false;
		var uri = "/file_generali/include/liz/vetrine/meteo/meteo_" + ed + ".shtml";
		var xhttp = ajaxObject();
		if( ! xhttp ) return false;
		xhttp.open( "GET", uri, true );
		xhttp.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
		//xhttp.setRequestHeader("connection", "close");
		xhttp.onreadystatechange = function() {
			if (xhttp.readyState == 4) {
				if( xhttp.status == 200 && xhttp.responseText ) {
					var msg = xhttp.responseText;
					var div = document.getElementById( "liveBar_meteo" );
					if( ! msg || ! div ) return false;
					div.innerHTML = msg;
				}
			}
		}
		xhttp.send();
	},
	liveBar_local : function( name ) {
		var div = document.getElementById( "liveBar_cronaca" );
		if( ! div ) return false;
		if( name.indexOf( "," ) > 0 ) {
			var spl = name.split( "," );
			if( spl.length > 1 ) {
				var a = document.createElement( "a" );
				a.href = spl[0];
				div.innerHTML = "";
				div.appendChild( a );
				div = a;
				name = spl[1];
			}
		}
		div.innerHTML = name + ":";
	},
	liveBar_message : function( msg, append ) {
		var lb_loc = document.getElementById( "liveBar_news" );
		if( ! lb_loc ) return false;
		var lb_div = lb_loc.getElementsByTagName( "div" );
		if( ! lb_div[0] ) return false;
		if( ! append ) lb_div[0].innerHTML = "";
		var div = document.createElement( "div" );
		div.innerHTML = msg;
		lb_div[0].appendChild( div );
		return true;
	},
	init_boxtabs : function() {
		var boxes = [];
		var all = document.getElementsByTagName( "div" );
		var check = "isBoxtabAlready";
		for( var i = 0; i < all.length; i++ )
			if( all[ i ].className.match( /\bboxtabs\b/ )
				&& ! all[ i ][ check ] )
				boxes.push( all[ i ] );
		for( var b = 0; b < boxes.length; b++ ) {
			boxes[ b ][ check ] = "yes.";
			var boxH = [],
				boxTabs = [];
			var carousel = boxes[ b ].getElementsByTagName( "div" )[0];
			var divs = carousel.getElementsByTagName( "div" );
			for( var d = 0; d < divs.length; d++ ) {
				if( divs[ d ].parentNode == carousel ) {
					boxTabs.push( divs[ d ] );
					boxH.push( divs[ d ].getElementsByTagName( "span" )[0] );
				}
			}
			for( i = 0; i < boxTabs.length; i++ ) {
				var tab = boxTabs[ i ];
				var tabs = document.createElement( "div" );
				tabs.className = "boxtabs_tabs";
				for( var i2 = 0; i2 < boxH.length; i2++ ) {
					var span = boxH[ i2 ].cloneNode( true );
					span.className += " boxtabs_tab";
					span.tabBox = boxTabs[ i2 ];
					if( boxH[ i2 ] == boxH[ i ] )
						span.className += " current";
					else {
						span.onmouseup = function() {
							var car = this.parentNode.parentNode.parentNode;
							var divs = car.getElementsByTagName( "div" );
							for( var i = 0; i < divs.length; i++ )
								if( divs[ i ].parentNode == car )
									divs[ i ].style.display = divs[ i ] == this.tabBox ? "block" : "none";
						}
					}
					tabs.appendChild( span );
				}
				boxH[ i ].parentNode.insertBefore( tabs, boxH[ i ] );
				boxTabs[ i ].style.display = i ? "none" : "block";
			}
			for( i = 0; i < boxH.length; i++ )
				boxH[ i ].parentNode.removeChild( boxH[ i ] );
		}
		return boxes.length;
	},
	init_artToolbar : function( comments ) {
		var cl = "artToolbar";
		var toolbar = document.getElementById( cl );
		//var art = document.getElementById( "artContent" );
		var art = document.getElementById( "testoArt" );
		if( ! art || ! toolbar ) return;
		var toolClone = toolbar.cloneNode( true );
		var scripts = toolClone.getElementsByTagName( "script" );
		while( scripts.length ) scripts[0].parentNode.removeChild( scripts[0] );
		toolClone.innerHTML = toolClone.innerHTML.replace( /(\sid="[^"]+)(?=")/i, "$1-clone" );
		QN.addThisScrip();
		/*var commAnchor = document.getElementById( "js-kit-comments" );
		if( commAnchor ) art.insertBefore( toolClone, commAnchor );
		else art.appendChild( toolClone );*/
		art.appendChild( toolClone );
		if( ! comments ) return;
		var query = "childrenof:" + location.href + " type:comment";
		var src = "http://api.echoenabled.com/v1/count?";
		src += "q=" + escape( query ) + "&";
		src += "appkey=dev.monrif&callback=QN.artCommentCount";
		var jsKitCount = document.createElement( "script" );
		jsKitCount.type = "text/javascript";
		jsKitCount.src = src;
		art.appendChild( jsKitCount );
	},
	artCommentCount : function( data ) {
		if( window["console"] ) console.debug( data );
	},
	plusOneTestata : function( coldx ) {
		return; // ESCE SEMPRE ;-)
		// Esce se è attivo l'incluso HTML
		if( document.getElementById("soccialbox") ) return;
		var id = "homeHeadline_plusone";
		if( document.getElementById( id ) ) return;
		var cont = document.getElementById( "homeHeadline_extra" );
		if( coldx ) {
			var cont = document.createElement( "div" );
			var col = document.getElementById( "homePage_coldx" );
			if( ! col ) return;
			col.insertBefore( cont, col.firstChild );
		}
		if( ! cont ) return;
		var p1 = document.createElement( "div" );
		p1.id = id;
		var nTest = QN.getNumTestata();
		var hrefs = {
			1 : "http://qn.quotidiano.net/",
			2 : "http://www.ilrestodelcarlino.it/",
			3 : "http://www.lanazione.it/",
			4 : "http://www.ilgiorno.it/"
		};

		p1.className = "plusonebox_" + nTest;
		var imgsrc = "/file_generali/img/liz/loghi/testate_mini/" + nTest + ".gif";
		var em = document.createElement( "em" );
		em.innerHTML = "<img src=\"" + imgsrc + "\" alt=\"" + hrefs[ nTest ] + "\" />";
		em.innerHTML += "<br />Consigliaci su Google";
		p1.appendChild( em );
		p1.innerHTML += '<g:plusone href="' + hrefs[ nTest ] + '"></g:plusone>';
		cont.appendChild( p1 );
		var head = document.getElementsByTagName( "head" )[0];
		var script = document.createElement( "script" );
		script.type = "text/javascript";
		script.src = "http://apis.google.com/js/plusone.js";
		//script.innerHTML = "{lang: 'it'}";
		head.appendChild( script );
	},
	init_ansa_news : function() {
		var cont = document.getElementById( "ansaNewsBox" );
		if( cont ) QN.carousel( cont, true );
	},
	init_gallery_top : function() {
		var logo = document.getElementById( "testata" );
		if( ! logo ) return;
		var m = logo.className.match( /\btest(\d+)\b/i );
		if( !( m[1] && m[1] == "1" ) ) return;
		var testata = QN.get_testataCookie();
		if( ! testata || testata.id == m[1] ) return false;
		logo.className = logo.className.replace( /(\btest)\d+\b/i, "$1" + testata.id );
		logo.href = testata.url;
		logo.getElementsByTagName("span")[0].innerHTML = testata.text;
	},
	carousel : function( cont, seq ) {
		if( typeof cont == "string" ) var cont = document.getElementById( cont );
		if( ! cont || cont.carousel ) return;
		if( ! cont.id ) {
			var id0 = "some_carousel";
			var id1 = 0;
			while( document.getElementById( id0 + id1 ) ) id1++;
			cont.id = id0 + id1;
		}
		var inside = cont.getElementsByTagName( "*" ),
			carousel = false;
		for( var i = 0; i < inside.length; i++ ) {
			if( inside[i].className.indexOf( "carousel_slide" ) >= 0 ) {
				var carousel = inside[i];
				break;
			}
		}
		cont.carousel = carousel;
		carousel.id = cont.id + "__" + carousel.className;
		if( ! carousel ) return;
		var items = [],
			divs = carousel.getElementsByTagName( "div" );
		for( var i = 0; i < divs.length; i++ )
			if( ( divs[i].parentNode == carousel && ! divs[i].className.match( /\bartTestate\b/ ) )
				|| divs[i].parentNode.className.match( /\bartTestate\b/ ) )
				items.push( divs[i] );
		if( ! items.length ) return;
		var dim = {
			width0 : cont.clientWidth,
			height0 : cont.clientHeight,
			width : carousel.clientWidth,
			height : carousel.clientHeight
		};
		if( dim.width0 == dim.width && dim.height0 == dim.height ) return;
		var keys = {
			w: { css: "width", js: "clientWidth", pos: "left" },
			h: { css: "height", js: "clientHeight", pos: "top" }
		};
		var dir = keys[ dim.width > dim.width0 ? "w" : "h" ];
		var tot = 0;
		for( var i = 0; i < items.length; i++ )
			tot += parseFloat( items[ i ][ dir.js ] );
		if( dim[ dir.css ] > tot )
			carousel.style[ dir.css ] = ( tot + 2 * items.length ) + "px";
		carousel.cDir = dir;
		var views = Math.ceil( tot / dim[ dir.css + "0" ] );
		cont.style.overflow = "hidden";
		cont.scrollLeft = 0;
		cont.scrollTop = 0;
		if( views < 2 ) return;
		var nav = document.createElement( "div" );
		nav.className = "carousel_nav";
		var navId = cont.id + "__" + nav.className;
		var preNav = document.getElementById( navId );
		if( preNav ) preNav.parentNode.removeChild( preNav );
		nav.id = navId;
		if( seq ) {
			var btns = { "-1" : "\u25C4", 1 : "\u25BA" };
			nav.maxLen = views;
			for( var i in btns ) {
				carousel.currentIndex = 0;
				var btn = document.createElement( "strong" );
				btn.theIndex = parseInt( i );
				btn.theIndexMax = nav.maxLen - 1;
				btn.innerHTML = "<span>" + btns[ i ] + "</span>";
				btn.carousel = carousel;
				appendEvent( btn, "click", function(){
					var goTo = carousel.currentIndex + this.theIndex;
					if( goTo < 0 ) goTo = this.theIndexMax;
					else if( goTo > this.theIndexMax ) goTo = 0;
					carousel.currentIndex = goTo;
					QN.carouselFocus( this.carousel, goTo );
				});
				nav.appendChild( btn );
			}
		} else {
			nav.buttons = [];
			for( var i = 0; i < views; i++ ) {
				var btn = document.createElement( "strong" );
				if( items[ i ].parentNode.className.match( /\bartTestate\b/ ) ) btn.className = "carnav_test";
				btn.theIndex = i;
				btn.innerHTML = "<span>" + ( i + 1 ) + "</span>";
				btn.carousel = carousel;
				nav.buttons[i] = btn;
				appendEvent( btn, "click", function(){ QN.carouselFocus( this.carousel, this.theIndex ); } );
				nav.appendChild( btn );
			}
		}
		appendEvent( carousel, "mouseover", function(){ this.mouseisover = true; } );
		appendEvent( carousel, "mouseout", function(){ this.mouseisover = false; } );
		cont.appendChild( nav );
		carousel.nav = nav;
		QN.carouselFocus( carousel, 0, true );
	},
	carouselFocus : function( carousel, num, go_on ) {
		if( ! carousel || ! carousel.cDir ) return;
		if( ! num ) var num = 0;
		if( ! go_on ) var go_on = false;
		if( ! carousel.mouseisover ) {
			carousel.style[ carousel.cDir.pos ] = ( - 100 * num ) + "%";
			if( carousel.nav && carousel.nav.buttons ) {
				for( var i = 0; i < carousel.nav.buttons.length; i++ ) {
					var cn = carousel.nav.buttons[ i ].className;
					var cN = " carousel_cur";
					if( i == num ) carousel.nav.buttons[ i ].className += cN;
					else carousel.nav.buttons[ i ].className = cn.replace( cN, "" );
				}
			}
		}
		// TIMERS
		var glob = "carousel_timers";
		if( ! window[ glob ] ) window[ glob ] = [];
		if( go_on ) {
			if( carousel.mouseisover ) next = num;
			else {
				var next = num + 1;
				var maxLen = carousel.nav.buttons ? carousel.nav.buttons.length : carousel.nav.maxLen || 1000;
				if( next >= maxLen ) next = 0;
			}
			var f = function(){ QN.carouselFocus( carousel, next, true ); };
			window[ glob ][ carousel.id ] = window.setTimeout( f, 4444 );
		} else {
			var t = window[ glob ][ carousel.id ];
			if( t ) window.clearTimeout( t );
		}
	},
	delay_action : function( source, out ) {
		var time = out ? 500 : 1000;
		var func = function(){ QN.mouseAction( source, out ); };
		window.setTimeout( func, time );
	},
	mouseAction : function( source, out ) {
		var menu = source.submenu || source;
		if( ! menu.isSubMenu ) return;
		if( ! menu.over ) menu.over = [];
		if( ! source ) source = menu;
		var i = Array_indexOf( menu.over, source );
		if( ! out && i < 0 ) menu.over.push( source );
		else if( out && i >= 0 ) menu.over.splice( i, 1 );
		var time = out ? 333 : 500;
		if( menu.timeout ) clearTimeout( menu.timeout );
		menu.timeout = setTimeout( function(){ QN.mouseActionDo( menu ); }, time );
	},
	mouseActionDo : function( menu ) {
		var li = menu.parentNode;
		//while( li && li.tagName != "LI" && li.parentNode ) li = li.parentNode;
		var cl = " hover";
		if( menu.over.length && li.className.indexOf( cl ) < 0 ) li.className += cl;
		else if( ! menu.over.length ) li.className = li.className.replace( cl, "" );
	},
	popup : function( url ) {
		var width = 300, height = 200;
		var left = (screen.width - width)/2;
		var top = (screen.height - height)/2;
		var params = 'width='+width+', height='+height;
		params += ', top='+top+', left='+left;
		params += ', directories=no, location=no';
		params += ', menubar=no, resizable=no';
		params += ', scrollbars=no, status=no, toolbar=no';
		newwin=window.open(url,'windowname5', params);
		if (window.focus) {newwin.focus()}
		return false;
	}
}

/* MAPPE SENSIBILI CRONACHE CITTADINE
	Attualmente:
		Milano metropoli
*/
var sense_maps = {
	"mi" : {
		"milano" : [
			"173,181,144,151,126,158,132,122,161,107,201,117,202,143,197,163",
			"",
			"http://www.ilgiorno.it/milano"
		],
		"sesto" : [
			"163,74,151,89,162,107,199,116,217,108",
			'<h1 class="titleSmall">Edizione Sesto, Cinisello e Nord Milano</h1> Sesto San Giovanni, Cinisello Balsamo, Cormano, Bresso, Paderno Dugnano, Cusano Milanino, Cologno Monzese',
			"http://www.ilgiorno.it/sesto"
		],
		"rho" : [
			"143,63,123,62,104,89,92,120,114,164,125,158,131,123,160,107,150,90,154,84",
			'<h1 class="titleSmall">Edizione Rho Bollate</h1> Rho, Lainate, Arese, Pero, Bollate, Novate Milanese, Garbagnate Milanese, Senago, Cesate, Cornaredo, Settimo Milanese, Pogliano Milanese, Vanzago, Pregnana Milanese',
			"http://www.ilgiorno.it/rho"
		],
		"martesana" : [
			"282,57,274,75,219,95,217,108,202,117,203,143,233,148,243,162,275,150,298,116,292,68",
			'<h1 class="titleSmall">Edizione Martesana</h1> Trezzo Sull\'Adda, Vaprio D\'Adda, Trezzano Rosa, Pozzo D\'Adda, Basiano, Masate, Grezzago, Segrate, Pioltello, Rodano, Melzo, Cassano D\'Adda, Inzago, Vignate, Pozzuolo Martesana, Truccazzano, Liscate, Cernusco sul Naviglio, Gorgonzola, Carugate, Cassina De\' Pecchi, Bussero, Pessano Con Bornago, Gessate, Cambiago, Bellinzago Lombardo, Vimodrone',
			"http://www.ilgiorno.it/martesana"
		],
		"sud" : [
			"133,222,175,228,242,219,300,157,242,163,232,149,202,144,198,164,172,183,144,152,113,165",
			'<h1 class="titleSmall">Edizione Sud Milano</h1> Rozzano, Opera, Basiglio, Locate Triulzi, Pieve Emanuele, Lacchiarella, Binasco, Zibido San Giacomo, Casarile, Noviglio, Vernate, Corsico, Buccinasco, Cesano Boscone, Trezzano sul Naviglio, Assago, San Donato Milanese, San Giuliano Milanese, Peschiera Borromeo, Mediglia, Settala, Pantigliate, Colturano, Melegnano, Paullo, Cerro Al Lambro, Vizzolo Predabissi, San Zenone Al Lambro, Carpiano, Cusago, Gaggiano, Dresano, Tribiano',
			"http://www.ilgiorno.it/sudmilano"
		]
	},
	"default" : {
		"mi" : function(){
			var first = 0, def = 0;
			for (i in sense_maps["mi"]) {
				if (!first) first = i;
				if (location.href.indexOf(sense_maps["mi"][i][2]) == 0) {
					def = i;
					break;
				}
			}
			if (!def) def = first;
			return def;
		}
	}
};
function sense_map_area(area,hide,show) {
	if (hide < 0) hide = "sense_map_frac";
	var h = area.alt.split(":",2);
	var it = show ? h[1] : sense_maps["default"][h[0]]();
	var id = area.parentNode.id.replace(/_map$/,'');
	var tid = id + "_frac_" + h[1];
	var tcl = "_frac_" + it;
	var frs = document.getElementById(id).getElementsByTagName("*");
	for (i in frs) {
		if (!frs[i].className||frs[i].className.indexOf(hide)<0) continue;
		if (frs[i].className.indexOf(tid) < 0) {
			frs[i].style.display = (frs[i].className.indexOf(tcl)<0||show) ? "none" : "block";
		} else
			frs[i].style.display = show ? "block" : "none";
	}
	var box = document.getElementById(id+"_cronache");
	box.innerHTML = sense_maps[h[0]][it][1];
}
function sense_map(id,src,into) {
	if (!src||!sense_maps[src]) return false;
	var bnd = document.getElementById(into);
	if (!bnd) return false;
	var box = document.getElementById(id);
	var i = 0, id2 = id;
	while (box != undefined) {
		id2 = id2.replace(/_\d+$/,'');
		id2 += "_" + (i++);
		box = document.getElementById(id2);
	}
	var map = document.createElement("map");
		map.id = id2 + "_map";
		map.name = map.id;
	bnd.appendChild(map);
	var box = document.createElement("div");
		box.id = id2;
		box.className = "sense_map sense_map_" + src;
	bnd.appendChild(box);
	for (sec in sense_maps[src]) {
		var vars = sense_maps[src][sec];
		var area = document.createElement("area");
			area.shape = "poly";
			area.href = sense_maps[src][sec][2];
			area.alt = src + ":" + sec;
			area.coords = vars[0];
			area.onmouseover = function() { sense_map_area(this,-1,1) };
			area.onmouseout = function() { sense_map_area(this,-1,0) };
		map.appendChild(area);
		var frac = document.createElement("span");
			frac.id = id2 + "_frac_" + sec;
			frac.className = box.className.match(/^\w+/).pop() + "_frac";
			frac.className += " " + box.className.match(/\w+$/).pop() + "_frac_" + sec;
			frac.style.display = (sec==sense_maps["default"][src]()) ? "block" : "none";
		box.appendChild(frac);
	}
	var img = document.createElement("img");
		img.src = "/file_generali/img/elvis/blank.gif";
		img.id = id2 + "_img";
		img.className = "sense_map_img";
		img.useMap = "#" + map.id;
		img.alt = "";
	box.appendChild(img);
	var click = document.createElement("strong");
		click.id = id2 + "_click";
		click.className = "sense_map_click";
		click.innerText = "Clicca sulla mappa per scegliere una cronaca";
	bnd.appendChild(click);
	var eds = document.createElement("div");
		eds.id = id2 + "_cronache";
		eds.className = "sense_map_cronache";
		eds.innerHTML = sense_maps[src][sense_maps["default"][src]()][1];
	bnd.appendChild(eds);
}
// <script type="text/javascript">sense_map("sense_map_mi","mi","mappa_milano_metropoli")</script>

