var FotoVideoOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '420px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// Identifica un overlay a pił passi 
	this.overlay.stepOverlay = true;
	
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	//overlay indica il tipo di overlay che usiamo.
	//gli altri parametri sono quelli del file di configurazione
	this.stepOne = function (overlay, azione, content_id, mix_param) {
		this.overlay.scriptUrl = "http://" +  conf.baseUrl + "/overlay_manager/" + azione;
		
		var actionString = 'content_id=' + content_id;
		
		 switch (azione) {
		 	//foto
		 	case 'foto_elimina':	actionString += '&page=' + mix_param; // uso view_state per indicare la pagina				
		 							break;
		 	case 'foto_visibile':	actionString += '&view_state=' + mix_param;
		 							break;
		 	
		 	// video   
		 	case 'video_elimina':	actionString += '&page=' + mix_param;
		 							break;
		 	case 'video_visibile':	actionString += '&view_state=' + mix_param;
		 							break;		 	
		 }
		 
		 this.overlay.setContentByAjax(actionString, null, null, this);
	};
	
	this.stepTwo = function (azione, content_id, view_state) {
		this.overlay.scriptUrl = "http://" +  location.hostname + "/gui_manager/foto_video/" + azione;		
		var actionString = 'content_id=' + content_id + '&azione=' + azione + '&view_state=' + (view_state ? view_state : 0);
		
		if(azione == 'foto_visibile'){
			//this.overlay.stepTwo(actionString, null, null, this.reload);
			this.overlay.getResultByAjax(actionString, this, this.reload_foto);
		}else if(azione == 'video_visibile'){
			this.overlay.getResultByAjax(actionString, this, this.reload_video);
		}else{
			this.overlay.stepTwo(actionString, null, null, this);
		}
		
	};
	
	this.reload_foto = function (obj, data) {
		var responseText = data.header + data.body;
		obj.show(null, responseText, null);
		//OverlayConfiguration.foto_video.overlay.hide();
		// del ok		
		if(String(data['result']) == "OK"){
			// reload_url = 'http://'+ data['params']['nick'] +'.'+ conf.domain +'/gallery/photo_detail/1/'+ data['params']['content_id'] +'/image_detail?method=single_photo';
			reload_url = Utilities.getUserUrl(data.params.nick) + '/gallery/photo_detail/1/'+ data['params']['content_id'] +'/image_detail?method=single_photo';
			reload_ajax(reload_url,'dettaglio_gallery');
			save = 'yes';
		}
		// del ko
		else{			
			OverlayManager.show('genericMessage', 'Attenzione', data['params']['error'], 'rosso');
			save = 'no';
		}
		
		//var t=setTimeout(function(){OverlayConfiguration.kiss.changeProfile1(document.getElementById('currentIndex').value, document.getElementById('currentPage').value, 'kiss', save);}, changeProfileTime);
	};
	
	this.reload_video = function (obj, data) {
		var responseText = data.header + data.body;
		obj.show(null, responseText, null);
		//OverlayConfiguration.foto_video.overlay.hide();
		// del ok		
		if(String(data['result']) == "OK"){
			// reload_url = 'http://'+ data['params']['nick'] +'.'+ conf.domain +'/gallery/video_detail/1/'+ data['params']['content_id'] +'/video_detail?method=single_video';
			reload_url = Utilities.getUserUrl(data.params.nick) + '/gallery/video_detail/1/'+ data['params']['content_id'] +'/video_detail?method=single_video';
			
			reload_ajax(reload_url,'dettaglio_gallery');
			save = 'yes';
		}
		// del ko
		else {			
			OverlayManager.show('genericMessage', 'Attenzione', data['params']['error'], 'rosso');
			save = 'no';
		}
		
		//var t=setTimeout(function(){OverlayConfiguration.kiss.changeProfile1(document.getElementById('currentIndex').value, document.getElementById('currentPage').value, 'kiss', save);}, changeProfileTime);
	};
};

OverlayConfiguration.foto_video = new FotoVideoOverlay('textOverlay');
OverlayManager.foto_video = function (args) {
	OverlayConfiguration.foto_video.stepOne('foto_video', args[0], args[1], args[2]);
};