/** 
 *
 * Author: Ben Cooling
 * 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: '../images/',
				image: 'jpg',
				indent: 20,
				lineHeight: 15,
				margin: 5
		},
		  
			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',
					'text-indent': settings.indent,
					'height': settings.lineHeight,
					'margin': settings.margin
					});
			});
		  
          // returns the jQuery object to allow for chainability.  
          return this;  

    }  
})(jQuery);  
