/*
 * per gestire l'external interface
 * riporta i client swf presenti in pagina e ne richiama le
 * varie funzioni
 */
//var EXT_INT_MODE = "editing";

var JSInterface = {
	
  load: function() {
	this.mode = EXT_INT_MODE;
	
	// instanzio il mio client handler:
	this.clientHandler = ClientHandler.load();
	
  },
  
  addFlashClient: function(client)
  {
  	this.clientHandler.addClient(client)
  },
  
  getSessionData:function(callbackClient, vars )
  {
  	
	
	
	new Ajax.Request('/' + current_project_name + '/selector/get_session_data?vars=' + vars,
 	{
  	asynchronous:true, evalScripts:true,
    onSuccess:function(response){
		this.JSInterface.clientHandler.call(callbackClient,"getSessionDataCallback", response.responseText.toJSON());
	},
    onError:function(request){ }
	})
	
  },
  
  
  getResource:function(callbackClient, id )
  {
  	
	
	
	new Ajax.Request('/' + current_project_name + '/resource/show_xml?id=' + id,
 	{
  	asynchronous:true, evalScripts:true,
    onSuccess:function(response){
		this.JSInterface.clientHandler.call(callbackClient,"getResourceCallback", response.responseText.toJSON());
	},
    onError:function(request){ }
	})
	
  },
  getDestinations:function(callbackClient, id )
  {
  	
	new Ajax.Request('/' + current_project_name + '/resource/show_destinations_xml?id=' + id,
 	{
  	asynchronous:true, evalScripts:true,
    onSuccess:function(response){
		this.JSInterface.clientHandler.call(callbackClient,"getDestinationsCallback", response.responseText.toJSON());
	},
    onError:function(request){ }
	})
	
  },
  getSources:function(callbackClient, id )
  {

	new Ajax.Request('/' + current_project_name + '/resource/show_sources_xml?id=' + id,
 	{
  	asynchronous:true, evalScripts:true,
    onSuccess:function(response){
		this.JSInterface.clientHandler.call(callbackClient,"getSourcesCallback", response.responseText.toJSON());
	},
    onError:function(request){ }
	})
	
  },
  getRelatedByTags:function(callbackClient, id )
  {

	new Ajax.Request('/' + current_project_name + '/resource/show_related_by_tags_xml?id=' + id,
 	{
  	asynchronous:true, evalScripts:true,
    onSuccess:function(response){
		this.JSInterface.clientHandler.call(callbackClient,"getRelatedByTagsCallback", response.responseText.toJSON());
	},
    onError:function(request){ }
	})
	
  }
  
};

JSInterface.load();