(function(i,f){var t=i.fn.domManip,h="_tmplitem",u=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,p={},e={},y,x={key:0,data:{}},w=0,q=0,g=[];function k(B,A,D,E){var C={data:E||(A?A.data:{}),_wrap:A?A._wrap:null,tmpl:null,parent:A||null,nodes:[],calls:c,nest:b,wrap:n,html:r,update:z};if(B){i.extend(C,B,{nodes:[],parent:A})}if(D){C.tmpl=D;C._ctnt=C._ctnt||C.tmpl(i,C);C.key=++w;(g.length?e:p)[w]=C}return C}i.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(A,B){i.fn[A]=function(C){var F=[],I=i(C),E,G,D,J,H=this.length===1&&this[0].parentNode;y=p||{};if(H&&H.nodeType===11&&H.childNodes.length===1&&I.length===1){I[B](this[0]);F=this}else{for(G=0,D=I.length;G<D;G++){q=G;E=(G>0?this.clone(true):this).get();i.fn[B].apply(i(I[G]),E);F=F.concat(E)}q=0;F=this.pushStack(F,A,I.selector)}J=y;y=null;i.tmpl.complete(J);return F}});i.fn.extend({tmpl:function(C,B,A){return i.tmpl(this[0],C,B,A)},tmplItem:function(){return i.tmplItem(this[0])},template:function(A){return i.template(A,this[0])},domManip:function(C,G,H,B){if(C[0]&&C[0].nodeType){var F=i.makeArray(arguments),E=C.length,D=0,A;while(D<E&&!(A=i.data(C[D++],"tmplItem"))){}if(E>1){F[0]=[i.makeArray(C)]}if(A&&q){F[2]=function(I){i.tmpl.afterManip(this,I,H)}}t.apply(this,F)}else{t.apply(this,arguments)}q=0;if(!y){i.tmpl.complete(p)}return this}});i.extend({tmpl:function(C,F,E,B){var D,A=!B;if(A){B=x;C=i.template[C]||i.template(null,C);e={}}else{if(!C){C=B.tmpl;p[B.key]=B;B.nodes=[];if(B.wrapped){s(B,B.wrapped)}return i(m(B,null,B.tmpl(i,B)))}}if(!C){return[]}if(typeof F==="function"){F=F.call(B||{})}if(E&&E.wrapped){s(E,E.wrapped)}D=i.isArray(F)?i.map(F,function(G){return G?k(E,B,C,G):null}):[k(E,B,C,F)];return A?i(m(B,null,D)):D},tmplItem:function(B){var A;if(B instanceof i){B=B[0]}while(B&&B.nodeType===1&&!(A=i.data(B,"tmplItem"))&&(B=B.parentNode)){}return A||x},template:function(B,A){if(A){if(typeof A==="string"){A=l(A)}else{if(A instanceof i){A=A[0]||{}}}if(A.nodeType){A=i.data(A,"tmpl")||i.data(A,"tmpl",l(A.innerHTML))}return typeof B==="string"?(i.template[B]=A):A}return B?(typeof B!=="string"?i.template(null,B):(i.template[B]||i.template(null,u.test(B)?B:i(B)))):null},encode:function(A){return(""+A).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});i.extend(i.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){_=_.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(_,$1,$2);_=[];",close:"call=$item.calls();_=call._.concat($item.wrap(call,_));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){_.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){_.push($.encode($1a));}"},"!":{open:""}},complete:function(A){p={}},afterManip:function v(C,A,D){var B=A.nodeType===11?i.makeArray(A.childNodes):A.nodeType===1?[A]:[];D.call(C,A);o(B);q++}});function m(A,E,C){var D,B=C?i.map(C,function(F){return(typeof F==="string")?(A.key?F.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+h+'="'+A.key+'" $2'):F):m(F,A,F._ctnt)}):A;if(E){return B}B=B.join("");B.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(G,H,F,I){D=i(F).get();o(D);if(H){D=a(H).concat(D)}if(I){D=D.concat(a(I))}});return D?D:a(B)}function a(B){var A=document.createElement("div");A.innerHTML=B;return i.makeArray(A.childNodes)}function l(A){return new Function("jQuery","$item","var $=jQuery,call,_=[],$data=$item.data;with($data){_.push('"+i.trim(A).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(I,C,G,D,E,J,F){var L=i.tmpl.tag[G],B,H,K;if(!L){throw"Template command not found: "+G}B=L._default||[];if(J&&!/\w$/.test(E)){E+=J;J=""}if(E){E=j(E);F=F?(","+j(F)+")"):(J?")":"");H=J?(E.indexOf(".")>-1?E+J:("("+E+").call($item"+F)):E;K=J?H:"(typeof("+E+")==='function'?("+E+").call($item):("+E+"))"}else{K=H=B.$1||"null"}D=j(D);return"');"+L[C?"close":"open"].split("$notnull_1").join(E?"typeof("+E+")!=='undefined' && ("+E+")!=null":"true").split("$1a").join(K).split("$1").join(H).split("$2").join(D?D.replace(/\s*([^\(]+)\s*(\((.*?)\))?/g,function(N,M,O,P){P=P?(","+P+")"):(O?")":"");return P?("("+M+").call($item"+P):N}):(B.$2||""))+"_.push('"})+"');}return _;")}function s(B,A){B._wrap=m(B,true,i.isArray(A)?A:[u.test(A)?A:i(A).html()]).join("")}function j(A){return A?A.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function d(A){var B=document.createElement("div");B.appendChild(A.cloneNode(true));return B.innerHTML}function o(G){var I="_"+q,B,A,E={},F,D,C;for(F=0,D=G.length;F<D;F++){if((B=G[F]).nodeType!==1){continue}A=B.getElementsByTagName("*");for(C=A.length-1;C>=0;C--){H(A[C])}H(B)}function H(O){var L,N=O,M,J,K;if((K=O.getAttribute(h))){while(N.parentNode&&(N=N.parentNode).nodeType===1&&!(L=N.getAttribute(h))){}if(L!==K){N=N.parentNode?(N.nodeType===11?0:(N.getAttribute(h)||0)):0;if(!(J=p[K])){J=e[K];J=k(J,p[N]||e[N],null,true);J.key=++w;p[w]=J}if(q){P(K)}}O.removeAttribute(h)}else{if(q&&(J=i.data(O,"tmplItem"))){P(J.key);p[J.key]=J;N=i.data(O.parentNode,"tmplItem");N=N?N.key:0}}if(J){M=J;while(M&&M.key!=N){M.nodes.push(O);M=M.parent}delete J._ctnt;delete J._wrap;i.data(O,"tmplItem",J)}function P(Q){Q=Q+I;J=E[Q]=(E[Q]||k(J,p[J.parent.key+I]||J.parent,null,true))}}}function c(C,A,D,B){if(!C){return g.pop()}g.push({_:C,tmpl:A,item:this,data:D,options:B})}function b(A,C,B){return i.tmpl(i.template(A),C,B,this)}function n(C,A){var B=C.options||{};B.wrapped=A;return i.tmpl(i.template(C.tmpl),C.data,B,C.item)}function r(B,C){var A=this._wrap;return i.map(i(i.isArray(A)?A.join(""):A).filter(B||"*"),function(D){return C?D.innerText||D.textContent:D.outerHTML||d(D)})}function z(){var A=this.nodes;i.tmpl(null,null,null,this).insertBefore(A[0]);i(A).remove()}})(jQuery);
!function(c){var a;c(document).ready(function(){c.support.transition=(function(){var f=document.body||document.documentElement,g=f.style,e=g.transition!==undefined||g.WebkitTransition!==undefined||g.MozTransition!==undefined||g.MsTransition!==undefined||g.OTransition!==undefined;return e})();if(c.support.transition){a="TransitionEnd";if(c.browser.webkit){a="webkitTransitionEnd"}else{if(c.browser.mozilla){a="transitionend"}else{if(c.browser.opera){a="oTransitionEnd"}}}}});var d=function(f,e){this.$element=c(f);this.options=e;this.enabled=true;this.fixTitle()};d.prototype={show:function(){var j,f,i,e,h,g;if(this.hasContent()&&this.enabled){h=this.tip();this.setContent();if(this.options.animate){h.addClass("fade")}h.remove().css({top:0,left:0,display:"block"}).prependTo(document.body);j=c.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight});f=h[0].offsetWidth;i=h[0].offsetHeight;e=b(this.options.placement,this,[h[0],this.$element[0]]);switch(e){case"below":g={top:j.top+j.height+this.options.offset,left:j.left+j.width/2-f/2};break;case"above":g={top:j.top-i-this.options.offset,left:j.left+j.width/2-f/2};break;case"left":g={top:j.top+j.height/2-i/2,left:j.left-f-this.options.offset};break;case"right":g={top:j.top+j.height/2-i/2,left:j.left+j.width+this.options.offset};break}h.css(g).addClass(e).addClass("in")}},setContent:function(){var e=this.tip();e.find(".twipsy-inner")[this.options.html?"html":"text"](this.getTitle());e[0].className="twipsy"},hide:function(){var f=this,g=this.tip();g.removeClass("in");function e(){g.remove()}c.support.transition&&this.$tip.hasClass("fade")?g.bind(a,e):e()},fixTitle:function(){var e=this.$element;if(e.attr("title")||typeof(e.attr("data-original-title"))!="string"){e.attr("data-original-title",e.attr("title")||"").removeAttr("title")}},hasContent:function(){return this.getTitle()},getTitle:function(){var g,e=this.$element,f=this.options;this.fixTitle();if(typeof f.title=="string"){g=e.attr(f.title=="title"?"data-original-title":f.title)}else{if(typeof f.title=="function"){g=f.title.call(e[0])}}g=(""+g).replace(/(^\s*|\s*$)/,"");return g||f.fallback},tip:function(){return this.$tip=this.$tip||c('<div class="twipsy" />').html(this.options.template)},validate:function(){if(!this.$element[0].parentNode){this.hide();this.$element=null;this.options=null}},enable:function(){this.enabled=true},disable:function(){this.enabled=false},toggleEnabled:function(){this.enabled=!this.enabled},toggle:function(){this[this.tip().hasClass("in")?"hide":"show"]()}};function b(g,e,f){return typeof g=="function"?g.apply(e,f):g}c.fn.twipsy=function(e){c.fn.twipsy.initWith.call(this,e,d,"twipsy");return this};c.fn.twipsy.initWith=function(n,j,e){var m,l,h,g;if(n===true){return this.data(e)}else{if(typeof n=="string"){m=this.data(e);if(m){m[n]()}return this}}n=c.extend({},c.fn[e].defaults,n);function f(p){var o=c.data(p,e);if(!o){o=new j(p,c.fn.twipsy.elementOptions(p,n));c.data(p,e,o)}return o}function i(){var o=f(this);o.hoverState="in";if(n.delayIn==0){o.show()}else{o.fixTitle();setTimeout(function(){if(o.hoverState=="in"){o.show()}},n.delayIn)}}function k(){var o=f(this);o.hoverState="out";if(n.delayOut==0){o.hide()}else{setTimeout(function(){if(o.hoverState=="out"){o.hide()}},n.delayOut)}}if(!n.live){this.each(function(){f(this)})}if(n.trigger!="manual"){l=n.live?"live":"bind";h=n.trigger=="hover"?"mouseenter":"focus";g=n.trigger=="hover"?"mouseleave":"blur";this[l](h,i)[l](g,k)}return this};c.fn.twipsy.Twipsy=d;c.fn.twipsy.defaults={animate:true,delayIn:0,delayOut:0,fallback:"",placement:"above",html:false,live:false,offset:0,title:"title",trigger:"hover",template:'<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>'};c.fn.twipsy.rejectAttrOptions=["title"];c.fn.twipsy.elementOptions=function(j,f){var h=c(j).data(),e=c.fn.twipsy.rejectAttrOptions,g=e.length;while(g--){delete h[e[g]]}return c.extend({},f,h)}}(window.jQuery||window.ender);
!function(b){var a=function(d,c){this.$element=b(d);this.options=c;this.enabled=true;this.fixTitle()};a.prototype=b.extend({},b.fn.twipsy.Twipsy.prototype,{setContent:function(){var c=this.tip();c.find(".title")[this.options.html?"html":"text"](this.getTitle());c.find(".content p")[this.options.html?"html":"text"](this.getContent());c[0].className="popover"},hasContent:function(){return this.getTitle()||this.getContent()},getContent:function(){var d,c=this.$element,e=this.options;if(typeof this.options.content=="string"){d=c.attr(this.options.content)}else{if(typeof this.options.content=="function"){d=this.options.content.call(this.$element[0])}}return d},tip:function(){if(!this.$tip){this.$tip=b('<div class="popover" />').html(this.options.template)}return this.$tip}});b.fn.popover=function(c){if(typeof c=="object"){c=b.extend({},b.fn.popover.defaults,c)}b.fn.twipsy.initWith.call(this,c,a,"popover");return this};b.fn.popover.defaults=b.extend({},b.fn.twipsy.defaults,{placement:"right",content:"data-content",template:'<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>'});b.fn.twipsy.rejectAttrOptions.push("content")}(window.jQuery||window.ender);
Read={init:function(){var a=$("#chapter_"+initial_active_node);$(".read_accordion").accordion({active:a});$(".section_link").live("click",Read.fetch_section);$(".load_questions").live("click",Read.load_questions);$(".load_pictures").live("click",Read.load_pictures);$(".font-sizer").live("click",Read.change_font_size);$(".ui-accordion").bind("accordionchange",Read.chapter_selected);$(".next_page").live("click",Read.next_page);Read.History.init();Read.update_qr_code()},change_font_size:function(){var a=$(this);size=a.attr("data-font-size");$("#paragraphs").css("font-size",size)},next_page:function(){var c=$(".section_link");var b=c.index($("a",$("li.active_section")));if(c.length>b+1){var a=$(c[b+1]);if($("li.active_section a").attr("data-last")!="True"){a.trigger("click")}else{$(c[b]).parents(".chapter").next().trigger("click")}$("html, body").stop().animate({scrollTop:10},500,"easeInOutExpo")}else{window.alert("yay. you've reached the end of the book!")}return false},chapter_selected:function(c,d){if(d.newHeader!=d.oldHeader){var b=$(d.newHeader);var a=b.next();$("ul li:first a",a).trigger("click")}},fetch_section:function(){$("#add_question_form").hide();var a=$(this);$("li.active_section").removeClass("active_section");a.closest("li").addClass("active_section");$(".paragraphs").addClass("transparent");if(!Read.History.backclick){Read.History.push(null,null,a.attr("href"))}if(_gaq){_gaq.push(["_trackPageview",a.attr("href")])}$(document).attr("title",a.html()+" | African License");$.post("/api/learn/section/"+a.attr("rel")+"/get.json",{course:active_course},function(b){$("#paragraph_container").html("");$("#section_header").html(b.chapter.title+" > "+b.title);$("#paragraph_template").tmpl(b.paragraphs).appendTo("#paragraph_container");$(".paragraphs").removeClass("transparent");Read.update_qr_code();if(a.attr("data-last")=="True"){var c="Review Chapter: "+b.chapter.title;$("#generate_test").removeAttr("data-sections");$("#generate_test").attr("data-chapters","chapter="+b.chapter.pk);$("#generate_test").attr("data-title",c);$("#generate_test").attr("title",c)}else{var c="Review Section: "+b.title;$("#generate_test").removeAttr("data-chapters");$("#generate_test").attr("data-sections","section="+b.pk);$("#generate_test").attr("data-title",c);$("#generate_test").attr("title",c)}});Read.History.backclick=false;return false},update_qr_code:function(){var a="http://chart.apis.google.com/chart?cht=qr&chs=200x200&chl=http://"+document.location.host+"/m/"+document.location.pathname;$("#qr_code").attr("src",a);$("#mobile_container").slideDown()},load_pictures:function(){var b=$(this);var a=$(this).closest(".paragraph");var c=a.attr("id");$.post("/api/learn/linked_pictures.json",{id:c,type:"paragraph"},function(d){var e=$(".pictures",a);e.html("");$("#picture_template").tmpl(d).appendTo(e);$(".pictures").append("<div class='clear'></div>").show()})},load_questions:function(){var b=$(this);var a=$(this).closest(".paragraph");var c=$(".questions",a);if(c.is(":visible")){c.slideUp()}else{c.slideDown().html("<div class='loader'>loading</div>");$.post("/api/learn/questions_by_paragraph.json",{paragraph:b.attr("rel")},function(d){if(d.length==0){c.html("There are currently no questions associated with this paragraph")}else{c.html("");$.each(d,function(g,i){var f=$("<div/>").addClass("question");f.append("<strong>"+i.title+"</strong>");var h=$("<ul/>");$.each(i.answers[0],function(j,l){var k=$("<li/>").html(l.option);h.append(k)});f.append(h);c.append(f)});if(d.length>=5){var e=$("#generate_test").clone();e.html("Quick Test &raquo;").attr("data-paragraph",a.attr("id")).attr("title","Generate a quick test out of the questions above").attr("data-title","Quick Test: "+a.prev().html()).css("float","right").removeAttr("data-sections").removeAttr("data-chapters");c.append(e);c.append("<div class='clear'></div>");e.tipsy({gravity:$.fn.tipsy.autoNS,fade:true})}}})}return false},History:{backclick:false,init:function(){if(Modernizr.history){$(window).bind("popstate",function(b){Read.History.backclick=true;var a=$(".chapter a[href='"+window.location.pathname+"']");a.trigger("click");if(Modernizr.localstorage){localStorage.setItem("learn_path",window.location.pathname)}})}},push:function(b,c,a){if(Modernizr.history){history.pushState(b,c,a);if(Modernizr.localstorage){localStorage.setItem("learn_path",window.location.pathname)}}}}};$(document).ready(Read.init);