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