/*
 * jQuery WG Iconize Links plug-in 1.0
 * Copyright (c) 2009 Roberto Lee (webgenerator.nl)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 2009-07-03
 * Rev: 1
 */
 (function($){
     $.fn.extend({
         WG_IconizeLinks: function(options) {
	        var defaults = {
	        	path_icons: 'icon/filetypes/',
	        	icons_image_extension: 'png',
	        	width_icons: '22',
				type: 'left',
				reset_css_parent: true,
				extension_all : '', //f.e. url
				parse_extension_from : 'label', //label or link
				cb: function(){}
	        };

	        var options = $.extend(defaults, options);

			var ParentUlCssEd = 0;

            return $(this).each(function(idx) {// Don't break the chain
				html_elem = this;

				if($(html_elem).is('*'))
				{
					var filename = options.parse_extension_from == "label" ? $(this).html() : $(this).attr('href');
					var filenamechunkarr = filename.split(".")
					var extension = options.extension_all != '' ? options.extension_all :
																							typeof($(this).attr('icon')) != "undefined"
																							?
																							$(this).attr('icon')
																							:
																							filenamechunkarr[filenamechunkarr.length - 1];

					if(options.type == 'left')
					{
				        var css_icons_left = {
							'margin':'0',
							'padding':'0px 0px 0px 23px',
							'display':'block',
							'height': options.width_icons + 'px',
							'background':'transparent url(' + options.path_icons + extension + '.' + options.icons_image_extension + ') no-repeat center left'
				        }
						$(this).css(css_icons_left);
						ParentUlCssEd++;
						options.cb.call();
					}

					if(options.type == 'right')
					{
				        var css_icons_right = {
							'margin':'0',
							'padding':'0p',
							'height': options.width_icons + 'px'
				        }
						$(this).css(css_icons_right).append($('<img/>').attr({
																			'src':	options.path_icons + extension + '.' + options.icons_image_extension,
																			'border' : '0',
																			'style' : 'margin: 0px 0px 0px 5px;'
																		}));
						ParentUlCssEd++;
						options.cb.call();
					}

					if((ParentUlCssEd == 1) && (options.reset_css_parent))
					{
						ResetCSSParent(html_elem);
					}
				}
            });

			function ResetCSSParent(elem)
			{
		        $(elem).parent("li").parent("ul").css({
										'list-style-type':'none',
										'margin': '0px',
										'padding': '0px'
				})
				//$.log("reset");
			}
		}
    });
})(jQuery);


(function($) {

   $.fn.log = function(msg) {
      if (typeof (console) == "undefined") {
         console = { log: function() { } };
      }
      if (console) {
         console.log("%s: %o", msg, this);
      }
      return this;
   }
})(jQuery);

jQuery.log = function(msg) {
      if (typeof (console) == "undefined") {
         console = { log: function() { } };
      }
      if (console) {
         console.log("%s: %o", msg, this);
      }
};
