(function($){(function($){$.toJSON=function(o){if(typeof(JSON)=="object"&&JSON.stringify){return JSON.stringify(o)}var type=typeof(o);if(o===null){return"null"}if(type=="undefined"){return undefined}if(type=="number"||type=="boolean"){return o+""}if(type=="string"){return $.quoteString(o)}if(type=="object"){if(typeof o.toJSON=="function"){return $.toJSON(o.toJSON())}if(o.constructor===Date){var month=o.getUTCMonth()+1;if(month<10){month="0"+month}var day=o.getUTCDate();if(day<10){day="0"+day}var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10){hours="0"+hours}var minutes=o.getUTCMinutes();if(minutes<10){minutes="0"+minutes}var seconds=o.getUTCSeconds();if(seconds<10){seconds="0"+seconds}var milli=o.getUTCMilliseconds();if(milli<100){milli="0"+milli}if(milli<10){milli="0"+milli}return'"'+year+"-"+month+"-"+day+"T"+hours+":"+minutes+":"+seconds+"."+milli+'Z"'}if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i])||"null")}return"["+ret.join(",")+"]"}var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number"){name='"'+k+'"'}else{if(type=="string"){name=$.quoteString(k)}else{continue}}if(typeof o[k]=="function"){continue}var val=$.toJSON(o[k]);pairs.push(name+":"+val)}return"{"+pairs.join(", ")+"}"}};$.evalJSON=function(src){if(typeof(JSON)=="object"&&JSON.parse){return JSON.parse(src)}return eval("("+src+")")};$.secureEvalJSON=function(src){if(typeof(JSON)=="object"&&JSON.parse){return JSON.parse(src)}var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,"@");filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]");filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,"");if(/^[\],:{}\s]*$/.test(filtered)){return eval("("+src+")")}else{throw new SyntaxError("Error parsing JSON, source is not valid.")}};$.quoteString=function(string){if(string.match(_escapeable)){return'"'+string.replace(_escapeable,function(a){var c=_meta[a];if(typeof c==="string"){return c}c=a.charCodeAt();return"\\u00"+Math.floor(c/16).toString(16)+(c%16).toString(16)})+'"'}return'"'+string+'"'};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}})(jQuery);(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);(function($){var init=function(htmlElement){var $element=$(htmlElement);if($element.css("position")===undefined||$element.css("position")==="static"){$element.css("position","relative")}var $scrollbar=$("<div class='scrollbar' />");var $drag=$("<div class='drag' />").appendTo($scrollbar);$element.wrapInner("<div class='wrapper'><div class='content' /></div>").append($scrollbar);var $wrapper=$element.find("> .wrapper");var $content=$wrapper.find("> .content");var mouseOffsetY=0;var updateId=undefined;var update=function(repeat){if(updateId!==undefined&&!repeat){clearInterval(updateId);updateId=undefined}else{if(updateId===undefined&&repeat){updateId=setInterval(function(){update(true)},50)}}$wrapper.css("height",$element.height());var visibleHeight=$element.height();var contentHeight=$content.outerHeight();var scrollTop=$wrapper.scrollTop();var scrollTopFrac=scrollTop/contentHeight;var visVertFrac=Math.min(visibleHeight/contentHeight,1);if(visVertFrac<1){$scrollbar.fadeIn(50).css({height:$element.innerHeight()+$scrollbar.height()-$scrollbar.outerHeight(true)});$drag.css({top:$scrollbar.height()*scrollTopFrac,height:$scrollbar.height()*visVertFrac})}else{$scrollbar.fadeOut(50)}};var scroll=function(event){var clickFrac=(event.pageY-$scrollbar.offset().top-mouseOffsetY)/$scrollbar.height();$wrapper.scrollTop($content.outerHeight()*clickFrac);update()};$element.mousewheel(function(event,delta){$wrapper.scrollTop($wrapper.scrollTop()-50*delta);update();event.stopPropagation();event.preventDefault()}).scroll(update);$element.get(0).updateScrollbar=update;$wrapper.css({"padding-right":$scrollbar.outerWidth(true),height:$element.height(),overflow:"hidden"});$scrollbar.css({position:"absolute",top:0,right:0,overflow:"hidden"}).mousedown(function(event){mouseOffsetY=$drag.outerHeight()/2;scroll(event);$scrollbar.addClass("dragOn");$(window).bind("mousemove",scroll).one("mouseup",function(event){$scrollbar.removeClass("dragOn");$(window).unbind("mousemove",scroll);scroll(event);event.stopPropagation()});event.stopPropagation()}).attr("unselectable","on").css("-moz-user-select","none").each(function(){this.onselectstart=function(){return false}});$drag.css({position:"absolute",left:0,width:"100%"}).mousedown(function(event){mouseOffsetY=event.pageY-$drag.offset().top;scroll(event);$scrollbar.addClass("dragOn");$(window).bind("mousemove",scroll).one("mouseup",function(event){$scrollbar.removeClass("dragOn");$(window).unbind("mousemove",scroll);scroll(event);event.stopPropagation()});event.stopPropagation()});update()};$.fn.scrollpanel=function(){return this.each(function(){init(this)})}})(jQuery);(function($){$.log=function(){$.log.history=$.log.history||[];$.log.history.push(arguments);if(window.console){window.console.log(Array.prototype.slice.call(arguments))}};var Timer=function(){this.start=new Date().getTime();this.last=this.start;this.log=function(label){var now=new Date().getTime();$.log("timer",label,"+"+(now-this.last),"="+(now-this.start));this.last=now}};$.timer=new Timer()})(jQuery);var H5ai=function(options,langs){var defaults={store:{viewmode:"h5ai.viewmode",lang:"h5ai.lang"},callbacks:{pathClick:[]},viewmodes:["details","icons"],showTree:true,folderStatus:{},lang:null,useBrowserLang:true,setParentFolderLabels:true,linkHoverStates:true};this.config=$.extend({},defaults,options);this.pathClick=function(fn){if($.isFunction(fn)){this.config.callbacks.pathClick.push(fn)}return this};this.init=function(){this.applyViewmode();this.initTopSpace();this.initViews();this.initTree();this.linkHoverStates();this.initLangSelector(langs);this.localize(langs,this.config.lang,this.config.useBrowserLang);this.initIndicators()};this.triggerPathClick=function(path,context){for(idx in this.config.callbacks.pathClick){this.config.callbacks.pathClick[idx].call(window,path,context)}};this.getViewmode=function(){var viewmode=localStorage.getItem(this.config.store.viewmode);return $.inArray(viewmode,this.config.viewmodes)>=0?viewmode:this.config.viewmodes[0]};this.applyViewmode=function(viewmode){if(viewmode!==undefined){localStorage.setItem(this.config.store.viewmode,viewmode)}viewmode=this.getViewmode();$("#viewdetails,#viewicons").hide().removeClass("current");if(this.config.viewmodes.length>1){if($.inArray("details",this.config.viewmodes)>=0){$("#viewdetails").show()}if($.inArray("icons",this.config.viewmodes)>=0){$("#viewicons").show()}}if(viewmode==="details"){$("#viewdetails").closest("li").addClass("current");$("#extended").addClass("details-view").removeClass("icons-view").show()}else{if(viewmode==="icons"){$("#viewicons").closest("li").addClass("current");$("#extended").removeClass("details-view").addClass("icons-view").show()}else{$("#extended").hide()}}};this.initTopSpace=function(){function adjustTopSpace(){var winHeight=$(window).height();var navHeight=$("body > nav").outerHeight();var footerHeight=$("body > footer").outerHeight();var contentSpacing=50;var treeSpacing=50;$("body").css("margin-top",""+(navHeight+contentSpacing)+"px").css("margin-bottom",""+(footerHeight+contentSpacing)+"px");$("#tree").css("top",""+(navHeight+treeSpacing)+"px").css("height",""+(winHeight-navHeight-footerHeight-36-2*treeSpacing)+"px");try{$("#tree").get(0).updateScrollbar()}catch(err){}}$(window).resize(function(){adjustTopSpace()});adjustTopSpace()};this.initViews=function(){$("#table").remove();$("#viewdetails").closest("li").click($.proxy(function(){this.applyViewmode("details")},this));$("#viewicons").closest("li").click($.proxy(function(){this.applyViewmode("icons")},this))};this.initTree=function(){var $tree=$("#tree");var $extended=$("#extended");var shiftTree=function(forceVisible,dontAnimate){if($tree.outerWidth()<$extended.offset().left||forceVisible===true){if(dontAnimate===true){$tree.stop().css({left:0})}else{$tree.stop().animate({left:0})}}else{if(dontAnimate===true){$tree.stop().css({left:18-$tree.outerWidth()})}else{$tree.stop().animate({left:18-$tree.outerWidth()})}}};$tree.hover(function(){shiftTree(true)},function(){shiftTree()});$(window).resize(function(){shiftTree()});shiftTree(false,true)};this.linkHoverStates=function(){if(!this.config.linkHoverStates){return}$("a[href^='/']:not(.linkedHoverStates)").each(function(){var $a=$(this).addClass("linkedHoverStates");var href=$a.attr("href");$a.hover(function(){$("a[href='"+href+"']").addClass("hover")},function(){$("a[href='"+href+"']").removeClass("hover")})})};this.initLangSelector=function(langs){var sortedLangsKeys=[];for(lang in langs){sortedLangsKeys.push(lang)}sortedLangsKeys.sort();var THIS=this;var $ul=$("<ul />");for(idx in sortedLangsKeys){(function(lang){$("<li class='langOption' />").addClass(lang).text(lang+" - "+langs[lang]["lang"]).appendTo($ul).click(function(){localStorage.setItem(THIS.config.store.lang,lang);THIS.localize(langs,lang,false)})})(sortedLangsKeys[idx])}$("#langSelector .langOptions").append($ul);$("#langSelector").hover(function(){var $ele=$(".langOptions");$ele.css("top","-"+$ele.outerHeight()+"px").stop(true,true).fadeIn()},function(){$(".langOptions").stop(true,true).fadeOut()})};this.localize=function(langs,lang,useBrowserLang){if(useBrowserLang===true){var browserLang=navigator.language;if(langs[browserLang]!==undefined){lang=browserLang}else{if(browserLang.length>2&&langs[browserLang.substr(0,2)]!==undefined){lang=browserLang.substr(0,2)}}}if(langs[lang]===undefined){lang="en"}var storedLang=localStorage.getItem(this.config.store.lang);if(langs[storedLang]!==undefined){lang=storedLang}var selected=langs[lang];for(key in selected){$(".l10n-"+key).text(selected[key])}$(".lang").text(lang);$(".langOption").removeClass("current");$(".langOption."+lang).addClass("current")};this.initIndicators=function(){var THIS=this;$("#tree .entry.folder:not(.initiatedIndicator)").each(function(){var $entry=$(this).addClass("initiatedIndicator");var $indicator=$entry.find("> .indicator");$indicator.click(function(event){if($indicator.hasClass("unknown")){$.get("/h5ai/php/treecontent.php",{href:$entry.find("> a").attr("href")},function(html){$content=$(html);$indicator.removeClass("unknown");if($content.find("> li").size()===0){$indicator.replaceWith($("<span class='blank' />"))}else{$indicator.addClass("open");$entry.find("> .content").replaceWith($content);$("#tree").get(0).updateScrollbar();THIS.initIndicators()}})}else{if($indicator.hasClass("open")){$indicator.removeClass("open");$("#tree").get(0).updateScrollbar(true);$entry.find("> .content").slideUp(function(){$("#tree").get(0).updateScrollbar()})}else{$indicator.addClass("open");$("#tree").get(0).updateScrollbar(true);$entry.find("> .content").slideDown(function(){$("#tree").get(0).updateScrollbar()})}}})})}};var h5ai=new H5ai(h5aiOptions,h5aiLangs);$.h5ai={click:$.proxy(h5ai.pathClick,h5ai)};$(function(){h5ai.init();$("#tree").scrollpanel()})})(jQuery);
