function adaptPage(minHeight)
{
    var object = document.getElementById('container');
    
    var fixedHeight = document.documentElement.clientHeight -67;
    
    if(minHeight != undefined)
    {
    	if(fixedHeight <= minHeight)
        {
        	fixedHeight = minHeight;
        }
    }
    
    object.style.minHeight = (fixedHeight) + 'px';
}

var oldItem = 'item5';
function changeEvent(item)
{
	//alert(oldItem);
	var blockOld = document.getElementById(oldItem);
	blockOld.style.display = "none";

	var block = document.getElementById(item);
	block.style.display = "block";
	
	if(item == 'articolo9')
	{
		var object = document.getElementById('container');
	    object.style.minHeight = (document.documentElement.clientHeight + 180 -37) + 'px';
	}
	else if(oldItem == 'articolo9')
	{
		adaptPage();
	}
	
	oldItem = item;
}

function openGallery()
{
	window.open('showGallery.html', 'mywindow', 'left=20,top=20,width=1000,height=700,toolbar=1,resizable=1');
}

function openVideo()
{
	window.open('showVideo.html', 'mywindow', 'left=20,top=20,width=1000,height=700,toolbar=1,resizable=1');
}

function initStatuto()
{
	oldItem = 'articolo1';
}

function onLoadEvent()
{
	adaptPage(720);
	var get = parseGetVars();
	
	if(get['item'] != undefined)
	{
		changeEvent(get['item']);
	}
}

function parseGetVars()
{
  // creo una array

  var args = new Array();
  // individuo la query (cioè tutto quello che sta a destra del ?)
  // per farlo uso il metodo substring della proprietà search
  // dell'oggetto location
  var query = window.location.search.substring(1);
  // se c'è una querystring procedo alla sua analisi
  if (query)
  {
    // divido la querystring in blocchi sulla base del carattere &
    // (il carattere & è usato per concatenare i diversi parametri della URL)
    var strList = query.split('&');
    // faccio un ciclo per leggere i blocchi individuati nella querystring
    for(str in strList)
    {
      // divido ogni blocco mediante il simbolo uguale
      // (uguale è usato per l'assegnazione del valore)
      var parts = strList[str].split('=');
      // inserisco nella array args l'accoppiata nome = valore di ciascun
      // parametro presente nella querystring
      args[unescape(parts[0])] = unescape(parts[1]);
    }
  }
  return args;
}

function openHomePopUp()
{
	$( "#dialog" ).dialog();
	$("#dialog").dialog( "option", "position", [($(window).width()-450)/2,180] );
	$("#dialog").dialog( "option", "width", 500 );
	$("#dialog").dialog( "option", "height", 300 );
}

function redirect(url)
{
	location.href = url;
}
