// JavaScript Document

/* ON LOAD */
$(document).ready(function(){
	setBgPosition();
});

/* RESIZE */

$(window).resize(function(){
	setBgPosition();
});

function setBgPosition()
{
	// Scrivo l'altezza globale della pagina
	var pageHeight = $(window).height();
	// Bottom della Pagina Int. Subito sotto ci sta il footer. Im margine top del footer batte sul bottom di Pagina Int
	var paginaIntBottom = $("div#paginaInt").height() + $("div#paginaInt").offset().top;
	//Altezza del footer
	var footerHeight = $("div#footer").height();
	
	// Calcolo il valore del margine superiore
	var margine_top = (pageHeight - paginaIntBottom - footerHeight - 13);
	// Se il margine è troppo piccolo, imposto un valore minimo
	if(margine_top < 10) margine_top = 10;
	
	// Set del margine top del footer (questo va anche su ie)
	$("div#footer").css({ marginTop: margine_top + "px"});
	
	// Calcolo la posizione del fondo del footer
	var footerBottom = $("div#footer").height() + $("div#footer").offset().top;
	
	// Imposto l'altezza globale di html e body (per avere lo sfondo del body che va fino in fondo)
	$("body").css({height: (footerBottom + 13) + "px"});
	$("html").css({height: (footerBottom + 14) + "px"});
	// $("html").css({border: "1px solid red"});
}

/* FUNZIONE DI CARICAMENTO DEL CATALOGO VIA AJAX */
function loadCatalogueElement(paginaHtml,destinazione)
{
	$.ajax({
	  url: paginaHtml,
	  dataType: "html",
	  cache: false,
	  success: function(html){
		$(destinazione).replaceWith(html);
		$('#gallery a').lightBox();
		$('#dettaglio_prodotto_immagine a').lightBox();
	}
	});
}



