$(function(){$.manager=function(pagePluralName,pController,cController,connController,count,preview,options){var permission=false;extArray=cController.split("/");if(pagePluralName=="Users"){extName="user";var addUrl="settings";}else{extName=extArray[0];var addUrl="add";}
permission=hasPermission(extName);if(permission){if(pagePluralName=="Users"){parentController=$.controller.array(pController);}else if(pagePluralName=="Records"){parentController=$.controller.array(pController,{order:"position"});}else if(pagePluralName=="Life Stream"){parentController=$.controller.array(pController,{user_id:$.session.user.id,order:"name"});}else{parentController=$.controller.array(pController,{order:"position",user_id:$.session.user.id});}
if(options.published=="NO"){var defaults={user_id:$.session.user.id}}else if(pagePluralName=="Users"||pagePluralName=="Records"){var defaults={master:[parentController,connController]}}else if(pagePluralName=="Life Stream"){var defaults={master:[parentController,connController],order:"created_at DESC"}}else{var defaults={master:[parentController,connController],user_id:$.session.user.id}}
var opts=$.extend(defaults,options);opts=$.extend({paginate:{overlap:1,selector:"#nav-updater"}},opts);childController=$.controller.array(cController,opts);$.retrieveFilter=function(){if($("#filter-input").val()!=""){childController.conditions.filter=$("#filter-input").val();opts.filter=$("#filter-input").val();childController.retrieve();}else{delete opts.filter;delete childController.conditions.filter;childController.retrieve();}}
var timer;$("#filter-input").keyup(function(e){clearTimeout(timer);timer=setTimeout("$.retrieveFilter()",700);});$(".ti_next").addClass("disabled").click(function(){return false;});$(".ti_prev").addClass("disabled").click(function(){return false;});$(".ti_item_start").text("0");$(".ti_item_end").text("0");$(parentController).observe("selection",function(){if(options.published!="NO"){if($(parentController).valueForKeyPath("selection.name")){$("#content-replace h1:first").html($(parentController).valueForKeyPath("selection.name")+"<span></span>");$("#content-replace a:first, .cat_sort div.empty a.nothing-yet").live("click",function(){$(this).attr("href","http://demo.firerift.com/app/"+extName+"/"+addUrl+"?"+connController+"="+$(parentController).valueForKeyPath("selection.id"));});}else if(pagePluralName=="Life Stream"){$("#content-replace h1:first").html("Life Stream<span></span>");}else{$("#content-replace h1:first").html("<span></span>");}}});$(childController).observe("contents",function(){arrayId='';if(pagePluralName=="Life Stream"){$("#content-replace h1 span").text(childController.count+" Items");}else{$("#content-replace h1 span").text(childController.count+" "+pagePluralName);}});$.fn.makesef=function(from){str=$(from).val();ex=/\$|,|@|#|~|`|\%|\*|\^|\.|\&|\(|\)|\+|\=|\[|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\\\|\!|\$|\//g;str=str.replace(ex,"");ex=/^\s+|\s+$/g;str=str.replace(ex,"");ex=/\s+/g;str=str.replace(ex,"-");str=str.toLowerCase();$(this).val(str);};var newId=0;var totalNewFields=0;function addNewField(){$("#add_new_field li.form-item").clone().attr("id","n_"+newId).appendTo("#dropdown-holder div.dropdown-panel div.dropdown-body ul.data_fields");$("#n_"+newId).find("div.select-gen").css("width","100px");$("#n_"+newId).find("div.select-gen select").css("width","100px");$("#n_"+newId).find("div.select-gen .type-select-update").css("width","67px");$("#n_"+newId).find("input[name=name]").attr("name","name+n+"+newId);$("#n_"+newId).find("input[name=db_name]").attr("name","db_name+n+"+newId);$("#n_"+newId).find("input[name=id]").remove();$("#n_"+newId).find("select[name=type]").attr("name","type+n+"+newId);$("#n_"+newId).find("span.type-select-update").attr("id","type_n_"+newId);var newId2=newId;$("#dropdown-holder input[name=name+n+"+newId2+"]").live("keyup",function(){$("#dropdown-holder input[name=db_name+n+"+newId2+"]").makesef($(this));});$("#n_"+newId).find("a.delete").click(function(){$("#n_"+newId2).remove();totalNewFields--;return false;});totalNewFields++;newId++;}
var errStr="";var positionAry=new Array();function getFieldDataStr(data_set_id){var dataStr="";var newDataStr="";var i=0;var i2=0;var sPos=0;var submitId=new Array();var posAry=new Object();if(positionAry.length>0){for(i2=0;i2<positionAry.length;i2++){posAry[String(positionAry[i2])]=i2;}}
$("#dropdown-holder form").find(".data_field").each(function(){submitId[$(this).attr("id")]=i;i++;sPos=i;});$("#dropdown-holder form").find(".field_name,.field_db_name,.field_type,.field_id").each(function(){var name=$(this).attr("name");var nameAry=name.split("+");var value=$(this).val();if(value==null||value=="null"||value==""){switch(nameAry[0]){case"name":errStr="Field Name";break;case"db_name":errStr="Field Database Name";break;case"type":errStr="Field Type";break;}
return false;}
var id;if(nameAry[1]=="n"){id=nameAry[2];newDataStr=newDataStr+id+"["+nameAry[0]+"]="+value+"&";if(nameAry[0]=="name"){if(i2!=0){newDataStr+=id+"[position]="+posAry["n_"+id]+"&";}else{newDataStr+=id+"[position]="+sPos+"&";sPos++;}
if(data_set_id!=""){newDataStr+=id+"[data_set_id]="+data_set_id+"&";}}}else{id=nameAry[1];dataStr+=submitId[id]+"["+nameAry[0]+"]="+value+"&";if(nameAry[0]=="name"&&i2!=0){dataStr+=submitId[id]+"[position]="+posAry[id]+"&";}}});var dataArr=new Array();dataArr[0]=dataStr;dataArr[1]=newDataStr;return dataArr;}
if(options.published!="NO"){$("div.categories-link").format(function(elem,data){$(elem).children("a.show-entries").click(function(){childController.conditions.offset=0;$("#filter-input").val("");delete opts.filter;delete childController.conditions.filter;delete childController.conditions.lifestream_id;$(parentController).valueForKey("selection",data);$("div.categories-link").removeClass("active");$(elem).addClass("active");return false;});$(elem).find("span a").click(function(){$("#dropdown-holder").html($("#category_dropdown").html());$("div.select-gen").each(function(){if($(this).hasClass("full")){$(this).find("span:first").css("width",$(this).width()-35);$(this).find("select").css("width",$(this).width());}else{$(this).find("span:first").css("width",$(this).find("select").width()-23);}
if($(this).hasClass("inline")){$(this).css("width",$(this).find("select").width()+10);}});$("#dropdown-holder input.btn-delete").addClass("fromCat").show();if(data.service){var dd_title=data.service;if(dd_title=="gallery_category"){dd_title="Gallery Category";}
$("#dropdown-holder .dropdown-title div:first").prepend("Edit "+dd_title+" ").append(" <em>Stream ID# "+data.id+"</em>");var form=data.service.toLowerCase();if(form=="gallery_category"){form="galleries";}
if(form=="twitter"){$("#dropdown-holder div.twitter-filter-holder input").remove();$("#dropdown-holder div.twitter-filter-holder div.form-item").html("<h1 style=\"display:inline;\">Username:</h1> <b>"+data.username+"</b><br /><br /><h1 style=\"display:inline;\">Fileter Keyword(s):</h1> <b>"+data.life_filter+"</b>");$("#dropdown-holder div.twitter-filter-holder").show();}
if(form=="youtube"||form=="vimeo"){$("#dropdown-holder input[name=username]").parent().before("<hr />").removeClass("remove-this").html("<h1 style=\"display:inline;\">Username:</h1> <b>"+data.username+"</b>");$("#dropdown-holder input[name=username]").parent().show();}
if(form=="other"){$("#dropdown-holder input[name=feed_url]").parent().before("<hr />").removeClass("remove-this").html("<h1 style=\"display:inline;\">Feed URL:</h1> <b>"+data.feed_url+"</b>");$("#dropdown-holder input[name=feed_url]").parent().show();}
if(form=="twitter"||form=="flickr"||form=="youtube"||form=="vimeo"){form="external";}
$("#dropdown-holder a.dd-"+form+"-btn").click();$("#dropdown-holder div.dropdown-tabbar").remove();$("#dropdown-holder .remove-this").remove();$("#dropdown-holder form.dd-"+form+"-tab div.form-item:first").css("paddingTop","20px");$("#dropdown-holder form.dd-"+form+"-tab").find("input[name=name]").val(data.name);$("#dropdown-holder form.dd-"+form+"-tab").find("input[name=life_filter]").val(data.life_filter);$("#dropdown-holder form.dd-"+form+"-tab").find("input[name="+form+"_published]").val(data.published);if(data.published=="YES"){$("#dropdown-holder form.dd-"+form+"-tab").find("#"+form+"_published").removeClass("check-off").addClass("check-on");}
$("#dropdown-holder form.dd-"+form+"-tab").append("<input type='hidden' name='id' value='"+data.id+"'/>");}else{$("#dropdown-holder .dropdown-title div:first").prepend("Edit ").append(" <em>ID# "+data.id+"</em>");$("#dropdown-holder form:first").find("input[name=name]").val(data.name);$("#dropdown-holder .sef_title").text(data.sef_title);$("input[name=id]").val(data.id);$("input[name=shared]").val(data.shared);}
if(data.shared=="YES"){$("#dropdown-holder a.checkbox").removeClass("check-off");$("#dropdown-holder a.checkbox").addClass("check-on");}
if(pagePluralName!="Records"){$("#dropdown-holder").show("slide",{direction:"up"},500,function(){$("#dropdown-holder input[type=text]:first").focus();});}else if(pagePluralName=="Records"){$.getJSON("http://demo.firerift.com/api/data/data_fields/?order=position&data_set_id="+data.id,function(data){$(data.items).each(function(){var that=this;$("#add_new_field li.form-item").clone().attr("id",this.id).addClass("data_field").appendTo("#dropdown-holder div.dropdown-panel div.dropdown-body ul.data_fields");$("#"+this.id).find("input[name=name]").attr("name","name+"+this.id).val(this.name);$("#"+this.id).find("input[name=db_name]").attr("name","db_name+"+this.id).val(this.db_name);$("#"+this.id).find("input[name=id]").attr("name","id+"+this.id).val(this.id);$("#"+this.id).find("select[name=type]").attr("name","type+"+this.id).val(this.type);$("#"+this.id).find("span.type-select-update").attr("id","type_"+this.id).text($("#"+this.id).find("select[name=type+"+this.id+"] option:selected").text());$("#dropdown-holder input[name=name+"+this.id+"]").live("keyup",function(){$("#dropdown-holder input[name=db_name+"+that.id+"]").makesef($(this));});$("#"+this.id).find("a.delete").click(function(){$.ajax({url:"http://demo.firerift.com/api/data/data_fields?id="+that.id,type:"DELETE",success:function(){$("#"+that.id).remove();},error:function(){errorAlert();}});return false;});});$("#dropdown-holder").show("slide",{direction:"up"},500,function(){$("#dropdown-holder input[type=text]:first").focus();});});positionAry.length=0;$("ul.data_fields").sortable({items:"li.data",revert:true,axis:"y",helper:"clone",opacity:0.6,handle:".handle_dd",tolerance:"pointer",update:function(event,ui){positionAry=$(this).sortable('toArray');},error:function(){errorAlert();}});newId=0;totalNewFields=0;$("#dropdown-holder div.btn-addfield a").click(function(){addNewField();return false;});}
$("#dropdown-holder form").submit(function(event){var parentStr=$(this).serialize();if(pagePluralName=="Records"){parentStr="name="+$("#dropdown-holder form input[name=name]").val()+"&id="+$("#dropdown-holder form input[name=id]").val();var dataStr=getFieldDataStr($("#dropdown-holder form input[name=id]").val());}
if(errStr!=""){errStr="Please fill in and/or select the "+errStr+" field(s).";$("#alert-holder").html(tips[1]);$("#alert-holder div").text(errStr);$("#alert-holder").fadeIn("normal").fadeTo(4500,1).fadeOut("normal");errStr="";return false;}
$.ajax({url:"http://demo.firerift.com/api/"+pController,data:parentStr,type:"PUT",dataType:"json",success:function(data){if(pagePluralName=="Records"){if(dataStr[0]!=""){$.ajax({url:"http://demo.firerift.com/api/data/data_fields",data:dataStr[0],type:"PUT",success:function(){if(dataStr[1]==""){$("#dropdown-holder").hide("slide",{direction:"up"},500);parentController.retrieve();}},error:function(){errorAlert();}});}
if(dataStr[1]!=""){$.ajax({url:"http://demo.firerift.com/api/data/data_fields",data:dataStr[1],type:"POST",success:function(){$("#dropdown-holder").hide("slide",{direction:"up"},500);parentController.retrieve();},error:function(){errorAlert();}});}}else{$("#dropdown-holder").hide("slide",{direction:"up"},500);parentController.retrieve();}},error:function(data){if(data.status==400){$("#alert-holder").html(tips[1]);$("#alert-holder div").text("The Title you entered is already in use. Please use another.");$("#alert-holder").fadeIn("normal").fadeTo(4500,1).fadeOut("normal");}else{errorAlert();}}});return false;});$("#dropdown-holder input.btn-delete").click(function(){$("#dropdown-holder").html($("#delete_confirmation").html());if($(this).hasClass("fromCat")){$("#dropdown-holder span.manNote").remove();$("#dropdown-holder span.catNote").show();}
$("#dropdown-holder .btn-delete").click(function(event){parentController.destroy(data.id);$("#dropdown-holder").hide("slide",{direction:"up"},500);return false;});$("#dropdown-holder").show("slide",{direction:"up"},500);return false;});return false;});var theName=data.name;if(theName.length>24){theName=theName.slice(0,24)+"...";}
$(elem).children("a.show-entries").text(theName);if(data==$(parentController).valueForKey("selection")){$(elem).addClass("active");}});}
$("div.manager-item div h2").format(function(elem,data){(pagePluralName=="Users")?$(elem).text("#"+data.user[0].id):$(elem).text("#"+data.id);});$("div.manager-item-image img").format(function(elem,data){if((data.cover_pic!=null&&data.cover_pic!="NULL")||(data.thumbnail&&data.thumbnail!="")){if(data.cover_pic){var theImage="http://demo.firerift.com/upload/media/frt_"+data.cover_pic;}else if(data.thumbnail){var theImage=data.thumbnail;}
$(elem).hide().load(function(){$(this).imgCenter();}).attr("src",theImage);}else{$(elem).parent().hide();}});var arrayId='';$("div.manager-item div h1 a").format(function(elem,data){switch(pagePluralName){case"Users":editLink="http://demo.firerift.com/app/"+extName+"/settings?id="+data.user[0].id;break;case"Records":editLink="http://demo.firerift.com/app/"+extName+"/edit?id="+data.id+"&data_set_id="+$(parentController).valueForKey("selection").id;break;case"Life Stream":if(data.service=="blogs"){editLink="http://demo.firerift.com/app/blog/edit?id="+data.id;}else if(data.service=="galleries"){editLink="http://demo.firerift.com/app/gallery/edit?id="+data.gallery_id;}else if(data.service=="gallery_category"){editLink="http://demo.firerift.com/app/gallery/edit?id="+data.id;}else{editLink=data.title_link;$(elem).attr("target","blank");}
break;default:editLink="http://demo.firerift.com/app/"+extName+"/edit?id="+data.id;break;}
$(elem).attr("href",editLink);var text=data.title;if(pagePluralName=="Users"){text=data.user[0].name}
if(pagePluralName=="Records"){if(arrayId!=''){text=data[arrayId];}else{var i=0;for(key in data){i++;if(i==4){arrayId=key;text=data[key];break;}}}}
if(text){if(pagePluralName=="Life Stream"){if($(elem).parent().parent().find(".manager-item-image:visible").length){if(text.length>45){text=text.slice(0,45)+"...";}}else{if(text.length>60){text=text.slice(0,60)+"...";}}}else{if(text.length>24){text=text.slice(0,24)+"...";}}}
$(elem).text(text);});var aTag=$(".manager-item-opts a").clone();$(".manager-item-opts").format(function(elem,data){var fn=$.formatDate("M j, Y | g:i A","created_at",true);fn(elem,data);$(elem).append($(aTag).clone());$(elem).children(".lb-preview").attr("href","http://demo.firerift.com/app/core/shared/preview"+preview+"?id="+data.id);$(elem).children(".lb-preview").fancybox({'zoomSpeedIn':300,'zoomSpeedOut':300,'frameWidth':700,'frameHeight':400,'overlayShow':true});$(elem).children(".unpublish").attr("title","Unpublish "+data.title);$(elem).children(".unpublish").click(function(event){$(elem).parent().parent().fadeOut(1000);$.ajax({url:"http://demo.firerift.com/api/"+cController+"?id="+data.id+"&published=NO",type:"PUT",success:function(){childController.retrieve();},error:function(){errorAlert();}});return false;});$(elem).children(".publish").attr("title","Publish "+data.title);$(elem).children(".publish").click(function(event){$(elem).parent().parent().fadeOut(1000);$.ajax({url:"http://demo.firerift.com/api/"+cController+"?id="+data.id+"&published=YES",type:"PUT",success:function(){childController.retrieve();},error:function(){errorAlert();}});return false;});if(data.user){if(data.user[0].suspended=="YES"){$(elem).children(".unsuspend").attr("title","Unsuspend "+data.user[0].name).show();$(elem).children(".unsuspend").click(function(event){$.ajax({url:"http://demo.firerift.com/api/auth/users?id="+data.user[0].id+"&suspended=NO",type:"PUT",success:function(){childController.retrieve();},error:function(){errorAlert();}});return false;});}else{$(elem).children(".suspend").attr("title","Suspend "+data.user[0].name).show();$(elem).children(".suspend").click(function(event){$.ajax({url:"http://demo.firerift.com/api/auth/users?id="+data.user[0].id+"&suspended=YES",type:"PUT",success:function(){childController.retrieve();},error:function(){errorAlert();}});return false;});}
if(data.user[0].id==$.session.user.id){$(elem).remove();}}
if(pagePluralName=="Life Stream"){if(data.service=="blogs"||data.service=="galleries"||data.service=="gallery_category"){$(elem).children(".delete_item").hide();}}
var title;(pagePluralName=="Users")?title=data.user[0].name:title=data.title;if(title&&title.length>45){title=title.slice(0,45)+"...";}
$(elem).children(".delete_item").attr("title","Delete "+title);$(elem).children(".delete_item").click(function(event){$("#dropdown-holder").html($("#delete_confirmation").html());$("#dropdown-holder .btn-delete").click(function(event){var url;var type="DELETE";switch(pagePluralName){case"Users":url="http://demo.firerift.com/api/auth/users?id="+data.user[0].id;break;case"Records":url="http://demo.firerift.com/api/data/records?id="+data.id;break;case"Life Stream":type="PUT";url="http://demo.firerift.com/api/"+cController+"?deleted=YES&id="+data.id;break;default:url="http://demo.firerift.com/api/"+cController+"?id="+data.id;}
$.ajax({url:url,type:type,success:function(){childController.retrieve();},error:function(){errorAlert();}});$("#dropdown-holder").hide("slide",{direction:"up"},500);return false;});$("#dropdown-holder").show("slide",{direction:"up"},500);return false;});});if(options.published=="NO"){$("div.manager-categories div").template("",{success:function(){if($("div.manager-categories div.categories-link").length<=0){if(extName=="data"&&($.session.user.role=="Admin"||$.session.user.role=="Developer")){$(".cat_sort").html('<div class="empty"><a href="" class="nothing-yet cat">Click to Add a Category</a></div>');}else if(extName!="data"){$(".cat_sort").html('<div class="empty"><a href="" class="nothing-yet cat">Click to Add a Category</a></div>');}
$("#content-replace a:first").hide();}else{if(extName=="data"&&($.session.user.role!="Admin"&&$.session.user.role!="Developer")){$(".categories-opts div, #category_dropdown, .categories-link span").remove();}
$("#content-replace a:first").show();$("a.show-entries:first").click();}}});}else if(pagePluralName=="Life Stream"){$("div.ti_lifestreams").template(parentController,{success:function(){$("a.lifestream").click(function(){childController.conditions.lifestream_id=$.session.user.id;var data=$("div.ti_lifestreams").data("template");$(parentController).valueForKey("selection",data);$("div.categories-link").removeClass("active");$(this).parent("div.categories-link").addClass("active");return false;});if($("div.ti_lifestreams div.categories-link").length<=0){$(".cat_sort").html('<div class="empty"><a href="" class="nothing-yet cat">Add a Stream to your Life Stream</a></div>');}else{$("a.show-entries:first").click();}}});}else{$("div.manager-categories div").template(parentController,{success:function(){if($("div.manager-categories div.categories-link").length<=0){if(extName=="data"&&($.session.user.role=="Admin"||$.session.user.role=="Developer")){$(".cat_sort").html('<div class="empty"><a href="" class="nothing-yet cat">Click to Add a Category</a></div>');}else if(extName!="data"){$(".cat_sort").html('<div class="empty"><a href="" class="nothing-yet cat">Click to Add a Category</a></div>');}
$("#content-replace a:first").hide();}else{if(extName=="data"&&($.session.user.role!="Admin"&&$.session.user.role!="Developer")){$(".categories-opts div, #category_dropdown, .categories-link span, #add_new_field").remove();}
$("#content-replace a:first").show();$("a.show-entries:first").click();}}});}
var nothingYet="Add Something to this Category";if(extName=="gallery"){nothingYet="Add a Gallery to this Category";}else if(extName=="blog"){nothingYet="Add an Entry to this Category";}else if(extName=="data"){nothingYet="Add a Record to this Data Set";}else if(extName=="user"){nothingYet="Add a User to this Role";}else if(extName=="page"){nothingYet="Add a Page Snip to this Category";}else if(extName=="lifestream"){nothingYet="Add a Stream to your Life Stream";}
var dumbCheck=0;$(".cat_sort").template(childController,{success:function(){if($("#filter-input").val()!=""){$("div.handle").hide();}else{$("div.handle").show();}
$(".cat_sort").show();if(dumbCheck!=0&&$(".cat_sort li").length<=0&&$("#filter-input").val()==""&&$.url.segment($.url.segment()-1)!="shared"&&$.url.segment($.url.segment()-1)!="drafts"){if(extName=="lifestream"){$(".cat_sort").append('<div class="empty"><a href="" class="nothing-yet cat">'+nothingYet+'</a></div>');}else{$(".cat_sort").append('<div class="empty"><a href="" class="nothing-yet">'+nothingYet+'</a></div>');}}
dumbCheck=1;}});$("#addcats a, .cat_sort div.empty a.nothing-yet.cat").live("click",function(){$("div#dropdown-holder").html($("div#category_dropdown").html());if(pagePluralName=="Records"){$("div#dropdown-holder").html($("div#category_dropdown").html());newId=0;totalNewFields=0;addNewField();positionAry.length=0;$("ul.data_fields").sortable({items:"li.data",revert:true,axis:"y",helper:"clone",opacity:0.6,handle:".handle_dd",tolerance:"pointer",update:function(event,ui){positionAry=$(this).sortable('toArray');},error:function(){errorAlert();}});$("#dropdown-holder div.btn-addfield a").click(function(){addNewField();return false;});}
$("#dropdown-holder .dropdown-title div:first").prepend("Add ");$("#dropdown-holder input[name=id]").remove();$("div#dropdown-holder form").submit(function(event){var parentStr=$(this).serialize();if(pagePluralName=="Records"){parentStr="name="+$("div#dropdown-holder form input[name=name]").val();var dataStr=getFieldDataStr("");}
if(errStr!=""){errStr="Please fill in and/or select the "+errStr+" field(s).";$("div#alert-holder").html(tips[1]);$("div#alert-holder div").text(errStr);$("div#alert-holder").fadeIn("normal").fadeTo(4500,1).fadeOut("normal");errStr="";return false;}
$.ajax({url:"http://demo.firerift.com/api/"+pController,data:parentStr,dataType:"json",type:"POST",success:function(data){if(pagePluralName=="Records"){for(var i=0;i<totalNewFields;i++){dataStr[1]=dataStr[1]+i+"[data_set_id]="+data.items[0].id+"&";}
$.ajax({url:"http://demo.firerift.com/api/data/data_fields",data:dataStr[1],type:"POST",success:function(){$("div#dropdown-holder").hide("slide",{direction:"up"},500);parentController.retrieve();},error:function(){errorAlert();}});}else{$("div#dropdown-holder").hide("slide",{direction:"up"},500);parentController.retrieve();}},error:function(data){if(data.status==400){$("div#alert-holder").html(tips[1]);$("div#alert-holder div").text("The Title you entered is already in use. Please use another.");$("div#alert-holder").fadeIn("normal").fadeTo(4500,1).fadeOut("normal");}else{errorAlert();}}});return false;});$("div#dropdown-holder").show("slide",{direction:"up"},500,function(){$("#dropdown-holder input[type=text]:first").focus();});return false;});$("div#sortcats a").click(function(){$("div.manager-categories").addClass("ui-sortable");$(".categories-link span").addClass("handle");$(".categories-link span a").css({"visibility":"hidden"});$("div#sortcats").hide();$("div#finishedsorting").show();$("div.manager-categories div").rearrange(parentController,{autoRetrieve:false,revert:true,helper:"clone",opacity:0.6,handle:".handle",axis:"y",tolerance:"pointer",complete:function(){$("div#alert-loading-holder").stop(true,true).fadeOut("normal");},error:function(){errorAlert();}});return false;});$("div#finishedsorting a").click(function(){$("div.manager-categories").removeClass("ui-sortable");$(".categories-link span").removeClass("handle");$(".categories-link span a").css({"visibility":"visible"});$("div#sortcats").show();$("div#finishedsorting").hide();$("div.manager-categories div").rearrange("destroy");return false;});$(".cat_sort").rearrange(childController,{revert:true,axis:"y",helper:"clone",opacity:0.6,handle:".handle",tolerance:"pointer",error:function(){errorAlert();}});}}});