
(function($){$.whileAsync=function(opts)
{var delay=Math.abs(opts.delay)||10,bulk=isNaN(opts.bulk)?500:Math.abs(opts.bulk),test=opts.test||function(){return true;},loop=opts.loop||function(){},end=opts.end||function(){};(function(){var t=false,begin=new Date();while(t=test())
{loop();if(bulk===0||(new Date()-begin)>bulk)
{break;}}
if(t)
{setTimeout(arguments.callee,delay);}
else
{end();}})();}
$.eachAsync=function(array,opts)
{var i=0,l=array.length,loop=opts.loop||function(){};$.whileAsync($.extend(opts,{test:function(){return i<l;},loop:function()
{var val=array[i];return loop.call(val,i++,val);}}));}
$.fn.eachAsync=function(opts)
{$.eachAsync(this,opts);return this;}})(jQuery);(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}
return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}
if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}
r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};(function($){$.fn.suggestions=function(param,param2){function processKey(key){switch(key){case 40:if(conf._data.div.is(':visible')){highlightResult('next',true);}else{updateSuggestions(false);}
break;case 38:if(conf._data.div.is(':visible')){highlightResult('prev',true);}
break;case 27:conf._data.div.hide();restoreText();cancelPendingSuggestions();break;default:updateSuggestions(true);}}
function restoreText(){conf._data.textbox.val(conf._data.prevText);}
function updateSuggestions(delayed){if(conf._data.timerID!=null)
clearTimeout(conf._data.timerID);if(delayed)
setTimeout(doUpdateSuggestions,conf.delay);else
doUpdateSuggestions();}
function doUpdateSuggestions(){if(conf._data.textbox.val()==conf._data.prevText)
return;conf._data.prevText=conf._data.textbox.val();conf.fetch.call(conf._data.textbox,conf._data.textbox.val());}
function suggestionsChanged(){conf._data.div.show();updateSuggestionsTable();fitContainer();trimResultText();}
function cancelPendingSuggestions(){if(conf._data.timerID!=null)
clearTimeout(conf._data.timerID);conf.cancelPending.call(this);}
function updateSuggestionsTable(){if(conf.suggestions.length==0){conf._data.div.hide();return;}
var table=conf._data.div.children('table');table.empty();for(var i=0;i<conf.suggestions.length;i++){var td=$('<td />').append($('<span />').text(conf.suggestions[i]));$('<tr />').addClass('os-suggest-result').attr('rel',i).data('text',conf.suggestions[i]).append(td).appendTo(table);}}
function fitContainer(){if(conf._data.div.is(':hidden'))
return;var availableHeight=$('body').height()-(Math.round(conf._data.div.offset().top)-
$(document).scrollTop())-20;var rowHeight=conf._data.div.find('tr').outerHeight();var numRows=Math.floor(availableHeight/rowHeight);if(numRows<2&&conf.suggestions.length>=2)
numRows=2;if(numRows>conf.maxRows)
numRows=conf.maxRows;var tableHeight=conf._data.div.find('table').outerHeight();if(numRows*rowHeight<tableHeight){conf._data.div.height(numRows*rowHeight);conf._data.visibleResults=numRows;}else{conf._data.div.height(tableHeight);conf._data.visibleResults=conf.suggestions.length;}}
function trimResultText(){if(conf._data.div.is(':hidden'))
return;var maxWidth=0;var spans=conf._data.div.find('span').get();for(var i=0;i<spans.length;i++)
if($(spans[i]).outerWidth()>maxWidth)
maxWidth=$(spans[i]).outerWidth();var fix=0;if(conf._data.visibleResults<conf.suggestions.length)
fix=20;if(fix<4)
fix=4;maxWidth+=fix;var textBoxWidth=conf._data.textbox.outerWidth();var factor=maxWidth/textBoxWidth;if(factor>conf.maxGrowFactor)
factor=conf.maxGrowFactor;if(factor<1)
factor=1;var newWidth=Math.round(textBoxWidth*factor);if(newWidth!=conf._data.div.outerWidth())
conf._data.div.animate({width:newWidth},conf.animationDuration);newWidth-=fix;conf._data.div.find('tr').each(function(){var span=$(this).find('span');if(span.outerWidth()>newWidth){var span=$(this).find('span');span.text(span.text()+'...');while(span.outerWidth()>newWidth&&span.text().length>3){span.text(span.text().substring(0,span.text().length-4)+'...');}
$(this).attr('title',$(this).data('text'));}});}
function getHighlightedRow(){return conf._data.div.find('.os-suggest-result-hl');}
function highlightResult(result,updateTextbox){var selected=getHighlightedRow();if(!result.get||selected.get(0)!=result.get(0)){if(result=='prev'){result=selected.prev();}else if(result=='next'){if(selected.size()==0)
result=conf._data.div.find('tr:first');else{result=selected.next();if(result.size()==0)
result=selected;}}
selected.removeClass('os-suggest-result-hl');result.addClass('os-suggest-result-hl');}
if(updateTextbox){if(result.size()==0)
restoreText();else
conf._data.textbox.val(result.data('text'));}
if(result.size()>0&&conf._data.visibleResults<conf.suggestions.length){var rowHeight=result.outerHeight();var first=conf._data.div.scrollTop()/rowHeight;var last=first+conf._data.visibleResults-1;var to=result.attr('rel');if(to<first)
conf._data.div.scrollTop(to*rowHeight);else if(result.attr('rel')>last)
conf._data.div.scrollTop((to-conf._data.visibleResults+1)*rowHeight);}}
function init(){if(typeof conf!='object'||typeof conf._data!='undefined')
return;if(typeof conf.animationDuration=='undefined')
conf.animationDuration=200;if(typeof conf.cancelPending!='function')
conf.cancelPending=function(){};if(typeof conf.delay=='undefined')
conf.delay=250;if(typeof conf.maxGrowFactor=='undefined')
conf.maxGrowFactor=2;if(typeof conf.maxRows=='undefined')
conf.maxRows=7;if(typeof conf.submitOnClick=='undefined')
conf.submitOnClick=false;if(typeof conf.suggestions!='object')
conf.suggestions=[];conf._data={};conf._data.textbox=$(this);conf._data.timerID=null;conf._data.prevText=null;conf._data.visibleResults=0;conf._data.mouseDownOn=$([]);conf._data.div=$('<div />').addClass('os-suggest').css({top:Math.round($(this).offset().top)+this.offsetHeight,left:Math.round($(this).offset().left),width:$(this).outerWidth()}).hide().appendTo($('body'));$('<table />').addClass('os-suggest-results').width($(this).outerWidth()).appendTo(conf._data.div);$(this).attr('autocomplete','off').keydown(function(e){conf._data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;conf._data.keypressed_count=0;}).keypress(function(){conf._data.keypressed_count++;processKey(conf._data.keypressed);}).keyup(function(){if(conf._data.keypressed_count==0)
processKey(conf._data.keypressed);}).blur(function(){if(conf._data.mouseDownOn.size()>0)
return;conf._data.div.hide();cancelPendingSuggestions();});conf._data.div.mouseover(function(e){var tr=$(e.target).closest('.os-suggest tr');highlightResult(tr,false);}).mousedown(function(e){var tr=$(e.target).closest('.os-suggest tr');conf._data.mouseDownOn=tr;}).mouseup(function(e){var tr=$(e.target).closest('.os-suggest tr');var other=conf._data.mouseDownOn;conf._data.mouseDownOn=$([]);if(tr.get(0)!=other.get(0))
return;highlightResult(tr,true);conf._data.div.hide();conf._data.textbox.focus();if(conf.submitOnClick)
conf._data.textbox.closest('form').submit();});}
function getProperty(prop){return(param[0]=='_'?undefined:conf[param]);}
function setProperty(prop,value){if(typeof conf=='undefined'){$(this).data('suggestionsConfiguration',{});conf=$(this).data('suggestionsConfiguration');}
if(prop[0]!='_')
conf[prop]=value;if(prop=='suggestions'&&conf._data)
suggestionsChanged();}
var conf=$(this).data('suggestionsConfiguration');if(typeof param=='object')
return this.each(function(){for(key in param){setProperty.call(this,key,param[key]);}});else if(typeof param=='string'){if(typeof param2!='undefined')
return this.each(function(){setProperty(param,param2);});else
return getProperty(param);}else if(typeof param!='undefined')
return this;return this.each(init);};})(jQuery);(function($){$.fn.extend({getSelection:function(){var e=this.jquery?this[0]:this;var retval='';if(e.style.display=='none'){}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();retval=range.text;}else if(e.selectionStart||e.selectionStart=='0'){retval=e.value.substring(e.selectionStart,e.selectionEnd);}
return retval;},encapsulateSelection:function(pre,peri,post,ownline,replace){function checkSelectedText(){if(!selText){selText=peri;isSample=true;}else if(replace){selText=peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' '}}
var e=this.jquery?this[0]:this;var selText=$(this).getSelection();var isSample=false;if(e.style.display=='none'){}else if(document.selection&&document.selection.createRange){if(document.documentElement&&document.documentElement.scrollTop){var winScroll=document.documentElement.scrollTop;}else if(document.body){var winScroll=document.body.scrollTop;}
$(this).focus();var range=document.selection.createRange();if(ownline&&range.moveStart){var range2=document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range3.text!=""){pre="\n"+pre;}
var range3=document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}}
checkSelectedText();range.text=pre+selText+post;if(isSample&&range.moveStart){if(window.opera){post=post.replace(/\n/g,'');}
range.moveStart('character',-post.length-selText.length);range.moveEnd('character',-post.length);}
range.select();if(document.documentElement&&document.documentElement.scrollTop){document.documentElement.scrollTop=winScroll}else if(document.body){document.body.scrollTop=winScroll;}}else if(e.selectionStart||e.selectionStart=='0'){var textScroll=e.scrollTop;$(this).focus();var startPos=e.selectionStart;var endPos=e.selectionEnd;checkSelectedText();if(ownline){if(startPos!=0&&e.value.charAt(startPos-1)!="\n"){pre="\n"+pre;}
if(e.value.charAt(endPos)!="\n"){post+="\n";}}
e.value=e.value.substring(0,startPos)+pre+selText+post+e.value.substring(endPos,e.value.length);if(isSample){e.selectionStart=startPos+pre.length;e.selectionEnd=startPos+pre.length+selText.length;}else{e.selectionStart=startPos+pre.length+selText.length+post.length;e.selectionEnd=e.selectionStart;}
e.scrollTop=textScroll;}
$(this).trigger('encapsulateSelection',[pre,peri,post,ownline,replace]);},getCaretPosition:function(){function getCaret(e){var caretPos=0;if($.browser.msie){var postFinished=false;var periFinished=false;var postFinished=false;var preText,rawPreText,periText;var rawPeriText,postText,rawPostText;var periRange=document.selection.createRange().duplicate();var preRange=document.body.createTextRange();preRange.moveToElementText(e);preRange.setEndPoint("EndToStart",periRange);var postRange=document.body.createTextRange();postRange.moveToElementText(e);postRange.setEndPoint("StartToEnd",periRange);preText=rawPreText=preRange.text;periText=rawPeriText=periRange.text;postText=rawPostText=postRange.text;do{if(!postFinished){if(preRange.compareEndPoints("StartToEnd",preRange)==0){postFinished=true;}else{preRange.moveEnd("character",-1)
if(preRange.text==preText){rawPreText+="\r\n";}else{postFinished=true;}}}
if(!periFinished){if(periRange.compareEndPoints("StartToEnd",periRange)==0){periFinished=true;}else{periRange.moveEnd("character",-1)
if(periRange.text==periText){rawPeriText+="\r\n";}else{periFinished=true;}}}
if(!postFinished){if(postRange.compareEndPoints("StartToEnd",postRange)==0){postFinished=true;}else{postRange.moveEnd("character",-1)
if(postRange.text==postText){rawPostText+="\r\n";}else{postFinished=true;}}}}while((!postFinished||!periFinished||!postFinished));caretPos=rawPreText.replace(/\r\n/g,"\n").length;}else if(e.selectionStart||e.selectionStart=='0'){caretPos=e.selectionStart;}
return caretPos;}
return getCaret(this.get(0));},scrollToCaretPosition:function(pos){function getLineLength(e){return Math.floor(e.scrollWidth/($.os.name=='linux'?7:8));}
function getCaretScrollPosition(e){var text=e.value.replace(/\r/g,"");var caret=$(e).getCaretPosition();var lineLength=getLineLength(e);var row=0;var charInLine=0;var lastSpaceInLine=0;for(i=0;i<caret;i++){charInLine++;if(text.charAt(i)==" "){lastSpaceInLine=charInLine;}else if(text.charAt(i)=="\n"){lastSpaceInLine=0;charInLine=0;row++;}
if(charInLine>lineLength){if(lastSpaceInLine>0){charInLine=charInLine-lastSpaceInLine;lastSpaceInLine=0;row++;}}}
var nextSpace=0;for(j=caret;j<caret+lineLength;j++){if(text.charAt(j)==" "||text.charAt(j)=="\n"||caret==text.length){nextSpace=j;break;}}
if(nextSpace>lineLength&&caret<=lineLength){charInLine=caret-lastSpaceInLine;row++;}
return($.os.name=='mac'?13:($.os.name=='linux'?15:16))*row;}
return this.each(function(){$(this).focus();if(this.selectionStart||this.selectionStart=='0'){this.selectionStart=pos;this.selectionEnd=pos;$(this).scrollTop(getCaretScrollPosition(this));}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();var oldPos=$(this).getCaretPosition();var goBack=false;if(oldPos==pos){pos++;goBack=true;}
range.moveToElementText(this);range.collapse();range.move('character',pos);range.select();this.scrollTop+=range.offsetTop;if(goBack){range.move('character',-1);range.select();}}
$(this).trigger('scrollToPosition');});}});})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'supportedBrowsers':{'ltr':{'msie':7,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1},'rtl':{'msie':8,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1}},imgPath:wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/'};$.wikiEditor.isSupportKnown=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers;})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.isSupported=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers&&$.browser.versionNumber>=supportedBrowsers[$.browser.name];})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.autoMsg=function(object,property){if(typeof property=='object'){for(i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
if(property in object){return object[property];}else if(property+'Msg'in object){return gM(object[property+'Msg']);}else{return'';}};$.fn.wikiEditor=function(){var context=$(this).data('context');if(typeof context!=='undefined'){arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,arguments[0]==undefined?{}:arguments[0]);}
return $(this).data('context',context);}
return $(this);}
var instance=$.wikiEditor.instances.length;context={'$textarea':$(this),'modules':{},'data':{},'instance':instance};$.wikiEditor.instances[instance]=$(this);$(this).wrap($('<div></div>').addClass('wikiEditor-ui').attr('id','wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom').attr('id','wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text').attr('id','wikiEditor-ui-text'));context.$ui=$(this).parent().parent().parent();context.$ui.after($('<div style="clear:both;"></div>'));context.$ui.prepend($('<div></div>').addClass('wikiEditor-ui-top').attr('id','wikiEditor-ui-top'));context.api={addModule:function(context,data){function callModuleApi(module,call,data){if(module in $.wikiEditor.modules&&'fn'in $.wikiEditor.modules[module]&&call in $.wikiEditor.modules[module].fn){$.wikiEditor.modules[module].fn[call](context,data);}}
if(typeof data=='string'){callModuleApi(data,'create',{});}else if(typeof data=='object'){for(module in data){if(typeof module=='string'){callModuleApi(module,'create',data[module]);}}}}};for(module in $.wikiEditor.modules){if('api'in $.wikiEditor.modules[module]){for(call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}}
if(arguments.length>0&&typeof arguments[0]=='object'){context.api.addModule(context,arguments[0]);}
context.$textarea.scrollToCaretPosition(0);return $(this).data('context',context);};})(jQuery);RegExp.escape=function(s){return s.replace(/([.*+?^${}()|\/\\[\]])/g,'\\$1');};(function($){$.wikiEditor.modules.dialogs={api:{addDialog:function(context,data){$.wikiEditor.modules.dialogs.fn.create(context,{'modules':data})},openDialog:function(context,data){if(data.dialog in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[data.dialog].id).dialog('open');}},closeDialog:function(context,data){if(data.dialog in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[data.dialog].id).dialog('close');}}},fn:{create:function(context,config){for(module in config){$.wikiEditor.modules.dialogs.modules[module]=config[module];}
for(module in $.wikiEditor.modules.dialogs.modules){var module=$.wikiEditor.modules.dialogs.modules[module];if($('#'+module.id).size()==0){var configuration=module.dialog;configuration.bgiframe=true;configuration.autoOpen=false;configuration.modal=true;configuration.title=$.wikiEditor.autoMsg(module,'title');for(msg in configuration.buttons){configuration.buttons[gM(msg)]=configuration.buttons[msg];delete configuration.buttons[msg];}
$('<div /> ').attr('id',module.id).html(module.html).data('context',context).appendTo($('body')).each(module.init).dialog(configuration);}}}},'modules':{}};})(jQuery);(function($){$.wikiEditor.modules.toolbar={api:{addToToolbar:function(context,data){for(type in data){switch(type){case'sections':var $sections=context.modules.$toolbar.find('div.sections');var $tabs=context.modules.$toolbar.find('div.tabs');for(section in data[type]){if(section=='main'){context.modules.$toolbar.prepend($.wikiEditor.modules.toolbar.fn.buildSection(context,section,data[type][section]));continue;}
$sections.append($.wikiEditor.modules.toolbar.fn.buildSection(context,section,data[type][section]));$tabs.append($.wikiEditor.modules.toolbar.fn.buildTab(context,section,data[type][section]));}
break;case'groups':if(!('section'in data)){continue;}
var $section=context.modules.$toolbar.find('div[rel='+data.section+'].section');for(group in data[type]){$section.append($.wikiEditor.modules.toolbar.fn.buildGroup(context,group,data[type][group]));}
break;case'tools':if(!('section'in data&&'group'in data)){continue;}
var $group=context.modules.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.group+'].group');for(tool in data[type]){$group.append($.wikiEditor.modules.toolbar.fn.buildTool(context,tool,data[type][tool]));}
break;case'pages':if(!('section'in data)){continue;}
var $pages=context.modules.$toolbar.find('div[rel='+data.section+'].section .pages');var $index=context.modules.$toolbar.find('div[rel='+data.section+'].section .index');for(page in data[type]){$pages.append($.wikiEditor.modules.toolbar.fn.buildPage(context,page,data[type][page]));$index.append($.wikiEditor.modules.toolbar.fn.buildBookmark(context,page,data[type][page]));}
$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,page,$pages,$index);break;case'rows':if(!('section'in data&&'page'in data)){continue;}
var $table=context.modules.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page table');for(row in data[type]){$table.append($.wikiEditor.modules.toolbar.fn.buildRow(context,data[type][row]));}
break;case'characters':if(!('section'in data&&'page'in data)){continue;}
$characters=context.modules.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page div');var actions=$characters.data('actions');for(character in data[type]){$characters.append($($.wikiEditor.modules.toolbar.fn.buildCharacter(data[type][character],actions)).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')]);return false;}));}
break;default:break;}}},removeFromToolbar:function(context,data){if(typeof data.section=='string'){var tab='div.tabs span[rel='+data.section+'].tab';var target='div[rel='+data.section+'].section';if(typeof data.group=='string'){target+=' div[rel='+data.group+'].group';if(typeof data.tool=='string'){target+=' div[rel='+data.tool+'].tool';}}else if(typeof data.page=='string'){var index=target+' div.index div[rel='+data.page+']';target+=' div.pages div[rel='+data.page+'].page';if(typeof data.character=='string'){target+=' a[rel='+data.character+']';}else if(typeof data.row=='number'){target+=' table tr:not(:has(th)):eq('+data.row+')';}else{context.modules.$toolbar.find(index).remove();$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,null,context.modules.$toolbar.find(target),context.modules.$toolbar.find(index));}}else{context.modules.$toolbar.find(tab).remove();}
context.modules.$toolbar.find(target).remove();}}},fn:{create:function(context,config){if('$toolbar'in context.modules){return;}
context.modules.$toolbar=$('<div />').addClass('wikiEditor-ui-toolbar').attr('id','wikiEditor-ui-toolbar');$.wikiEditor.modules.toolbar.fn.build(context,config);context.$ui.find('.wikiEditor-ui-top').append(context.modules.$toolbar);},doAction:function(context,action,source){if($.trackAction!=undefined&&source.closest('.wikiEditor-ui-toolbar').size()){var rels=[];var step=source;var i=0;while(!step.hasClass('wikiEditor-ui-toolbar')){if(i>25){break;}
i++;var rel=step.attr('rel');if(rel){rels.push(step.attr('rel'));}
step=step.parent();}
rels.reverse();var id=rels.join('.');$.trackAction(id);}
switch(action.type){case'replace':case'encapsulate':var parts={'pre':'','peri':'','post':''};for(part in parts){if(part+'Msg'in action.options){parts[part]=gM(action.options[part+'Msg'],(action.options[part]||null));}else{parts[part]=(action.options[part]||'')}}
context.$textarea.encapsulateSelection(parts.pre,parts.peri,parts.post,action.options.ownline,action.type=='replace');break;case'callback':if(typeof action.execute=='function'){action.execute(context);}
break;case'dialog':context.$textarea.wikiEditor('openDialog',{'dialog':action.module});break;default:break;}},buildGroup:function(context,id,group){var $group=$('<div />').attr({'class':'group group-'+id,'rel':id});var label=$.wikiEditor.autoMsg(group,'label');if(label){$group.append('<div class="label">'+label+'</div>')}
if('tools'in group){for(tool in group.tools){$group.append($.wikiEditor.modules.toolbar.fn.buildTool(context,tool,group.tools[tool]));}}
return $group;},buildTool:function(context,id,tool){if('filters'in tool){for(filter in tool.filters){if($(tool.filters[filter]).size()==0){return null;}}}
var label=$.wikiEditor.autoMsg(tool,'label');switch(tool.type){case'button':var src=tool.icon;if(src.indexOf('http://')!==0&&src.indexOf('https://')!==0){src=$.wikiEditor.imgPath+'toolbar/'+src;}
$button=$('<img />').attr({'src':src,'width':22,'height':22,'alt':label,'title':label,'rel':id,'class':'tool tool-button'});if('action'in tool){$button.data('action',tool.action).data('context',context).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));return false;});}
return $button;case'select':var $select=$('<div />').attr({'rel':id,'class':'tool tool-select'}).click(function(){var $options=$(this).find('.options');$options.animate({'opacity':'toggle'},'fast');});$options=$('<div />').addClass('options');if('list'in tool){for(option in tool.list){var optionLabel=$.wikiEditor.autoMsg(tool.list[option],'label');$options.append($('<a />').data('action',tool.list[option].action).data('context',context).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));}).text(optionLabel).addClass('option').attr('rel',option));}}
$select.append($('<div />').addClass('menu').append($options));$select.append($('<div />').addClass('label').text(label));return $select;default:return null;}},buildBookmark:function(context,id,page){var label=$.wikiEditor.autoMsg(page,'label');return $('<div />').text(label).attr('rel',id).data('context',context).click(function(){$(this).parent().parent().find('.page').hide();$(this).parent().parent().find('.page-'+$(this).attr('rel')).show();$(this).siblings().removeClass('current');$(this).addClass('current');var section=$(this).parent().parent().attr('rel');if($.trackAction!=undefined){$.trackAction(section+'.'+$(this).attr('rel'));}
$.cookie('wikiEditor-'+$(this).data('context').instance+'-booklet-'+section+'-page',$(this).attr('rel'));});},buildPage:function(context,id,page){var $page=$('<div />').attr({'class':'page page-'+id,'rel':id});switch(page.layout){case'table':$page.addClass('page-table');var html='<table cellpadding=0 cellspacing=0 '+'border=0 width="100%" class="table table-"'+id+'">';if('headings'in page){html+=$.wikiEditor.modules.toolbar.fn.buildHeading(context,page.headings)}
if('rows'in page){for(row in page.rows){html+=$.wikiEditor.modules.toolbar.fn.buildRow(context,page.rows[row])}}
$page.html(html);break;case'characters':$page.addClass('page-characters');$characters=$('<div />').data('context',context).data('actions',{});var actions=$characters.data('actions');if('language'in page){$characters.attr('lang',page.language);}
if('direction'in page){$characters.attr('dir',page.direction);}
if('characters'in page){var html='';for(character in page.characters){html+=$.wikiEditor.modules.toolbar.fn.buildCharacter(page.characters[character],actions);}
$characters.html(html).children().click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')],$(this));return false;});}
$page.append($characters);break;}
return $page;},buildHeading:function(context,headings){var html='<tr>';for(heading in headings){html+='<th>'+$.wikiEditor.autoMsg(headings[heading],['html','text'])+'</th>';}
return html;},buildRow:function(context,row){var html='<tr>';for(cell in row){html+='<td class="cell cell-'+cell+'" valign="top"><span>'+
$.wikiEditor.autoMsg(row[cell],['html','text'])+'</span></td>';}
html+='</tr>';return html;},buildCharacter:function(character,actions){if(typeof character=='string'){character={'label':character,'action':{'type':'encapsulate','options':{'pre':character}}};}else if(0 in character&&1 in character){character={'label':character[0],'action':{'type':'encapsulate','options':{'pre':character[1]}}};}
if('action'in character&&'label'in character){actions[character.label]=character.action;return'<a rel="'+character.label+'" href="#">'+character.label+'</a>';}},buildTab:function(context,id,section){var selected=$.cookie('wikiEditor-'+context.instance+'-toolbar-section');return $('<span />').attr({'class':'tab tab-'+id,'rel':id}).append($('<a />').addClass(selected==id?'current':null).attr('href','#').text($.wikiEditor.autoMsg(section,'label')).data('context',context).click(function(){var $section=$(this).data('context').$ui.find('.section-'+$(this).parent().attr('rel'));$(this).blur();var show=$section.css('display')=='none';$section.parent().children().hide();$(this).parent().parent().find('a').removeClass('current');if(show){$section.show();$(this).addClass('current');}
if($.trackAction!=undefined){$.trackAction($section.attr('rel')+'.'+(show?'show':'hide'));}
$.cookie('wikiEditor-'+$(this).data('context').instance+'-toolbar-section',show?$section.attr('rel'):null);return false;}));},buildSection:function(context,id,section){var selected=$.cookie('wikiEditor-'+context.instance+'-toolbar-section');var $section;switch(section.type){case'toolbar':var $section=$('<div />').attr({'class':'toolbar section section-'+id,'rel':id});if('groups'in section){for(group in section.groups){$section.append($.wikiEditor.modules.toolbar.fn.buildGroup(context,group,section.groups[group]));}}
break;case'booklet':var $pages=$('<div />').addClass('pages');var $index=$('<div />').addClass('index');if('pages'in section){for(page in section.pages){$pages.append($.wikiEditor.modules.toolbar.fn.buildPage(context,page,section.pages[page]));$index.append($.wikiEditor.modules.toolbar.fn.buildBookmark(context,page,section.pages[page]));}}
$section=$('<div />').attr({'class':'booklet section section-'+id,'rel':id}).append($index).append($pages);$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,page,$pages,$index);break;}
if($section!==null&&id!=='main'){$section.css('display',selected==id?'block':'none');}
return $section;},updateBookletSelection:function(context,id,$pages,$index){var cookie='wikiEditor-'+context.instance+'-booklet-'+id+'-page';var selected=$.cookie(cookie);var $selectedIndex=$index.find('*[rel='+selected+']');if($selectedIndex.size()==0){selected=$index.children().eq(0).attr('rel');$.cookie(cookie,selected);}
$pages.children().hide();$pages.find('*[rel='+selected+']').show();$index.children().removeClass('current');$selectedIndex.addClass('current');},build:function(context,config){var $tabs=$('<div />').addClass('tabs').appendTo(context.modules.$toolbar);var $sections=$('<div />').addClass('sections').appendTo(context.modules.$toolbar);context.modules.$toolbar.append($('<div />').css('clear','both'));var sectionQueue=[];for(section in config){if(section=='main'){context.modules.$toolbar.prepend($.wikiEditor.modules.toolbar.fn.buildSection(context,section,config[section]));}else{sectionQueue.push({'$sections':$sections,'context':context,'id':section,'config':config[section]});$tabs.append($.wikiEditor.modules.toolbar.fn.buildTab(context,section,config[section]));}}
$.eachAsync(sectionQueue,{'bulk':0,'end':function(){$('body').css('position','static');$('body').css('position','relative');},'loop':function(i,s){s.$sections.append($.wikiEditor.modules.toolbar.fn.buildSection(s.context,s.id,s.config));}});}}};})(jQuery);(function($){$.wikiEditor.modules.toc={api:{},fn:{create:function(context,config){if('$toc'in context.modules){return;}
context.modules.$toc=$('<div></div>').addClass('wikiEditor-ui-toc').attr('id','wikiEditor-ui-toc');$.wikiEditor.modules.toc.fn.build(context,config);context.$ui.find('.wikiEditor-ui-bottom').append(context.modules.$toc);context.modules.$toc.height(context.$ui.find('.wikiEditor-ui-bottom').height());context.modules.$toc.css('width','12em').css('marginTop',-(context.$ui.find('.wikiEditor-ui-bottom').height()));context.$ui.find('.wikiEditor-ui-text').css(($('body.rtl').size()?'marginLeft':'marginRight'),'12em');$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);context.$textarea.bind('keyup encapsulateSelection',function(event){var context=$(this).data('context');$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}});}).bind('mouseup scrollToPosition',function(event){var context=$(this).data('context');$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.update(context);}});});},update:function(context){context.modules.$toc.find('a').removeClass('currentSelection');var position=context.$textarea.getCaretPosition();var section=0;if(context.data.outline.length>0){if(!(position<context.data.outline[0].position-1)){while(section<context.data.outline.length&&context.data.outline[section].position-1<position){section++;}
section=Math.max(0,section);}
context.modules.$toc.find('a.section-'+section).addClass('currentSelection');}},build:function(context){function buildStructure(outline,offset,level){if(offset==undefined)offset=0;if(level==undefined)level=1;var sections=[];for(var i=offset;i<outline.length;i++){if(outline[i].nLevel==level){var sub=buildStructure(outline,i+1,level+1);if(sub.length){outline[i].sections=sub;}
sections[sections.length]=outline[i];}else if(outline[i].nLevel<level){break;}}
return sections;}
function buildList(structure){var list=$('<ul></ul>');for(i in structure){var item=$('<li></li>').append($('<a></a>').attr('href','#').addClass('section-'+structure[i].index).data('textbox',context.$textarea).data('position',structure[i].position).click(function(event){$(this).data('textbox').scrollToCaretPosition($(this).data('position'));event.preventDefault();}).text(structure[i].text));if(structure[i].sections!==undefined){item.append(buildList(structure[i].sections));}
list.append(item);}
return list;}
var outline=[];var wikitext='\n'+context.$textarea.val()+'\n';var headings=wikitext.match(/\n={1,5}.*={1,5}(?=\n)/g);var offset=0;headings=$.makeArray(headings);for(var h=0;h<headings.length;h++){text=headings[h];var position=wikitext.indexOf(text,offset);if(position>offset){offset=position;}else if(position==-1){continue;}
text=$.trim(text);var startLevel=0;for(var c=0;c<text.length;c++){if(text.charAt(c)=='='){startLevel++;}else{break;}}
var endLevel=0;for(var c=text.length-1;c>=0;c--){if(text.charAt(c)=='='){endLevel++;}else{break;}}
var level=Math.min(startLevel,endLevel);text=$.trim(text.substr(level,text.length-(level*2)));outline[h]={'text':text,'position':position,'level':level,'index':h+1};}
var lastLevel=0;var nLevel=0;for(var i=0;i<outline.length;i++){if(outline[i].level>lastLevel){nLevel++;}
else if(outline[i].level<nLevel){nLevel-=Math.max(1,lastLevel-outline[i].level);}
if(nLevel<=0){nLevel=1;}
outline[i].nLevel=nLevel;lastLevel=outline[i].level;}
var structure=buildStructure(outline);if($('input[name=wpSection]').val()=='')
structure.unshift({'text':wgPageName.replace(/_/g,' '),'level':1,'index':0,'position':0});context.modules.$toc.html(buildList(structure));context.data.outline=outline;}}};})(jQuery);