var elenco_news = [	"01 Set. - Nuovi corsi invernali",
					"Click qui per leggere tutte le news"
				  ];
var elenco_foto = [ 'url("img/index_dock.jpg") center no-repeat',
					'url("img/index_sail.jpg") center no-repeat',
					'url("img/index_boat.jpg") center no-repeat',
					'url("img/index_jet.jpg") center no-repeat'
				  ];

var elenco_auto = [ 'img/autobus.jpg',
					'img/autocarro.jpg'
				  ];

const elenco_auto_len = 2;
const elenco_foto_len = 4;
var ix_news = 0;
var ix_loop = 0;
var ix_flipflop = 0;
var ix_step = 8;

var newwindow='';		// needed for popup "back-annotation"

//var mare_default_color = '#000000';
//var strada_default_color = '#000000';
//var mare_high_color = '#FF0000';
//var strada_high_color = '#FF0000';
var demo_on = true;
var demo_str = '';

function news(){
	len = elenco_news.length - 1;
	document.getElementById('news').innerHTML=elenco_news[ix_news];
	if (ix_news < len)
		ix_news = ix_news + 1;
	else
		ix_news = 0;

	setTimeout('news()',2000);
}

function setOpacity(value) {
	document.getElementById('back_img').style.opacity = value/10;
	document.getElementById('back_img').style.filter = 'alpha(opacity=' + value*10 + ')';
}

function setOpacityAuto(value) {
	document.getElementById('auto_img').style.opacity = value/10;
	document.getElementById('auto_img').style.filter = 'alpha(opacity=' + value*10 + ')';
}

function fade_out(){
	if (ix_step >= 0){
		setOpacity(ix_step);
		ix_step = ix_step - 1;
		setTimeout('fade_out()',120);
	}
	else{
		ix_step = 8;
		setTimeout('swap_back()',250);
	}
}

function fade_out_auto(){
	if (ix_step >= 0){
		setOpacityAuto(ix_step);
		ix_step = ix_step - 1;
		setTimeout('fade_out_auto()',120);
	}
	else{
		ix_step = 8;
		setTimeout('swap_back_auto()',250);
	}
}
	
function swap_back(){
	var obj = document.getElementById('back_img');

	obj.style.background=elenco_foto[ix_loop];
	if (ix_loop < elenco_foto_len-1)
	  ix_loop = ix_loop + 1;
	else
	  ix_loop = 0;
			
	setOpacity(10);
	setTimeout('fade_out()',3000);
}

function swap_back_auto(){
	
	setOpacityAuto(10);
	setTimeout('fade_out_auto()',3000);
	
	document.getElementById('auto_img').src = elenco_auto[ix_loop];
	if (ix_loop < elenco_auto_len-1)
	  ix_loop = ix_loop + 1;
	else
	  ix_loop = 0;
			
	
}

function doBlink(){
  var obj = document.getElementById('id_blink');
  
  if (obj.style.color == "#C31212")
  		obj.style.color = "white";
  else
  		obj.style.color = "#C31212";
}

function imgpop(filename,testo,tipo) {
	if (tipo=='H')
		s = 'height=400,width=520';
	else
		s = 'height=520,width=395';
	newwindow2=window.open('','imgpopup',s);
	var tmp = newwindow2.document;
	tmp.write('<html><head><title>Patenti Bignami - Galleria di Immagini</title>');
	tmp.write('</head><body><div><img src="img/galleria/'+filename+'" alt="'+testo+'" /></div>');
	tmp.write('</body></html>');
	tmp.close();
	// thanks to www.quirksmode.org and the great ppk book !!
}

function popitup(url,w,h) {
	s = 'height='+h+',width='+w+',scrollbars=yes,resizable=yes';
	newwindow=window.open(url,'popup',s);
	if (window.focus) {newwindow.focus()}
	urchinTracker('/pop_up/'+url);			// for google analytics
	return false;
	// thanks to www.quirksmode.org and the great ppk book !!
}

function to_old_win(url)
{
	if (!newwindow.closed) {opener.location.href = url}
	// thanks to www.quirksmode.org and the great ppk book !!	
}

function centerPopUp( url, name, width, height) {
	var yes		= 1;
	var no		= 0;
	var menubar     = no;  // The File, Edit, View Menus
	var scrollbars  = no; // Horizontal and vertical scrollbars
	var locationbar = no;  // The location box with the site URL
	var directories = no;  // the "What's New", "What Cool" links
	var resizable   = no;  // Can the window be resized?
	var statusbar   = no;  // Status bar (with "Document: Done")
	var toolbar     = no;  // Back, Forward, Home, Stop toolbar

	if( scrollbars == null ) scrollbars = "0"
		str  = "";
		str += "resizable=1,";
		str += "scrollbars=" + scrollbars + ",";
		str += "width=" + width + ",";
		str += "height=" + height + ",";

		str += "" +
			(menubar ? ",menubars" : "") +
			(scrollbars ? ",scrollbars" : "") +
			(locationbar ? ",location" : "") +
			(directories ? ",directories" : "") +
			(resizable ? ",resizable" : "") +
			(statusbar ? ",status" : "") +
			(toolbar ? ",toolbar" : "");


	if ( window.screen ) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = ( aw - width ) / 2;
		var yc = ( ah - height ) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	window.open( url, name, str );
}

// http://www.boutell.com/newfaq/creating/include.html

function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

function color(id, x) {
	document.getElementById(id).style.color=x;
}

