  /* ---------------------------------
    clb_util.js
  
    $Revision: 1.2 $
    Contains helper functions for collaboration spaces.
  
   
  -------------------------------------
  */ 
  
  /* 
  Returns an image tag displaying the correct icon
  img tag is returned as a string
  param: mt = mime type (no leading or trailing whitespace please)
  param: labels = text strings for files table
  
  notes: .mpp and .vsd are both returning mime type application/octet-stream
  */
  function webx_fileType(mt,labels) {

	var icon="/web/fw/i";
  	switch(mt) {
	  	case "application/msword":
			icon += "/icon-sm-msword.gif";
			alttext = labels.WEBEX_FILES_WORD_DOC;
			break;
	  	case "application/pdf":
	  		icon += "/icon-sm-pdf.gif";
	  		alttext = labels.WEBEX_FILES_PDF;
	  		break;
	  	case "application/photoshop":
	  	case "application/x-photoshop":
	  		icon += "/icon-sm-psd.gif";
	  		alttext = labels.WEBEX_FILES_PHOTOSHOP;
	  		break;
		case "application/vnd.ms-powerpoint":
			icon += "/icon-sm-ppt.gif";
			alttext = labels.WEBEX_FILES_POWERPOINT;
			break;
		case "application/vnd.ms-excel":
		case "application/msexcel":
			icon += "/icon-sm-xls.gif";
			alttext = labels.WEBEX_FILES_EXCEL;
			break;
		case "application/vnd.ms-project": 
			icon += "/icon-sm-mpp.gif";
			alttext = labels.WEBEX_FILES_PROJECT;
			break;
		case "application/vnd.visio":
			icon += "/icon-sm-vsd.gif";
			alttext = labels.WEBEX_FILES_VISIO;
			break;
		case "application/x-zip-compressed":
		case "application/zip":
			icon += "/icon-sm-zip.gif";
			alttext = labels.WEBEX_FILES_ZIP;
			break;
		case "image/bmp":	
	  	case "image/gif":
		case "image/jpg":
	 	case "image/jpeg":
	 	case "image/tiff":
	 	case "image/x-icon":
	 		icon += "/icon-sm-jpeg.gif";
	 		alttext = labels.WEBEX_FILES_IMAGE;
	 		break;
	 	case "application/x-fla":
		case "application/x-flash":
		case "application/x-shockwave-flash":
			icon += "/icon-sm-flash.gif";
			alttext = labels.WEBEX_FILES_FLASH;
		case "audio/basic":
		case "audio/mp4":
		case "audio/vnd.rn-realaudio":
		case "audio/vnd.rn-realmedia":
		case "audio/vnd.rn-realplayer":
		case "audio/vnd.rn-realvideo":
		case "audio/wav":
		case "audio/x-mpeg":
		case "audio/x-ms-wma":
		case "audio/x-pn-realaudio":
			icon += "/icon-sm-audio.gif";
			alttext = labels.WEBEX_FILES_AUDIO;
			break;
		case "video/mp4":
		case "video/quicktime":
		case "video/x-mpeg":
		case "video/x-mpeg2":
		case "video/x-ms-wm":
		case "video/x-ms-wmv":
		case "video/x-msvideo":
			icon += "/icon-sm-video.gif";
			alttext = labels.WEBEX_FILES_VIDEO;
			break;
		default: 
	  		icon += "/icon-sm-unknown.gif";
  			alttext = labels.WEBEX_FILES_UNKNOWN;
  	}
  	
  	var imgtag = "<img src=\""+icon+"\" alt=\""+alttext+"\"/>";
  	return imgtag;
  }
  
  /* Returns the timestamp of the file. 
  Placeholder - will try to push this out to backend logic.
  */
  function webx_fileUploaded(moddate) {
  	return moddate;
  }
  
  /* 
  Reformats the file size to be in the largest unit of measure
  Rounds up to the nearest integer
  param: string fs = files size in bytes
  */
  function webx_fileSize(fs) {
  	var filesize = parseInt(fs);

  	if (filesize < 1024) {
  		filesize += " B";
  	}
  	else if (filesize < 1048576) {
  		filesize = Math.round(filesize / 1024);
  		filesize += " KB";
  	}
	else if (filesize < 1073741824) {
  		filesize = Math.round(filesize / (1024*1024));
  		filesize += " MB";		
	}
  	else {
  		filesize = Math.round(filesize / (1024*1024*1024));
  		filesize += " GB";
  	}
  	return filesize;
  }
  

