/* 
Dipendenze
	Jquery
*/
$(function() {
	Ideal.initialize();
})

var Ideal = new objIdeal();

function objIdeal() {

	this.openGallery = function() {	
		var par = "width:800, height=500,toolbar=0,status=0,resizable=0,menubar=0,scrollbars=0,titlebar=0";
		window.open("gallery/dufour.html","IdealGallery", par, null);		
	}
	
	this.msgBox = function(messaggio) {
		$("#msgBox").dialog( "option", "title", 'Info' );
		$("#msgBox").dialog( "option", "width", 'auto' );
		$("#msgBox").dialog( "option", "height", 'auto' );
		$("#msgBox").html("<p>" + messaggio + "</p>");
		$("#msgBox").dialog("open");
	}
	
	this.loadSection = function(tipo) {
		var frm = document.forms[0];
		frm.action = tipo + ".html";
		frm.method = "post";
		frm.target = "_self";
		frm.submit();
	}
	
	this.loadTopPage = function(top) {
		this.load('tops/' + top + '.html', "topPage");
	}
	
	this.loadBottomPage = function(bottom) {
		this.load('bottoms/' + bottom + '.html', "bottomPage");
	}
	
	this.loadBodyPage = function(body) {
		this.load('bodies/' + body + '.html', "bodyPage");
	}
	
	this.loadSubBodyPage = function(subBody) {
		this.load('bodies/' + subBody + '.html', "subBody");
	}
	
	this.load = function(page, destination) {
		$('#' + destination).load(page, null,function(responseText, textStatus, xhr) {
			Ideal.initialize('#' + destination);
		});
	}
	
	this.initialize = function(destination) {
		if (destination == null) destination = "body";
		
		$(destination + ' .SectionMenu > button').click(function() {
			var tipo = $(this).attr("id");
			Ideal.loadSection(tipo);
		});
		$(destination + ' .menuTopContent > button').click(function() {
			var tipo = $(this).attr("id");
			Ideal.loadBodyPage(tipo.replace("#",""));
		});
		$(destination + ' .menuBodyContent > button').click(function() {
			var tipo = $(this).attr("id");
			Ideal.loadSubBodyPage(tipo.replace("#",""));
		});
	}
}
