(function(){window.PromptComponents={ImageList:{over:function(){$(this).addClass("active")},out:function(a){if(a.data.currently_active==this){return}$(this).removeClass("active")},click:function(a){a.preventDefault();$(a.data.currently_active).removeClass("active");$(this).addClass("active");if(a.data.currently_active==this){a.data.currently_active=null}else{a.data.currently_active=this}$(a.data).trigger("ImageList.selectionChange",[a.data,a.data.currently_active])},rebind:function(){$("li.card_content dl.image_list").each(function(){this.currently_active=this.currently_active||null;$(this).find("dd").unbind("mouseover",window.PromptComponents.ImageList.over).unbind("mouseout",window.PromptComponents.ImageList.out).bind("mouseover",window.PromptComponents.ImageList.over).bind("mouseout",this,window.PromptComponents.ImageList.out).unbind("click",window.PromptComponents.ImageList.click).bind("click",this,window.PromptComponents.ImageList.click)})},populate:function(c){var f=$(c.row),d=c.data,e=c.preferred_title||"title",b=c.selected||"",a=null;if(c.clear){f.find("dd").remove()}$.each(d,function(){a=$("<dd />").append("<span />").find("span").append("<img />").find("img").attr("src",this.small).end().end().append("<p />").find("p").html(this[e]).end().appendTo(f);window.PromptComponents.ImageList.rebind();if(b==this.small){a.click()}})}},ImageBrowser:{create:function(a){var c=$(a.node),j=a.searches,l=null,b=false;function m(k){c.find("dd.image_search dd.image_search_results").show();g(k)}function g(o){if(b){return}b=true;var p=c.find("dd.image_search dd.image_search_results select").val();p=p.replace("#{keywords}",o);p=p.replace("#{count}","8");c.find("dd.image_search dl.keywords dd.notification").hide();var k=c.find("dd.image_search dd.image_search_results").data("querycache");if(k[p]){c.find("dd.image_search dd.image_search_results select").removeAttr("disabled");b=false;f(k[p]);return}c.find("dd.image_search dd.image_search_results dt span.activity").fadeIn("fast",function(){$.ajax({url:p,dataType:"json",success:function(q){c.find("dd.image_search dd.image_search_results dt span.activity").fadeOut("fast",function(){c.find("dd.image_search dd.image_search_results select").removeAttr("disabled");b=false;if(q.error||(q.length==0)){c.find("dd.image_search dl.keywords dd.notification").show();f([])}else{var r=c.find("dd.image_search dd.image_search_results").data("querycache");r[p]=q;c.find("dd.image_search dd.image_search_results").data("querycache",r);f(q)}})},error:function(){b=false;c.find("dd.image_search dd.image_search_results dt span.activity").fadeOut("fast");c.find("dd.image_search dl.keywords dd.notification").show();f([])}})})}function f(k){l=null;if(c.find("dd.image_search dd.image_search_results dl dd").length>0){c.find("dd.image_search dd.image_search_results dl").find("dd:first").fadeOut("fast",function(){$.each(k,function(){n(this)});$(this).remove()}).end().find("dd:not(:first)").fadeOut("fast",function(){$(this).remove()})}else{$.each(k,function(){n(this)})}}function n(k){$("<dd>").html("<img>").find("img").attr("src",k.thumb).hide().bind("mouseover",h).bind("mouseout",e).load(function(){$(this).fadeIn("fast")}).end().bind("click",i).data("metadata",k).appendTo(c.find("dd.image_search dd.image_search_results dl"))}function h(){$(this).parent().addClass("active")}function e(){if(l==$(this).parent()[0]){return}$(this).parent().removeClass("active")}function i(){if(b){return}if(l){var k=$(l);l=null;k.find("img").mouseout()}l=this;var o=$(this).data("metadata");c.find("dd.image_search").hide().end().find("dd.image_choice").find("img").attr("src",o.thumb).end().find("textarea").val($.toJSON(o)).end().show()}c.find("a").click(function(k){k.preventDefault()}).end().find("dd.image_search").find("a.switch").click(function(){c.find("dd.image_search").hide().end().find("dd.image_upload").show().end()}).end().end().find("dd.image_upload").find("iframe").load(function(){if(!this.contentWindow.UploadedImage){return}var o=this.contentWindow.UploadedImage;c.find("dd.image_upload").hide().end().find("dd.image_choice").find("img").attr("src",o.thumb).end().find("textarea").val($.toJSON(o)).end().show();var k=c.find("dd.image_choice input.user_images").val().split(",");k=$.grep(k,function(p){return p!=""});k.push(o.id);c.find("dd.image_choice input.user_images").val(k.join(","));this.src=this.contentWindow.NewImage}).end().find("a.switch").click(function(){c.find("dd.image_upload").hide().end().find("dd.image_search").show().end()}).end().end().find("dd.image_choice").find("a.switch").click(function(){c.find("dd.image_choice").hide().end().find("dd.image_search").show()});for(var d in j){$("<option />").attr("value",j[d].endpoint).html(j[d].label).appendTo(c.find("dd.image_search dd.image_search_results select"))}if(c.find("dd.image_search dd.image_search_results select option").length==1){c.find("dd.image_search dd.image_search_results").find("select").hide().end().find("span.ing").show().end().find("span.search_provider").html(j[d].label).show()}c.find("dd.image_search dl.keywords :input").keyup(function(k){if(k.which==13){k.preventDefault();c.find("dd.image_search dl.keywords a.form_button").click()}}).end().find("dd.image_search dl.keywords a.form_button").click(function(){var k=jQuery.trim($("dd.image_search dl.keywords :input").val());if(k==""){return}c.find("dd.image_search dd.image_search_results select").blur().attr("disabled",true);m(k)}).end().find("dd.image_search dd.image_search_results select").change(function(k){$(this).blur().attr("disabled",true);c.find("dd.image_search dl.keywords a.form_button").click()});c.find("dd.image_search dd.image_search_results").data("querycache",{})}},SelectableList:{run:function(){$("li.card_content dl.selectable_list").find("dd:not(.other) input[type=radio]").change(function(a,b){$("li.card_content dl.selectable_list dd.other input[type=radio]").trigger("change",b)}).trigger("change",true).end().find("dd.other input[type=radio]").change(function(a,b){$(this).siblings("input[type=text]")[this.checked?"show":"hide"]()}).trigger("change",true)}},OptionalField:{run:function(){$("li.card_content dl.optional_field").each(function(){var a=$(this);a.find("a").click(function(b){b.preventDefault();a.toggleClass("opened").toggleClass("closed");if(a.hasClass("opened")){a.find(":input").focus()}})})}},Notification:{run:function(){$("li.card_content dl.notification").each(function(){var a=$(this);a.find("a").click(function(b){b.preventDefault();a.hide()})})}},TextList:{run:function(){$("ul.text_list").each(function(){var a=$(this);PromptComponents.TextList.rescan(a);a.find("li.add_item").click(function(b){b.preventDefault();a.find("li:first").clone().find(":input").colorize().val("").end().insertBefore(a.find("li.add_item")).find("dd.float_right a.form_button").show().end().find(":input:first").focus().end().find("textarea").forceUpdate();PromptComponents.TextList.rescan(a)}).find(":input").focus(function(){$(this).parents("li.add_item").click()});if(a.find(":input").get().map(function(b){return $(b).val()}).join("")!=""){PromptComponents.TextList.showExtraFields({data:a.find(":input:first")})}})},rescan:function(a){a.find("li.alternate").removeClass("is_alternate").each(function(b){$(this).find("dt").html("<br />"+(b+1)).end().find("dd.float_right a.form_button").unbind("click",PromptComponents.TextList.removeItem).bind("click",$(this),PromptComponents.TextList.removeItem).end().find(":input").unbind("keyup",PromptComponents.TextList.showExtraFields).bind("keyup",$(this),PromptComponents.TextList.showExtraFields)});a.find("li.alternate:odd").addClass("is_alternate");if(a.find("li.alternate").length==1){a.find("li.alternate:first").find("dd.float_right a.form_button").hide()}else{a.find("li.alternate:first").find("dd.float_right a.form_button").show()}Paginator.reloadTitleReplacements()},removeItem:function(b){b.preventDefault();var a=b.data.parents("ul.text_list");if(a.find("li.alternate").length==1){return}b.data.remove();PromptComponents.TextList.rescan(a)},showExtraFields:function(a){$("li.card_content li.secondary_input").show().find("textarea").forceUpdate()}},MapPrompt:{create:function(s){var o=s.use_local||false,B=s.use_directions||false,f=s.canvas,v=s.fields,q=s.metadata,n=s.loader,w=s.error,m=s.search,C=s.shows,D=null,A=null,x=null,y=null,g=null,r=null,z=null,a=null,d=null;Paginator.disableActions();function i(){var G=$.map(v,function(H){return H.val()}).join(" ");if($.trim(G)==""){return}n.fadeIn("fast",function(){if(o){x.execute(G);return}if(B){a=0;d=[];F();return}A.getLatLng(G,k)})}function h(){if(x.results.length==0){n.fadeOut("fast");w.show();return}var G=x.results[0];A.getLatLng(G.addressLines.join(" "),k)}function F(){if(a>v.length-1){c();return}A.getLatLng(v[a].val(),function(G){if(!G){n.fadeOut("fast");w.show();return}d.push(G);a++;F()})}function c(){r.loadFromWaypoints(d,z)}function l(){D.clearOverlays();n.fadeOut("fast",function(){if(y){GEvent.removeListener(g)}if(r.getStatus().code!=200){w.hide();f.show();j();y=new GMarker(d[d.length-1],{icon:new GIcon(G_DEFAULT_ICON,"http://maps.google.com/intl/en_us/mapfiles/marker.png"),draggable:true,bouncy:true});g=GEvent.addListener(y,"dragend",e);D.setCenter(d[d.length-1],12);D.addOverlay(y);D.checkResize();d=null;b();return}d=[];for(var H=0,G=r.getPolyline().getVertexCount();H<G;H++){d.push(r.getPolyline().getVertex(H))}d=u(80,d);w.hide();f.show();j();t();b()})}function k(G){n.fadeOut("fast",function(){if(G){w.hide();f.show();D.checkResize();D.setCenter(G,11);j();if(o){if(y){GEvent.removeListener(g);D.removeOverlay(y)}y=new GMarker(G,{icon:new GIcon(G_DEFAULT_ICON,"http://maps.google.com/intl/en_us/mapfiles/marker.png"),draggable:true,bouncy:true});g=GEvent.addListener(y,"dragend",e);D.addOverlay(y);D.setZoom(16);b()}}else{w.show()}})}function b(){var H={zoom:D.getZoom(),lat:D.getCenter().lat(),lng:D.getCenter().lng(),maptype:D.getCurrentMapType().getName().toLowerCase()};if(y!=null&&y.getLatLng){H.marked_point=y.getLatLng().toUrlValue()}if(r&&d&&d.length&&d.length>0){H.waypoints=[];for(var I=0,G=d.length;I<G;I++){H.waypoints.push(d[I].toUrlValue())}}else{delete H.waypoints}q.val($.toJSON(H))}function u(H,K){if(K.length<H){return K}var J=[];for(var L=0,G=H-1,I=K.length;L<G;L++){J.push(K[Math.floor(L*(I/G))])}return J}function p(H){var G=H.split(",");return new GLatLng(Number(G[0]),Number(G[1]))}function t(){D.clearOverlays();D.addOverlay(new GPolyline(d));D.addOverlay(new GMarker(d[0],{icon:new GIcon(G_DEFAULT_ICON,"http://maps.google.com/intl/en_us/mapfiles/marker_greenA.png")}));D.addOverlay(new GMarker(d[d.length-1],{icon:new GIcon(G_DEFAULT_ICON,"http://maps.google.com/intl/en_us/mapfiles/marker_greenB.png")}))}function j(){$.each(C,function(){this.show().find("textarea").forceUpdate()});Paginator.enableActions();D.checkResize()}function e(){b()}D=new GMap2(f[0],{size:new GSize(505,300)});A=new GClientGeocoder();if(o){x=new google.search.LocalSearch();x.setNoHtmlGeneration();x.setSearchCompleteCallback(this,h)}if(B){r=new GDirections(D);z={getSteps:true}}D.addControl(new GSmallZoomControl());D.addControl(new GMenuMapTypeControl(true));$.each(v,function(){this.keyup(function(G){if(G.which==13){G.preventDefault();i()}})});m.click(function(G){G.preventDefault();i()});if($.trim(q.val())!=""){var E=$.evalJSON(q.val());$.each(C,function(){this.show().find("textarea").forceUpdate()});f.show();D.setCenter(new GLatLng(E.lat,E.lng));$.each(D.getMapTypes(),function(){if(this.getName().toLowerCase()==E.maptype){D.setMapType(this)}});D.setZoom(E.zoom);if(B){i()}if(E.marked_point){y=new GMarker(p(E.marked_point),{icon:new GIcon(G_DEFAULT_ICON,"http://maps.google.com/intl/en_us/mapfiles/marker.png"),draggable:true,bouncy:true});g=GEvent.addListener(y,"dragend",e);D.addOverlay(y)}}GEvent.addListener(D,"moveend",b);GEvent.addListener(D,"zoomend",b);GEvent.addListener(D,"maptypechanged",b);$(window).bind("paginator:previewopened",function(){D.checkResize()});if(r){GEvent.addListener(r,"load",l);GEvent.addListener(r,"error",l)}}},MediaListItem:{create:function(a){}},Poll:{run:function(){$("dl.poll").each(function(){$(this).find("dd.other input[type=text]").keyup(function(){$(this).parent().siblings("dt").find("input.poll_title").val($(this).val());Paginator.reloadTitleReplacements()});$(this).find("dd.other").find("input[type=radio]").change(function(){if(this.checked){$(this).siblings("input[type=text]").show().focus().end().parent().find("span.colon").show()}}).end().end().find("input[type=radio]").change(function(){if(this.checked){$("li.card_content li.secondary_input").show().find("textarea").forceUpdate();var a=$(this).parent().hasClass("other")?$(this).siblings("input[type=text]").val():$(this).siblings("label").text();$(this).parent().siblings("dt").find("input.poll_title").val(a).change()}if(!$(this).parent().hasClass("other")){$(this).parent().siblings("dd.other").find("input[type=text]").hide().end().parent().find("span.colon").hide()}}).change()})}},HelpBubble:{run:function(){$("div.help_bubble").each(function(){var a=$(this);$(this).parents("dl").hover(function(){a.fadeIn("fast")},function(){a.fadeOut("fast")})})}}};$(window).bind("paginator:components",function(){window.PromptComponents.ImageList.rebind();window.PromptComponents.SelectableList.run();window.PromptComponents.Notification.run();window.PromptComponents.TextList.run();window.PromptComponents.Poll.run();window.PromptComponents.HelpBubble.run()})})();