function deletePortlet(a,b){var c=$j("#e_"+a);b||(b=!1),(b||confirm('Are you sure you want to delete the element titled: "'+$j(".portlet_title",c).text()+'"? It will not be recoverable.'))&&$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:{method:"deleteElement",elementID:a},type:"post",dataType:"html",success:function(a){/<script/.test(a)?($j(a).appendTo("body"),$j.jGrowl("There was an error deleting the element.")):c.remove()},error:function(a){$j.jGrowl("There was an error deleting the element. Please try again.")}})}function togglePortlet(a){var b=$j(a),c=b.parent().parent().parent(),d=c.parent().attr("id"),e=c.find(".portlet_content"),f=!0;e.css("display")!="none"?(b.attr({src:"images/toggle_arrow_left.png",alt:"Expand",title:"Expand"}),f=!1):b.attr({src:"images/toggle_arrow_down.png",alt:"Collapse",title:"Collapse"}),e.slideToggle(),f?e.trigger("elementOpened"):e.trigger("elementClosed"),d!="element_preview"&&$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:{method:"toggleElement",elementID:c.attr("id").split("_").pop(),isOpen:f},type:"post",dataType:"html",success:function(a){a.search(/script/)>=0&&$j(a).appendTo("body")}})}function editSettings(a,b){$settingsDiv.dialog("option","title","Settings For "+b),$settingsDiv.html("Loading element settings..."),lastSettingsID=a,$settingsDiv.dialog("open"),$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:{method:"getSettings",elementID:a},type:"post",dataType:"html",success:function(a,b){b.search(/success/)==-1?(lastSettingsID=0,$settingsDiv.dialog("close"),$j.jGrowl("There was an error loading the settings for this element. Please try clicking the pencil again.")):($settingsDiv.html(a),$j("#element_settings_div").tabs(),typeof contentEditorSettings!="undefined"&&$j("textarea.tinymceinst").tinymce(contentEditorSettings))},error:function(a,b){$j.jGrowl("There was an error loading the settings for this element. Please click the pencil and try again.")}}),$elementLibrary&&$j(".addable_element",$elementLibrary).qtip("hide")}function refreshPortlet(a,b){var c=$j("#e_"+a),b=b?b:{};c.parent().attr("id")!="element_preview"&&$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:$j.extend({},{method:"buildElement",id:a,inUnpublished:!!window.topframe&&!!window.topframe.unpublished},b),type:"post",dataType:"html",success:function(a,b){if(a.search(/Error<\/span>/)>0)$j.jGrowl("There was an error refreshing this element. Please try again.");else{var d=$j(a),e=d.find(".data_fs_link_color");e.length&&d.find(".portlet_content a").css("color",e.text()),typeof formatElementStructure!="undefined"&&formatElementStructure(d.filter("div.portlet")),c.replaceWith(d)}},error:function(a,b){$j.jGrowl("There was an error refreshing this element. Please try again.")}})}function loadPortletContent(a,b,c){var d={url:"cf_elements/elementremote.cfc",cache:!1,data:{method:"buildElement",id:a,firstLoad:!1,inUnpublished:!!window.topframe&&!!window.topframe.unpublished},type:"post",dataType:"html",success:function(b,c){var d=$j(b),e=d.find(".data_fs_link_color");e.length&&d.find(".portlet_content a").css("color",e.text()),$j("#c_"+a).html(d)},error:function(a,c){$j.jGrowl("There was an error loading "+b+".")}};a>0?c?$j("#e_"+a).parent().ajaxQueue(d):$j.ajax(d):$j.jGrowl("You are trying to load an invalid element")}function selectLayout(a){var b=$j("#layout_library_selected");$j("#layout_element_"+b.val()).removeClass("layout_library_selected"),$j("#layout_element_"+a).addClass("layout_library_selected"),b.val(a)}function togglePortletMenu(a){$j("#e_"+a+" .portlet_menu").slideToggle()}function toggleCustomizeSettings(a){var b=$j(a);b.val()==0?b.parent().parent().nextAll().hide():b.parent().parent().nextAll().show()}var $settingsDiv=$j("#settings_div"),lastSettingsID=0,$previewDiv=$j("#element_preview"),firstSort=!0;$settingsDiv.dialog({position:"center",modal:!0,draggable:!0,resizable:!1,autoOpen:!1,width:450,close:function(){var a=$j("textarea.tinymceinst",this);a.length&&a.tinymce().remove()},buttons:{Cancel:function(){$j(this).dialog("close")},Save:function(){var a=$j(this),b=$j("#e_"+lastSettingsID),c=$j(":input:not(.system_attr,.ignore_attr)",a).serializeArray(),d=$j("#layout_library_selected"),e={method:"saveSettings",elementID:lastSettingsID,systemAttributes:JSON.stringify($j(".system_attr",a).serializeArray())};if(!fsElements.onSave(e.elementID))return;c.length>0&&(e.otherAttributes=JSON.stringify(c)),d.length>0&&(e.layoutID=d.val(),b=$j("#tabID_"+lastSettingsID)),b.length>0&&$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:e,type:"post",dataType:"html",success:function(a,c){if(a.search(/Error<\/span>/)>0)$j.jGrowl("There was an error saving the settings for this element. Please try clicking the pencil again.");else{var d=$j(a),e=d.find(".data_fs_link_color");e.length&&d.find(".portlet_content a").css("color",e.text()),typeof formatElementStructure!="undefined"&&formatElementStructure(d.filter("div.portlet")),b.hide(),b.replaceWith(d)}},error:function(a,b){$j.jGrowl("There was an error saving the settings for this element. Please click the pencil and try again.")}}),a.dialog("close")}}}),initSortable=function(a,b){var c=$j(".portal_column",b),d=$j("#add_elements_menu");typeof formatElementStructure!="undefined"&&formatElementStructure($j("div.portlet",b)),c.find("div.data_fs_link_color").each(function(a){var b=$j(this);b.parent().find("a").css("color",b.text())}),d.hasClass("selected")&&c.addClass("portal_column_bottom"),c.sortable({opacity:.6,connectWith:".portal_column",dropOnEmpty:!0,distance:3,items:".portlet:not(.docked)",forcePlaceholderSize:!0,handle:".portlet_header",scroll:!0,scrollSensitivity:40,activate:function(a,b){var c=$j(this);firstSort&&$j.browser.msie&&c.sortable("refresh"),c.addClass("portal_column_bottom")},deactivate:function(a,b){firstSort=!1,d.hasClass("selected")||$j(this).removeClass("portal_column_bottom")},start:function(a,b){b.placeholder.height(b.helper.height()),b.helper.width($j(this).width())},update:function(a,b){var c=b.item.prev().attr("id"),d=b.item.attr("data-eid"),e=b.item.parent();if(e.length==0||b.item.hasClass("ie_makes_us_do_this"))return;e=e.attr("id").split("_").pop();if(b.item.hasClass("addable_element")){var f="tempID-"+Math.floor(Math.random()*100),g=b.item.wrap('<div class="new_element"></div>').parent("div"),h={method:"addelement",pageID:pageid,elementID:d,olderSiblingID:-1,parentID:e};g.html("Loading element..."),c!=undefined&&c!=""&&(h.olderSiblingID=c.split("_").pop()),g.load("cf_elements/elementremote.cfc",h,function(){var a=g.find("div.portlet");g.replaceWith(a),typeof formatElementStructure!="undefined"&&formatElementStructure(a)})}else if(b.sender==null){var h={method:"changeElementOrder",elementID:d,parentID:e,siblingID:-1};c!=undefined&&(h.siblingID=c.split("_").pop()),$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:h,type:"post",dataType:"html",success:function(a){/<script/.test(a)&&($j(a).appendTo("body"),$j.jGrowl("You must be logged in to move elements"))},error:function(a){$j.jGrowl("There was an error moving the element. The changes will not be saved.")}})}},tolerance:"intersect"})},$previewDiv.dialog({position:"center",modal:!0,draggable:!0,resizable:!0,autoOpen:!1,title:"Preview",width:400,minHeight:350,buttons:{Cancel:function(){$j(this).dialog("close")},Add:function(){var a=$j(this).children("div").attr("data-eid"),b=$j(".portal_column:visible:first"),c=$j('<div class="addable_element" id="temp_'+a+'">Loading element...</div>');b.append(c),c.load("cf_elements/elementremote.cfc",{method:"addelement",pageID:pageid,elementID:a,parentID:b.attr("id").split("_").pop()},function(){c.replaceWith(c.html()),b.sortable("refresh")}),$previewDiv.dialog("close")}}}),$j("div.portlet").live("mouseover",function(){$j(this).find("div.portlet_actions_container").show()}),$j("div.portlet").live("mouseout",function(){$j(this).find("div.portlet_actions_container").hide()}),$j(".addable_element").live("click",function(){var a=$j(this);$previewDiv.html("Loading..."),$previewDiv.dialog("open"),$j.ajax({url:"cf_elements/elementremote.cfc",cache:!1,data:{method:"buildElement",id:a.attr("id").split("_").pop(),firstLoad:!0,includeDescription:!0,inUnpublished:!!window.topframe&&!!window.topframe.unpublished},type:"post",dataType:"html",success:function(a,b){var c=$j(a),d=c.find(".data_fs_link_color");d.length&&c.find(".portlet_content a").css("color",d.text()),$previewDiv.html(c)},error:function(b,c){$j.jGrowl("There was an error loading the preview for "+a.text()+".")}}),$elementLibrary&&$j(".addable_element",$elementLibrary).qtip("hide")}),function(a){a.fn.ajaxQueue=function(b){var c=b.complete,d=a(this);b.complete=function(){c&&c.apply(this,arguments),d.dequeue("ajax")},d.queue("ajax",function(){a.ajax(b)})}}(jQuery),$j("#portal_tabs").length==0&&$j(function(){$j(".portal_column").dequeue("ajax")})
