/*!
 * ExpressionEngine - by EllisLab
 *
 * @package		ExpressionEngine
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2003 - 2011, EllisLab, Inc.
 * @license		http://expressionengine.com/user_guide/license.html
 * @link		http://expressionengine.com
 * @since		Version 2.0
 * @filesource
 */

jQuery(document).ready(function(){function a(){var a=EE.SESS_TIMEOUT-6E4,c=EE.XID_TIMEOUT-6E4,d=a<c?a:c,e=!1,g,h;h=function(){b.ajax({type:"POST",dataType:"json",url:EE.BASE+"&C=login&M=refresh_xid",success:function(a){b("input[name='XID']").val(a.xid);EE.XID=a.xid;setTimeout(h,c)}})};g=function(){var a='<form><div id="logOutWarning" style="text-align:center"><p>'+EE.lang.session_expiring+'</p><label for="username">'+EE.lang.username+'</label>: <input type="text" id="log_backin_username" name="username" value="" style="width:100px" size="35" dir="ltr" id="username" maxlength="32"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="password">'+
EE.lang.password+'</label>: <input class="field" id="log_backin_password" type="password" name="password" value="" style="width:100px" size="32" dir="ltr" id="password" maxlength="32"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" id="submit" name="submit" value="'+EE.lang.login+'" class="submit" /><span id="logInSpinner"></span></div></form>',c;if(e===!0)return(void 0)(e),!1;else setTimeout(void 0,d);b.ee_notice(a,{type:"custom",open:!0,close_on_click:!1});c=b("#logOutWarning");c.find("#log_backin_username").focus();
c.find("input#submit").click(function(){var a=c.find("input#log_backin_username").val(),f=c.find("input#log_backin_password").val(),h=b(this),j=c.find("span#logInSpinner");h.hide();j.html('<img src="'+EE.PATH_CP_GBL_IMG+'loader_blackbg.gif" />');b.ajax({type:"POST",dataType:"json",url:EE.BASE+"&C=login&M=authenticate&is_ajax=true",data:{username:a,password:f,XID:EE.XID},success:function(a){e=!0;if(a.messageType==="success")b("input[name='XID']").val(a.xid),c.slideUp("fast"),b.ee_notice(a.message,
{type:"custom",open:!0}),setTimeout(b.ee_notice.destroy,1600),EE.XID=a.xid,e=!0,clearTimeout(g),setTimeout(g,d);else if(a.messageType==="failure")c.before('<div id="loginCheckFailure">'+a.message+"</div>"),j.hide("fast"),h.css("display","inline");else if(a.messageType==="logout")window.location.href=EE.BASE+"&C=login&M=logout&auto_expire=true"}});return!1})};EE.SESS_TYPE==="c"?setTimeout(h,c):setTimeout(g,d)}var b=jQuery;b(document).bind("ajaxComplete",function(a,b){if(b.status&&+b.status===401)window.location=
EE.BASE+"&"+b.responseText});!1 in document.createElement("input")&&EE.insert_placeholders();b('a[rel="external"]').click(function(){window.open(this.href);return!1});finalLogOutTimer=function(){var f=b('<div id="logOutConfirm">'+EE.lang.session_timeout+" </div>"),c=30,d=c,e,g,h,j;h=function(){window.location=EE.BASE+"&C=login&M=logout&auto_expire=true"};j=function(){if(c<1)return setTimeout(h,0);else c===d&&b(window).bind("unload.logout",h);f.dialog("option","title",EE.lang.logout+" ("+(c--||"...")+
")");e=setTimeout(j,1E3)};g={Cancel:function(){b(this).dialog("close")}};g[EE.lang.logout]=h;f.dialog({autoOpen:!1,resizable:!1,modal:!0,title:EE.lang.logout,position:"center",minHeight:"0",buttons:g,beforeClose:function(){clearTimeout(e);b(window).unbind("unload.logout");c=d;b.ajax({type:"POST",dataType:"json",url:EE.BASE+"&C=login&M=refresh_xid",success:function(c){b("input[name='XID']").val(c.xid);EE.XID=c.xid;b("#logOutWarning").slideUp("fast");a()}})}});b("#logOutConfirm").dialog("open");b(".ui-dialog-buttonpane button:eq(2)").focus();
j();return!1};EE.SESS_TIMEOUT&&a();EE.cp.show_hide_sidebar();EE.cp.display_notices();EE.notepad=function(){var a=b("#notePad"),c=b("#notepad_form"),d=b("#notePadTextEdit"),e=b("#notePadControls"),g=b("#notePadText").removeClass("js_show"),h=g.text(),j=d.val();return{init:function(){j&&g.html(j.replace(/</ig,"&lt;").replace(/>/ig,"&gt;").replace(/\n/ig,"<br />"));a.click(EE.notepad.show);e.find("a.cancel").click(EE.notepad.hide);c.submit(EE.notepad.submit);e.find("input.submit").click(EE.notepad.submit);
d.autoResize()},submit:function(){j=b.trim(d.val());var a=j.replace(/</ig,"&lt;").replace(/>/ig,"&gt;").replace(/\n/ig,"<br />");d.attr("readonly","readonly").css("opacity",0.5);e.find("#notePadSaveIndicator").show();b.post(c.attr("action"),{notepad:j,XID:EE.XID},function(){g.html(a||h).show();d.attr("readonly","").css("opacity",1).hide();e.hide().find("#notePadSaveIndicator").hide()},"json");return!1},show:function(){if(e.is(":visible"))return!1;var a="";g.hide().text()!==h&&(a=g.html().replace(/<br>/ig,
"\n").replace(/&lt;/ig,"<").replace(/&gt;/ig,">"));e.show();d.val(a).show().height(0).focus().trigger("keypress")},hide:function(){g.show();d.hide();e.hide();return!1}}}();EE.notepad.init();EE.cp.accessory_toggle();EE.cp.control_panel_search();b("h4","#quickLinks").click(function(){window.location.href=EE.BASE+"&C=myaccount&M=quicklinks"}).add("#notePad").hover(function(){b(".sidebar_hover_desc",this).show()},function(){b(".sidebar_hover_desc",this).hide()}).css("cursor","pointer");EE.cp.logout_confirm();
b(".js_show").show()});EE.namespace=function(a){var a=a.split("."),b=EE;a[0]==="EE"&&(a=a.slice(1));for(var f=0,c=a.length;f<c;f+=1)typeof b[a[f]]==="undefined"&&(b[a[f]]={}),b=b[a[f]];return b};EE.namespace("EE.cp");
EE.cp.accessory_toggle=function(){$("#accessoryTabs li a").click(function(a){a.preventDefault();var a=$(this).parent("li"),b=$("#"+this.className);a.hasClass("current")?(b.slideUp("fast"),a.removeClass("current")):(a.siblings().hasClass("current")?(b.show().siblings(":not(#accessoryTabs)").hide(),a.siblings().removeClass("current")):b.slideDown("fast"),a.addClass("current"))})};
EE.cp.control_panel_search=function(){var a=$("#search"),b=a.clone(),f=$("#cp_search_form").find(".searchButton"),c;c=function(){var d=$(this).attr("action"),e={cp_search_keywords:$("#cp_search_keywords").val(),XID:EE.XID};$.ajax({url:d,data:e,type:"POST",dataType:"html",beforeSend:function(){f.toggle()},success:function(e){f.toggle();a=a.replaceWith(b);b.html(e);$("#cp_reset_search").click(function(){b=b.replaceWith(a);$("#cp_search_form").submit(c);$("#cp_search_keywords").select();return!1})}});
return!1};$("#cp_search_form").submit(c)};
EE.cp.show_hide_sidebar=function(){var a={revealSidebarLink:"77%",hideSidebarLink:"100%"},b=$("#mainContent"),f=$("#sidebarContent"),c=b.height(),d=f.height(),e;EE.CP_SIDEBAR_STATE==="n"?(b.css("width","100%"),$("#revealSidebarLink").css("display","block"),$("#hideSidebarLink").hide(),f.show(),d=f.height(),f.hide()):(f.hide(),c=b.height(),f.show());e=d>c?d:c;$("#revealSidebarLink, #hideSidebarLink").click(function(){var d=$(this),h=d.siblings("a"),j=this.id==="revealSidebarLink";$.ajax({type:"POST",
dataType:"json",url:EE.BASE+"&C=myaccount&M=update_sidebar_status",data:{XID:EE.XID,show:j},success:function(){}});$("#sideBar").css({position:"absolute","float":"",right:"0"});d.hide();h.css("display","block");f.slideToggle();b.animate({width:a[this.id],height:j?e:c},function(){b.height("");$("#sideBar").css({position:"","float":"right"})});return!1})};
EE.cp.display_notices=function(){var a=["success","notice","error"];$(".message.js_hide").each(function(){for(i in a)$(this).hasClass(a[i])&&$.ee_notice($(this).html(),{type:a[i]})})};
EE.insert_placeholders=function(){$('input[type="text"]').each(function(){if(this.placeholder){var a=$(this),b=this.placeholder,f=a.css("color");a.val()==""&&a.data("user_data","n");a.focus(function(){a.css("color",f);a.val()===b&&(a.val(""),a.data("user_data","y"))}).blur(function(){if(a.val()===""||a.val===b)a.val(b).css("color","#888"),a.data("user_data","n")}).trigger("blur")}})};
EE.cp.logout_confirm=function(){$("#activeUser").one("mouseover",function(){var a=$('<div id="logOutConfirm">'+EE.lang.logout_confirm+" </div>"),b=30,f=b,c,d,e,g;e=function(){$.ajax({url:EE.BASE+"&C=login&M=logout",async:!$.browser.safari});window.location=EE.BASE+"&C=login&M=logout"};g=function(){if(b<1)return setTimeout(e,0);else b===f&&$(window).bind("unload.logout",e);a.dialog("option","title",EE.lang.logout+" ("+(b--||"...")+")");c=setTimeout(g,1E3)};d={Cancel:function(){$(this).dialog("close")}};
d[EE.lang.logout]=e;a.dialog({autoOpen:!1,resizable:!1,modal:!0,title:EE.lang.logout,position:"center",minHeight:"0",buttons:d,beforeClose:function(){clearTimeout(c);$(window).unbind("unload.logout");b=f}});$("a.logOutButton",this).click(function(){$("#logOutConfirm").dialog("open");$(".ui-dialog-buttonpane button:eq(2)").focus();g();return!1})})};
