/*!
 * 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,j=a<c?a:c,e=!1,f,g;g=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(g,c)}})};f=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 d(e),!1;else setTimeout(d,j);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(),d=c.find("input#log_backin_password").val(),h=b(this),g=c.find("span#logInSpinner");h.hide();g.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:d,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(f),setTimeout(f,j);else if(a.messageType==="failure")c.before('<div id="loginCheckFailure">'+a.message+"</div>"),g.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(g,c):setTimeout(f,j)}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});var d=function(){var d=b('<div id="logOutConfirm">'+EE.lang.session_timeout+" </div>"),c=30,j=c,e,f,g,k;g=function(){window.location=EE.BASE+"&C=login&M=logout&auto_expire=true"};k=function(){if(c<1)return setTimeout(g,0);else c===j&&b(window).bind("unload.logout",g);d.dialog("option","title",EE.lang.logout+" ("+(c--||"...")+")");e=
setTimeout(k,1E3)};f={Cancel:function(){b(this).dialog("close")}};f[EE.lang.logout]=g;d.dialog({autoOpen:!1,resizable:!1,modal:!0,title:EE.lang.logout,position:"center",minHeight:"0",buttons:f,beforeClose:function(){clearTimeout(e);b(window).unbind("unload.logout");c=j;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();
k();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"),f=b("#notePadText").removeClass("js_show"),g=f.text(),k=d.val();return{init:function(){k&&f.html(k.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(){k=b.trim(d.val());var a=k.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:k,XID:EE.XID},function(){f.html(a||g).show();d.attr("readonly",!1).css("opacity",1).hide();e.hide().find("#notePadSaveIndicator").hide()},"json");return!1},show:function(){if(e.is(":visible"))return!1;var a="";f.hide().text()!==g&&(a=f.html().replace(/<br>/ig,
"\n").replace(/&lt;/ig,"<").replace(/&gt;/ig,">"));e.show();d.val(a).show().height(0).focus().trigger("keypress")},hide:function(){f.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 d=0,h=a.length;d<h;d+=1)typeof b[a[d]]==="undefined"&&(b[a[d]]={}),b=b[a[d]];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(),d=$("#cp_search_form").find(".searchButton"),h;h=function(){var c=$(this).attr("action"),j={cp_search_keywords:$("#cp_search_keywords").val(),XID:EE.XID};$.ajax({url:c,data:j,type:"POST",dataType:"html",beforeSend:function(){d.toggle()},success:function(c){d.toggle();a=a.replaceWith(b);b.html(c);$("#cp_reset_search").click(function(){b=b.replaceWith(a);$("#cp_search_form").submit(h);$("#cp_search_keywords").select();return!1})}});
return!1};$("#cp_search_form").submit(h)};
EE.cp.show_hide_sidebar=function(){var a={revealSidebarLink:"77%",hideSidebarLink:"100%"},b=$("#mainContent"),d=$("#sidebarContent"),h=b.height(),c=d.height(),j;EE.CP_SIDEBAR_STATE==="n"?(b.css("width","100%"),$("#revealSidebarLink").css("display","block"),$("#hideSidebarLink").hide(),d.show(),c=d.height(),d.hide()):(d.hide(),h=b.height(),d.show());j=c>h?c:h;$("#revealSidebarLink, #hideSidebarLink").click(function(){var c=$(this),f=c.siblings("a"),g=this.id==="revealSidebarLink";$.ajax({type:"POST",
dataType:"json",url:EE.BASE+"&C=myaccount&M=update_sidebar_status",data:{XID:EE.XID,show:g},success:function(){}});$("#sideBar").css({position:"absolute","float":"",right:"0"});c.hide();f.css("display","block");d.slideToggle();b.animate({width:a[this.id],height:g?j:h},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,d=a.css("color");a.val()==""&&a.data("user_data","n");a.focus(function(){a.css("color",d);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,d=b,h,c,j,e;j=function(){$.ajax({url:EE.BASE+"&C=login&M=logout",async:!$.browser.safari});window.location=EE.BASE+"&C=login&M=logout"};e=function(){if(b<1)return setTimeout(j,0);else b===d&&$(window).bind("unload.logout",j);a.dialog("option","title",EE.lang.logout+" ("+(b--||"...")+")");h=setTimeout(e,1E3)};c={Cancel:function(){$(this).dialog("close")}};
c[EE.lang.logout]=j;a.dialog({autoOpen:!1,resizable:!1,modal:!0,title:EE.lang.logout,position:"center",minHeight:"0",buttons:c,beforeClose:function(){clearTimeout(h);$(window).unbind("unload.logout");b=d}});$("a.logOutButton",this).click(function(){$("#logOutConfirm").dialog("open");$(".ui-dialog-buttonpane button:eq(2)").focus();e();return!1})})};
