docs: function(grad) {
  	var defs = svgedit.utilities.findDefs();
  	var existing_grads = $(defs).find("linearGradient, radialGradient");
  	var i = existing_grads.length;
  	var rad_attrs = ['r', 'cx', 'cy', 'fx', 'fy'];
  	while (i--) {
  		var og = existing_grads[i];
  		if (grad.tagName == "linearGradient") {
  			if (grad.getAttribute('x1') != og.getAttribute('x1') ||
  				grad.getAttribute('y1') != og.getAttribute('y1') ||
  				grad.getAttribute('x2') != og.getAttribute('x2') ||
  				grad.getAttribute('y2') != og.getAttribute('y2')) 
  			{
  				continue;
  			}
  		} else {
  			var grad_attrs = $(grad).attr(rad_attrs);
  			var og_attrs = $(og).attr(rad_attrs);
  			
  			var diff = false;
  			$.each(rad_attrs, function(i, attr) {
  				if (grad_attrs[attr] != og_attrs[attr]) {diff = true;}
  			});
  			
  			if (diff) {continue;}
  		}
  		
  		// else could be a duplicate, iterate through stops
  		var stops = grad.getElementsByTagNameNS(NS.SVG, "stop");
  		var ostops = og.getElementsByTagNameNS(NS.SVG, "stop");
  
  		if (stops.length != ostops.length) {
  			continue;
  		}
  
  		var j = stops.length;
  		while (j--) {
  			var stop = stops[j];
  			var ostop = ostops[j];
  
  			if (stop.getAttribute('offset') != ostop.getAttribute('offset') ||
  				stop.getAttribute('stop-opacity') != ostop.getAttribute('stop-opacity') ||
  				stop.getAttribute('stop-color') != ostop.getAttribute('stop-color')) 
  			{
  				break;
  			}
  		}
  
  		if (j == -1) {
  			return og;
  		}
  	} // for each gradient in defs
  
  	return null;
  }