/** 
 *
 * Adds an icon for anchors with file downloads
 * Enable plugin by calling $(selector).fileIcon()
 * Options include path, image (icon extention), indent, lineHeight
 *
 */

(function($){  
    $.fn.fileIcon = function(options) {  
          
        var  
      defaults = {  
        path: '/resources/_master/js/fileIcons/',
        image: 'jpg',
        indent: 100,
        lineHeight: 102,
        margin: 15
    },
      
      settings = $.extend({}, defaults, options);  
            
      this.each(function() {
        var $this = $(this); 
        var ext = $this.attr("href").split(".").pop().toLowerCase();
            
        switch (ext){
          case 'doc' || 'docx' || 'docm' || 'dotx' || 'dotm':
            var name = 'word';
            break;
          case 'xls' || 'xlsx' || 'xlsm' || 'xltx' || 'xltm' || 'xlsb' || 'xlam':
            var name = 'excel';
            break;          
          case 'ppt' || 'pptx' || 'pptm' || 'potx' || 'potm' || 'ppam' || 'ppsx' || 'ppsm' || 'sldx' || 'sldm' || 'thmx':
            var name = 'powerpoint';
            break;              
          case 'mov':
            var name = 'mov';
            break;
          case 'pdf':
            var name = 'pdf';
            break;
          default: 
            var name = 'file';
        }
                      
        $this.css({
          'display': 'block',
          'backgroundImage': 'url('+ settings.path +'icon_'+ name +'.'+ settings.image +')',
          'backgroundRepeat': 'no-repeat',
          'backgroundPosition': 'left center',
          'text-indent': settings.indent,
          'height': settings.lineHeight,
          'line-height': settings.lineHeight +'px',
          'margin': settings.margin,
          'fontStyle': 'italic',
          'fontSize': '16px',
          'text-decoration': 'none'
          });
      });
      
          // returns the jQuery object to allow for chainability.  
          return this;  

    }  
})(jQuery);  
