// Safari String#replace fix.
// Early versions of SF 2 won't handle "string".replace(/regex/, function(*args) { do_callback; });
// This fixes the String prototype to support that.
if ($.browser.safari && 413 > parseInt($.browser.version.match(/^\w+/), 10)) {
	(function(){
	  var default_replace = String.prototype.replace;
	  String.prototype.replace = function(search,replace){
		// replace is not function
		if(typeof replace != "function"){
			return default_replace.apply(this,arguments)
		}
		var str = "" + this;
		var callback = replace;
		// search string is not RegExp
		if(!(search instanceof RegExp)){
			var idx = str.indexOf(search);
			return (
				idx == -1 ? str :
				default_replace.apply(str,[search,callback(search, idx, str)])
			)
		}
		var reg = search;
		var result = [];
		var lastidx = reg.lastIndex;
		var re;
		while((re = reg.exec(str)) != null){
			var idx  = re.index;
			var args = re.concat(idx, str);
			result.push(
				str.slice(lastidx,idx),
				callback.apply(null,args).toString()
			);
			if(!reg.global){
				lastidx += RegExp.lastMatch.length;
				break
			}else{
				lastidx = reg.lastIndex;
			}
		}
		result.push(str.slice(lastidx));
		return result.join("")
	  }
	})();
}