// JavaScript Document by giacomo mola

function in_array(pagina,arraydipagine){
	for(n in arraydipagine){
		if(arraydipagine[n] === pagina){
			return true;
			}
	}
	return false;
}

function ShowPageArray(pagina,idcontent){
	var pagine = new Array("pagina1.php","pagina2.php");
	if(in_array(pagina,pagine)){
		var page;
		page =  $.ajax({
					   url: pagina,
					   async: false
					   }).responseText;
		$("#"+idcontent).html(page);
	} else {
		alert('Non Puoi.');
	}
}	

function LoadPageInDiv(idcontent){
	var page,pagename;
//	pagename = "include\\"+idcontent+".inc.html";
	pagename = "include/"+idcontent+".inc.html";
	page =  $.ajax({
				   url: pagename,
				   async: false
				   }).responseText;
	$("#"+idcontent).html(page);
}	

// -- Grid Object -- //

function makejgrid(tablediv,bei_array) {
    var box_h_class = "";
    var HTML = "";
    var i = 0;
    
    for (var socio in bei_array)
    {
      HTML += "<div id='" + tablediv + "_box_main_" + i + "' class='box_main'>";
      HTML += "  <div id='" + tablediv + "_box_header_" + i + "' class='box_header'>";
      if ((i % 2) == 0) 
        box_h_class="box_tab_header_hi"; 
      else 
        box_h_class="box_tab_header_lo";
        
      HTML += "    <table class='" + box_h_class + "'>";
      HTML += "      <tr>";
      HTML += "        <td align='left' width='380'><a href='javascript:GestBox(\"" + tablediv + "_box_contents_" + i + "\")'>" + bei_array[socio][0] + "</a></td>";
      HTML += "        <td align='right' width='120'>" + bei_array[socio][1] + "</td>";
      HTML += "      </tr>";
      HTML += "    </table>";
	  
      HTML += "    <div id='" + tablediv + "_box_contents_" + i + "' class='box_contents'>";
      HTML += "      <hr />";

	  HTML += "      	<table width='100%'>";
      HTML += "           <tr>";
      HTML += "             <TD align='left' valign='top'>" + bei_array[socio][2] + "</TD>";
      HTML += "             <TD align='left' valign='top'>" + bei_array[socio][3] + "</TD>";
      HTML += "           </tr>";
      HTML += "           <tr>";
      HTML += "             <TD align='left' valign='top'>" + bei_array[socio][4] + "</TD>";
      HTML += "             <TD align='left' valign='top'>" + bei_array[socio][5] + "</TD>";
      HTML += "           </tr>";
      HTML += "           <tr>";
      HTML += "             <TD align='left' valign='top'><a href='http://" + bei_array[socio][6] + "' target='affiliato' title='Visita il sito'>" + bei_array[socio][6] + "</a></TD>";
      HTML += "             <TD align='left' valign='top'><a href='mailto:" + bei_array[socio][7] + "' title='Scrivici'>" + bei_array[socio][7] + "</a></TD>";
      HTML += "           </TR>";
      HTML += "           <tr>";
      HTML += "             <td colspan='2'><hr /></td>";
      HTML += "           </tr>";
	  HTML += "      	</table>";
      
	  /*HTML += LoadIncToString(socio);*/
      /*
	  HTML += "      <TABLE align='left' border=0 cellspacing=2 cellpadding=2 width='100%'>";
      HTML += "        <tr>";
      HTML += "          <TD align='left' valign='top'>" + bei_array[socio][2] + "</TD>";
      HTML += "          <TD align='left' valign='top'>" + bei_array[socio][3] + "</TD>";
      HTML += "        </tr>";
      HTML += "        <tr>";
      HTML += "          <TD align='left' valign='top'>" + bei_array[socio][4] + "</TD>";
      HTML += "          <TD align='left' valign='top'>" + bei_array[socio][5] + "</TD>";
      HTML += "        </tr>";
      HTML += "        <tr>";
      HTML += "          <TD align='left' valign='top'><a href='http://" + bei_array[socio][6] + "' target='affiliato' title='Visita il sito'>" + bei_array[socio][6] + "</a></TD>";
      HTML += "          <TD align='left' valign='top'><a href='mailto:" + bei_array[socio][7] + "' title='Scrivici'>" + bei_array[socio][7] + "</a></TD>";
      HTML += "        </TR>";
      HTML += "        <tr>";
      HTML += "          <td colspan='3'><hr /></td>";
      HTML += "        </tr>";
      HTML += "      </table>";
      */
	  HTML += "    </div>";
	  
      HTML += "  </div>";
      HTML += "</div>";
      
      i++;
    }
       
    $("#"+tablediv).html(HTML);
}

function LoadIncToString(idinc) {
  var rhtml,pagename;
  pagename = "table\\"+idinc+".inc";
  
  rhtml =  $.ajax({
           url: pagename,
           async: false
           }).responseText;
  return rhtml;
} 
 

function opendiv(divid)
{
  document.getElementById(divid).style.visibility = "visible";
  document.getElementById(divid).style.height = "auto";
  document.getElementById(divid).style.display = "block";
}      
function closediv(divid)
{
  document.getElementById(divid).style.visibility = "hidden";
  document.getElementById(divid).style.height  = "0px";
  document.getElementById(divid).style.display = "none";
}
function GestBox(divid)
{
  var status = document.getElementById(divid).style.visibility;
  if ((status == "hidden") || (status == ""))
  {
    opendiv(divid);
  }
  else
  {
    closediv(divid);
  }
}

function OpenCatalogo(htmlpage)
{
  var pagename = "cataloghi\\"+htmlpage+".html";
  
  var w = 950;
  var h = 700;
  var l = Math.floor((screen.width-w)/2);
  var t = Math.floor((screen.height-h)/2);
  
  window.open(pagename,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}

// -- Create a spot div / James Mola 02.12.2010 -- //

var n_diapositive;
var n_current;
var margin_top;

function MakeSpot(div,time,_nd) {
	
	n_diapositive = _nd;
	n_current  = 2;
	margin_top = 350;
	
	if (document.getElementById(div) != null)
	{
		LoadPageInDiv(div);
			
		document.getElementById(div).style.display = "block";
		$("#"+div).animate({
			opacity: 0.85,
			height: '350px'
			}, 2000, 
			function() {
				// Animation complete.
				setTimeout(scrollDiv, time);
			}
		);
	}

	// -- evento di chiusura spot -- //
	var myHandler = function() {
		$("#"+div).animate({
			opacity: 0.10,
		    height: 'toggle'
  			}, 5000, 
			function() {
			    // Animation complete.
				document.getElementById(div).style.display = "none";
			}
		);
	}

	// -- evento di scrool spot -- //
	var scrollDiv = function() {
		$("#spot_contenuto").animate(
			{marginTop: '-'+margin_top+'px'}, 
			500, 
			function() {
			    // Animation complete.
				if(n_diapositive == n_current)
				{
					setTimeout(myHandler, time);
				}
				else
				{
					n_current++;
					margin_top += 350;
					setTimeout(scrollDiv, time);
				}
  		});
	}
	
//	setTimeout(myHandler, time);
}


