function StageSet() {
	this.prototype.constructor = StageSet;
};
//
StageSet.arr_paesi = null;
StageSet.search_bar = null;
StageSet.pluginloaded = null;
StageSet.hasResults = false;
//
StageSet.locale = "it_IT";
StageSet.last_idPaese = false;
StageSet.last_idSezione = false;
StageSet.ricercaWasOpened = false;
StageSet.timeout_closeballoon = false;
//
StageSet.last_placemark = null;
//
StageSet.init = function() {
//	trace("StageSet.init: ");
	//
	GoogleEarthPlugin.init("map3d");
	GoogleEarthPlugin.locale = StageSet.locale;
//	trace("StageSet.locale: "+StageSet.locale);
	var a = new Object();
	a[GoogleEarthPlugin.EVT_ON_LOAD] = StageSet.ge_plugin_onLoad;
	a[GoogleEarthPlugin.EVT_ON_BALLOON_CLOSE] = StageSet.ge_plugin_onBalloonClose;
	a[GoogleEarthPlugin.EVT_ON_BALLOON] = StageSet.ge_plugin_onBalloon;
	a[GoogleEarthPlugin.EVT_ON_PLACEMARK_CLICK] = StageSet.ge_plugin_onPlacemarkClick;
	GoogleEarthPlugin.eventDispatcher.addListener(a);
};
//
StageSet.onLoad = function(locale) {
//	trace("StageSet.onLoad: "+locale);
	if (locale) {
		StageSet.locale = locale;
		GoogleEarthPlugin.locale = StageSet.locale;
	}
	//
	StageSet.search_bar = new SearchBar($("country"), $("category"), $("keywordTextfield"), $("cercaButton"));
	var a = new Object();
	a[SearchBar.EVT_ON_PAESE] = StageSet.searchBar_onPaese;
	a[SearchBar.EVT_ON_SEARCH] = StageSet.searchBar_onSearch;
	a[SearchBar.EVT_ON_RESET] = StageSet.searchBar_onReset;
	StageSet.search_bar.addListener(a);
	//
};

StageSet.ge_plugin_onLoad = function(event) {
//	trace("ge_plugin_onLoad: ");
	if (StageSet.pluginloaded) return;
	StageSet.loadSupportoRicerca();
};

StageSet.loadSupportoRicerca = function() {
	var flashvars = {
		config_user:  Configurazione.config_user,
		locale:  StageSet.locale
	};
	var params = {};
	params.menu = "false";
	params.bgcolor = "#FFFFFF";
	params.allowScriptAccess = "true";
	var attributes = {};
	attributes.id = "supportoRicercaSWF";
	attributes.name = "supportoRicercaSWF";
	swfobject.embedSWF(Configurazione.supportoRicercaUrl, "supportoRicerca", "1", "1", "9.0.124", "expressInstall.swf", flashvars, params, attributes);
};

StageSet.supportoRicerca_onLoad = function() {
//	trace("StageSet.supportoRicerca_onLoad");
	StageSet.pluginloaded = true;
	//
//	StageSet.loadResults();
	StageSet.loadRadioButtons();
};

StageSet.loadRadioButtons = function() {
	var flashvars = {
		config_user:  Configurazione.config_user,
		locale:  StageSet.locale
	};
	var params = {};
	params.menu = "false";
	params.bgcolor = "#FFFFFF";
	params.allowScriptAccess = "true";
	var attributes = {};
	attributes.id = "radiobuttonsSWF";
	attributes.name = "radiobuttonsSWF";
	swfobject.embedSWF(Configurazione.radiobuttonsUrl, "Radiobuttons", "748", "82", "9.0.124", "expressInstall.swf", flashvars, params, attributes);
};

StageSet.radiobuttons_onLoad = function() {
//	trace("StageSet.radiobuttons_onLoad();");
	StageSet.loadResults();
};

StageSet.loadResults = function() {
	var shimmer = document.createElement('iframe');
	shimmer.id='resultsContainer';
	shimmer.frameBorder = 0;
	shimmer.style.width='20px';
	shimmer.style.height='390px';
	shimmer.style.overflow='hidden';
	shimmer.style.zIndex='999';
	shimmer.setAttribute('scrolling','no');
	shimmer.setAttribute('frameborder','0');
	$("results").appendChild(shimmer);
	
	var flashvars = {
		config_user:  Configurazione.config_user,
		locale:  StageSet.locale
	};
	var params = {};
	params.menu = "false";
	params.bgcolor = "#FFFFFF";
	params.allowScriptAccess = "true";
	var attributes = {};
	attributes.id = "resultsSWF";
	attributes.name = "resultsSWF";
	swfobject.embedSWF(Configurazione.swfResults, "resultsContainer", "340", "390", "9.0.124", "expressInstall.swf", flashvars, params, attributes);
	
	StageSet.closeResults();
	
};

StageSet.results_onLoad = function() {
//	trace("results_onLoad: ");
	$("radiobuttonsSWF").setActiveFolder(GoogleEarthPlugin.FOLDER_ALL);
	//
	GoogleEarthPlugin.loadShadowRisultati();
};

StageSet.radiobuttons_onChange = function(folder, hasVideo, hasGallery) {
	var folderName = folder;
	if (hasGallery) folderName+="_g";
	if (hasVideo) folderName+="_v";
	trace("radiobuttons_onChange: "+folder+"="+GoogleEarthPlugin.folderExists(folder)+", hasVideo:"+hasVideo+", hasGallery:"+hasGallery);
	if (GoogleEarthPlugin.folderExists(folderName)) {
		GoogleEarthPlugin.switchFolder(folderName);
	} else {
		GoogleEarthPlugin.switchFolder(GoogleEarthPlugin.FOLDER_NONE);
		GoogleEarthPlugin.toggleLoading(true);
		$("supportoRicercaSWF").loadPlacemarks(folder, hasVideo, hasGallery);
	}
};

StageSet.searchBar_onReset = function (event) {
	$("supportoRicercaSWF").reloadPaesi();
	//
	StageSet.fillComboSezioni([]);
};

StageSet.loadPlacemarks = function (placemarks, folder) {
//	trace("loadPlacemarks("+placemarks+","+folder+")");
	if (!GoogleEarthPlugin.folderExists(GoogleEarthPlugin.FOLDER_ALL)) GoogleEarthPlugin.zoomOut();
	GoogleEarthPlugin.createPlacemarks(placemarks, folder);
};

StageSet.selectPlacemark = function (idPaese, idSezione) {
//	trace("selectPlacemark("+idPaese+", "+idSezione+")");
	GoogleEarthPlugin.switchFolder(GoogleEarthPlugin.FOLDER_ALL);
	$("radiobuttonsSWF").setActiveFolder(GoogleEarthPlugin.FOLDER_ALL);
	GoogleEarthPlugin.selectPlacemark(idPaese, idSezione);
	if (StageSet.timeout_closeballoon) clearTimeout(StageSet.timeout_closeballoon);
};

StageSet.searchBar_onPaese = function (event) {
//	trace("searchBar_onPaese: ");
	$("supportoRicercaSWF").updateSezioni(event.paese);
	//
	StageSet.fillComboSezioni([]);
};

StageSet.searchBar_onSearch = function (event) {
//	trace("searchBar_onSearch: ");
	
	var h = $("map3d").style.height;
	if (h!="100%") {
		StageSet._hideApprofondimenti();
		//
		$("containerMap3d").style.height = "390px";
		$("containerMap3d").style.width = "748px";
		$("map3d").style.height = "390px";
		$("map3d").style.width = "748px";
		$("radiobuttonsSWF").style.height = "82px";
		$("radiobuttonsSWF").style.width = "748px";
		$("containerRadiobuttons").style.height = "82px";
		$("containerRadiobuttons").style.width = "748px";
//		$("results").style.height = "390px";
	}
	
	if (event.keyword.length) {
		var searchLaunched = $("resultsSWF").doSearch(event.paese, event.sezione, event.keyword);
//		trace("searchLaunched: "+searchLaunched);
		if (searchLaunched) StageSet.showResults();
	} else {
		$("supportoRicercaSWF").doSearch(event.paese, event.sezione, event.keyword);
		StageSet.closeResults();
	}
};

StageSet.fillComboPaesi = function (arr_paesi) {
	if (!StageSet.arr_paesi) StageSet.arr_paesi = arr_paesi;
	StageSet.search_bar.fillComboPaesi(arr_paesi);
};

StageSet.getNomePaese = function (idPaese) {
	var nomePaese = "NOT FOUND";
	if (!StageSet.arr_paesi) return nomePaese;
	for ( var int = 0; int < StageSet.arr_paesi.length; int++) {
		var array_element = StageSet.arr_paesi[int];
		if (array_element.data==idPaese) {
			nomePaese = array_element.label;
		}
	}
	return nomePaese;
};

StageSet.fillComboSezioni = function (arr_sezioni) {
	StageSet.search_bar.fillComboSezioni(arr_sezioni);
};

StageSet.closeBalloon = function () {
	GoogleEarthPlugin.closeBalloon();
	setTimeout("GoogleEarthPlugin.zoomOut()", 400);
};

StageSet.results_onData = function (hasResults) {
	trace("results_onData: "+hasResults);
	StageSet.hasResults = hasResults;
};

StageSet.collapseResults = function() {
	var swf;
	swf = $("resultsSWF");
	try {
		swf.setCollapsed(true);
	} catch (e) {
	}
	swf.style.width='17px';
	// TODO: mettere in fase di pubblicazione con un livello reale - 23/giu/2009 - fastweb
	/*
	$("col_dx").style.display="block";
	$("col_dx").style.display="none";
	*/
	//
	GoogleEarthPlugin.moveShadowRisultati(17);
};

StageSet.showResults = function() {
	//
	StageSet.closeBalloon();
	var swf;
	swf = $("resultsSWF");
//	trace("StageSet.showResults: "+swf);
	try {
		swf.setCollapsed(false);
	} catch (e) {
	}
	swf.style.width='340px';
	// TODO: mettere in fase di pubblicazione con un livello reale - 23/giu/2009 - fastweb
	/*
	$("col_dx").style.display="block";
	$("col_dx").style.display="none";
	*/
	// TODO: il div per il fix di IE8 deve essere presente, quindi va cambiato in produzione - 08/giu/2009 - fastweb
	//
	GoogleEarthPlugin.moveShadowRisultati(340);
};

StageSet.hideResults = function() {
//	trace("StageSet.hideResults: ");
	var swf;
	swf = $("resultsSWF");
	try {
		swf.setCollapsed(true);
	} catch (e) {
	}
	swf.style.width='0px';
	// TODO: mettere in fase di pubblicazione con un livello reale - 23/giu/2009 - fastweb
	/*
	$("col_dx").style.display="block";
	$("col_dx").style.display="none";
	*/
	// TODO: il div per il fix di IE8 deve essere presente, quindi va cambiato in produzione - 08/giu/2009 - fastweb
	//
	GoogleEarthPlugin.moveShadowRisultati(-100);
};

StageSet.closeResults = function() {
//	trace("StageSet.closeResults: ");
	StageSet.hasResults = false;
	StageSet.hideResults();
};

StageSet.results_onClick = function(results_vo) {
//	trace("StageSet.results_onClick: "+results_vo.tipo);
	switch (results_vo.tipo) {
		case "sezione":
			StageSet.collapseResults();
			StageSet.selectPlacemark(results_vo.id_stato,results_vo. id_sezione);
			break;
		case "approfondimento":
			StageSet.ricercaWasOpened = true;
			StageSet.showApprofondimenti(results_vo.link_approfondimento);
			break;
	}
};

StageSet.link_onClick = function(link_vo) {
//	trace("StageSet.link_onClick: "+link_vo);
	StageSet.ricercaWasOpened = false;
	StageSet.showApprofondimenti(link_vo.url);
};

StageSet.ge_plugin_onBalloonClose = function(event) {
};

StageSet.ge_plugin_onBalloon = function(event) {
	if (StageSet.hasResults) {
		StageSet.collapseResults();
	} else {
		StageSet.closeResults();
	}
};

StageSet.ge_plugin_onPlacemarkClick = function(event) {
	if (StageSet.hasResults) {
		StageSet.collapseResults();
	} else {
		StageSet.closeResults();
	}
};

StageSet._hidePlugin = function() {
//	trace("StageSet._hidePlugin: ");
	StageSet.closeBalloon();
	StageSet.hideResults();
	$("containerMap3d").style.height = "0px";
	$("containerMap3d").style.width = "0px";
	$("map3d").style.height = "0px";
	$("map3d").style.width = "0px";
	$("radiobuttonsSWF").style.height = "0px";
	$("radiobuttonsSWF").style.width = "0px";
	$("containerRadiobuttons").style.height = "0px";
	$("containerRadiobuttons").style.width = "0px";
	$("results").style.height = "0px";
};

StageSet.showPlugin = function(idPaese, idSezione) {
//	trace("StageSet.showPlugin: ");
	StageSet._hideApprofondimenti();
	//
	$("containerMap3d").style.height = "390px";
	$("containerMap3d").style.width = "748px";
	$("map3d").style.height = "390px";
	$("map3d").style.width = "748px";
	$("radiobuttonsSWF").style.height = "82px";
	$("radiobuttonsSWF").style.width = "748px";
	$("containerRadiobuttons").style.height = "82px";
	$("containerRadiobuttons").style.width = "748px";
	$("results").style.height = "390px";
	//
	if (idPaese||idSezione) {
		StageSet.selectPlacemark(idPaese, idSezione);
		if (StageSet.hasResults) StageSet.collapseResults();
	} else {
		if (StageSet.ricercaWasOpened) {
			StageSet.showResults();
		} else {
			if (StageSet.hasResults) StageSet.collapseResults();
			GoogleEarthPlugin.reopenLastBalloon();
		}
	}
	StageSet.ricercaWasOpened = false;
};

StageSet._hideApprofondimenti = function() {
	try {
//		StageSet.showPlugin();
		unloadContentEniWorldWide();
//		trace("hideApprofondimenti - unloadContentEniWorldWide ");
	} catch (e) {
		trace("hideApprofondimenti - unloadContentEniWorldWide NON TROVATO !!! "+e);
	}
};

StageSet.showApprofondimenti = function(url) {
	//
//	$("ajaxContent").style.display="block";
//	$("ajaxContent2").style.display="block";
//	$("ajaxContent3").style.display="block";
//	$("col_dx").style.display="block";
	try {
		StageSet._hidePlugin();
		loadContentEniWorldWide(url);
//		trace("showApprofondimenti - loadContentEniWorldWide "+url);
	} catch (e) {
		trace("showApprofondimenti - loadContentEniWorldWide !!! "+e);
	}
};

StageSet.init();

function isReady() {
	return true;
}

