timely.define(["jquery_timely","ai1ec_config","domReady","external_libs/colorpicker"],function(e,t,n){var r,i=function(n){n.preventDefault(),typeof r=="undefined"&&(r=wp.media.frames.file_frame=wp.media({title:t.choose_image_message,button:{text:t.choose_image_message},multiple:!1}),r.on("select",function(){var t=r.state().get("selection").first().toJSON();e("#ai1ec_category_imag_preview").attr("src",t.url),e("#ai1ec_category_image_url").val(t.url)})),r.open()};e("#tag-color").click(function(){var t=e("#tag-color").offset(),n=t.top+e("#tag-color").height(),r=t.left+1,i=e("<ul></ul>"),o=e('<li style="color: #60a;" class="color-1"></li><li style="color: #807;" class="color-2"></li><li style="color: #920;" class="color-3"></li><li style="color: #a60;" class="color-4"></li><li style="color: #990;" class="color-5"></li><li style="color: #080;" class="color-6"></li><li style="color: #077;" class="color-7"></li><li style="color: #00a;" class="color-8"></li><li style="color: #000;" class="color-9"></li><li style="color: #444;" class="color-10"></li><li style="color: #85e;" class="color-11"></li><li style="color: #d5d;" class="color-12"></li><li style="color: #d43;" class="color-13"></li><li style="color: #d90;" class="color-14"></li><li style="color: #bb0;" class="color-15"></li><li style="color: #2b0;" class="color-16"></li><li style="color: #0ba;" class="color-17"></li><li style="color: #26d;" class="color-18"></li><li style="color: #777;" class="color-19"></li><li style="color: #aaa;" class="color-20"></li><li style="color: #aab;" class="color-21"></li>'),a=e('<li class="select-more-colors">More colors</li>');e(a).ColorPicker({onSubmit:function(t,n,r,s){e("#tag-color-background").css("background-color","#"+n),e("#tag-color-value").val("#"+n),e(s).ColorPickerHide(),i.remove()},onBeforeShow:function(){i.hide(),e(document).unbind("mousedown",u);var t=e("#tag-color-value").val();t=t.length>0?t:"#ffffff",e(this).ColorPickerSetColor(t)}}),o.click(function(){s(e(this).css("color"))!=="#aaaabb"?(e("#tag-color-background").css("background-color",e(this).css("color")),e("#tag-color-value").val(s(e(this).css("color"))),i.remove()):(e("#tag-color-background").css("background-color",""),e("#tag-color-value").val(""),i.remove())}),i.append(o).append(a),i.appendTo("body").css({position:"absolute",top:n+"px",left:r+"px",width:"105px",height:"70px","z-index":1,background:"#fff",border:"1px solid #ccc"}).addClass("colorpicker-list"),e(document).bind("mousedown",{ls:i},u)}),e("#tag-color-value-remove").click(function(){e("#tag-color-background").css("background-color",""),e("#tag-color-value").val("")});var s=function(e){return e=e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/),"#"+o(e[1])+o(e[2])+o(e[3])},o=function(e){return("0"+parseInt(e,10).toString(16)).slice(-2)},u=function(t){a(t.data.ls.get(0),t.target,t.data.ls.get(0))||(e(t.data.ls.get(0)).remove(),e(document).unbind("mousedown",u))},a=function(e,t,n){if(e===t)return!0;if(e.contains)return e.contains(t);if(e.compareDocumentPosition)return!!(e.compareDocumentPosition(t)&16);var r=t.parentNode;while(r&&r!==n){if(r===e)return!0;r=r.parentNode}return!1},f=function(){n(function(){e("#ai1ec_category_image_uploader").click(i);var t=e("#ai1ec_category_imag_preview").attr("src");t&&t.length>0&&e("#ai1ec_category_image_url").val(t)})};return{start:f}});