horus.cspot.documents={
  tip:
    function ( event, context ) {
      var filestore=event.toId(1);
      var file=horus.cspot.documents['doc'+filestore].files[event.toId()];
      var tip=[];

      switch (context) {

      case 'name':
	var pagethumb=horus.cspot.documents.filestore[filestore];
	tip.push(['strong', null, file.filename ]);

	if (pagethumb)
	  tip.push
	    (horus.BR,
	     [ 'img', { src: pagethumb+'/'+file.filename.replace(/\w*$/, 'jpg') } ]);

	if (file.cats) {
	  var cats=[ 'div', { 'class': 'catlist' }, 'in: ' ];

	  for (var c in file.cats)
	    cats.push([ 'em', null, horus.cspot.documents.category[c] ], ', ');

	  cats.pop();
	  tip.push(cats);
	}

	if (file.tags!='')
	  tip.push([ 'div', { 'class': 'tags' }, 'tags: ', [ 'em', null, file.tags ] ]);

	tip.push([ 'div', null, 'click to download' ]);
	break;

      case 'size':
	tip.push(file.size.toGrouped(), ' bytes', horus.BR, file.filetype);
	break;

      case 'title':
	tip=horus.truncatedText(event);

	if (file.description)
	  if (tip)
	    tip=[ tip, horus.BR, horus.BR, file.description ];
	  else
	    tip=file.description;

      }

      return tip;
    },

  select:
    function( control ) {
      var prefix=control.name.replace(/selected$/, '');
      var selected=horus.getselected(control);
      var filter=selected.length>0;
      var uncat=selected.find(0)==null;
      var data=horus.cspot.documents[prefix];

      for (var fileid in data.files) {
	var file=data.files[fileid];
	var hide=filter;

	if (filter)
	  if (!file.cats)
	    hide=uncat;
	  else
	    for (var i=0; i<selected.length; i++)
	      if (file.cats[selected[i]]) {
		hide=false;
		break;
	      }

	horus.swapClass(prefix+'f'+fileid, hide, 'hidden');
      }
    }

};
