/*
 * @file
 * Javascript called when you create a new synapse.
 */
$('#new_synapse').fadeOut('fast');
$('#synapse_desc').typeahead('setQuery','');
$('#synapse_topic1id').attr('value','0');
$('#synapse_topic2id').attr('value','0');
$('#synapse_grabSynapse').attr('value','null');
// reset the draw synapse positions to false
MetamapsModel.synapseStartCoord = false;
MetamapsModel.synapseEndCoord = false;

var temp1, temp2, temp;	
		 
if ( Mconsole != null) {
    temp1 = Mconsole.graph.getNode(<%= @synapse.topic1.id %>);
    temp2 = Mconsole.graph.getNode(<%= @synapse.topic2.id %>);
    temp2.setData('dim', 25, 'current');
    Mconsole.graph.addAdjacence(temp1, temp2, {});
    temp = Mconsole.graph.getAdjacence(temp1.id, temp2.id);
    temp.setDataset('start', {  
      lineWidth: 0.4,
      alpha: 0.1      
      });
    temp.setDataset('end', {
      lineWidth: 2,
      alpha: 1
    });
    var d = new Array(<%= @synapse.node1_id.to_s() %>, <%= @synapse.node2_id.to_s() %>);
    temp.setDataset('current', {  
      desc: '<%= @synapse.desc %>',  
      showDesc: true, //will be changed by selectEdge
      category: '<%= @synapse.category %>',
      id: '<%= @synapse.id %>',
      userid: '<%= @synapse.user.id %>',
      username: '<%= @synapse.user.name %>',			
      permission: '<%= @synapse.permission %>'
      });
    temp.data.$direction = d;
    Mconsole.fx.animate({
      modes: ['edge-property:lineWidth:alpha'],
      duration: 100,
      onComplete: function() {
        setTimeout(function (){
          temp.setData('showDesc', false);
          Mconsole.plot();
        }, 3000);
      } 
    });
}
else {
  json = <%= @synapse.selfplusnodes_as_json.html_safe %>
  initialize("chaotic");
}
