/**
 * Colibri Component : sidebar
 **/

if(Colibri)(function(Colibri){
  
Colibri.sidebar = function(XMLPresentation, XMLDocuments) {
  
  this.init(XMLPresentation, XMLDocuments);
};

$.extend(Colibri.sidebar.prototype, {
  shareInstantUrl: '',

  init: function(XMLPresentation, XMLDocuments) {
  
    if(XMLPresentation === undefined || XMLDocuments === undefined)
      return;
  
  	$('.tagQuotes').hide();
  	$('.documentQuotes').hide();
  	$('.tag a').bind("click", function () {
  		$('.tag div:eq(' + $(this).attr('id') + ')').toggle();
  	});
  	$('.document a').bind("click", function () {
  		$('.document div:eq(' + $(this).attr('id') + ')').toggle(); 
  	});
  },

  getNoteContent: function (id) {
	  editor = tinyMCE.activeEditor;
	  if(id == null)
	    editor = tinyMCE.getInstanceById(id);
	  if(editor != null)
	  	return editor.getContent({format : 'html'});
	  else
	    return "";
  },

  scrollToChapter: function (timecode) {
	  theColibri.components.player.setTimecode(timecode);
	  setTimeout("$('#chapterList').scrollTo($('#plan li.currentChapter'), 'y');", 2000);
  },

  sync: function(timecode) {
	  if (document.location.href.slice(document.location.href.lastIndexOf('/') + 1) == document.getElementById('timecodeAtStart').value)
		  this.shareInstantUrl = document.location.href.slice(0, document.location.href.lastIndexOf('/'));
	  else
		  this.shareInstantUrl = document.location.href;
	  
	  $('#shareInstantField').text(this.shareInstantUrl + '/' + Math.round(timecode * 1000));
	  $('#shareInstantField').select();
  }
});

})(Colibri);
