(function(A){A.ajaxNav={version:0.91,defaults:{ajaxFile:"ajax/getdata.php",ajaxParams:{},target:false,workspace:false,createWorkspace:false,createViewport:false,fixViewport:false,onShow:false,callback:false,subMenu:false,classActive:"activeItem",trackGA:false,useOverlay:false,keyNav:false,windowResize:false,fade:true,find:false,offset:[50,50],buttons:false,dragDrop:false},parseGetParameters:function(D){var F={};if(D&&(index=D.indexOf("?"))!==-1){var C=D.substring(index+1).split(/&amp;|&/);for(var E=0;E<C.length;E++){var B=C[E].split("=");F[B[0]]=(typeof (B[1])!="undefined")?B[1]:""}}return F},cache:[],init:function(B){if(B.mainNav.is(".ajaxNav")){return }B.cacheIndex=this.cache.length;this.cache[B.cacheIndex]=B;B.hashRegExp=new RegExp(B.cacheIndex+":(\\-?\\d+),(\\-?\\d+)");B.root=window.location.protocol+"//"+window.location.hostname+window.location.pathname;B.backLinkLog={};if(B.options.keyNav){B.backLinkLog[B.root]=[0,0]}var C=B.options;if(!C.workspace&&!C.target){return }var D=C.target?A(C.target):A(":first-child",C.workspace);B.mainNav.each(function(E){if(A(this).is("."+C.classActive)){B.activeItem=[E,0]}});if(C.subMenu){A(C.subMenu,D).each(function(E){if(A(this).is("."+C.classActive)){B.activeItem[1]=E}})}this.createNav(B,B,B.mainNav);this.setHash(B,B.activeItem,true);if(B.activeItem[0]==-1){B.nav[-1]={nav:[]};B.nav[-1].nav[B.activeItem[1]]={}}if(C.subMenu){this.createSubMenu(B,B.activeItem,true)}B.currentTarget=B.activeItem;var D=this.getNav(B,B.activeItem)["target"]=C.target?A(C.target):A(":first-child",C.workspace);B.workspace=C.workspace?A(C.workspace):C.createWorkspace?D.wrap("<div/>").parent():A(D).parent();B.viewport=C.createViewport?B.workspace.wrap("<div/>").parent():B.workspace.parent();B.workspace.addClass("ajaxNav_workspace");B.viewport.addClass("ajaxNav_viewport");if(A.browser.msie){B.viewport.css("zoom",1)}B.contentWidth=D.width();B.contentHeight=D.height()||D.append('<div style="clear: both" />').outerHeight();B.windowWidth=A(window).width();B.left=B.viewport.width()/2-5000;B.top=0;if(C.fixViewport){B.viewport.css({overflow:"hidden",width:B.viewport.outerWidth(),height:B.viewport.outerHeight(),position:B.viewport.css("position")=="absolute"?"absolute":"relative"})}B.workspace.css({width:10000,height:10000,position:"absolute",left:B.left,top:B.top,textAlign:"center"});if(C.dragDrop){B.workspace.css({cursor:"move"}).bind("mousedown.ajaxNav",function(E){A.ajaxNav.drag.start(E,B)})}D.css({cursor:"auto",textAlign:"left",position:"absolute",top:D.position().top,left:5000-B.contentWidth/2,width:B.contentWidth,height:B.contentHeight});if(C.windowResize){A(window).bind("resize.ajaxNav",A.ajaxNav.setPosition)}if(C.useOverlay&&!this.compare(B.activeItem,[-1,-1])){this.addOverlay(B,B.activeItem)}if(C.keyNav){this.initKeyNav(B)}if(C.buttons){this.initButtons(B);this.setButtons(B)}this.preloadNeighbors(B);if(!this.hashEnabled){this.hashEnabled=true;this.hashPoll()}},initButtons:function(C){C.buttons={};var B;for(B in C.options.buttons){if(this.nav[B]){C.buttons[B]=A("<img/>").css("cursor","pointer").attr({src:C.options.buttons[B],alt:B,display:"block"}).addClass(B).appendTo(C.viewport).bind("click.ajaxNav",function(){A.ajaxNav.nav[this.alt](C)})}}},initKeyNav:function(B){A(document).bind("keydown.ajaxNav",function(E){if(A(E.target).is(":input")){return true}var C=false,D=false;if(37==E.keyCode){C="left"}else{if(39==E.keyCode){C="right"}else{if(38==E.keyCode){C="up"}else{if(40==E.keyCode){C="down"}}}}if(C){D=A.ajaxNav.nav[C](B)}if(D){E.preventDefault();E.stopPropagation()}return !D})},setButtons:function(C){var B=C.buttons;if(!B){return }if(B.left){B.left[this.getNav(C,C.activeItem[0]-1)?"show":"hide"]()}if(B.right){B.right[this.getNav(C,C.activeItem[0]+1)?"show":"hide"]()}if(B.up){B.up[this.getNav(C,[C.activeItem[0],C.activeItem[1]-1])?"show":"hide"]()}if(B.down){B.down[this.getNav(C,[C.activeItem[0],C.activeItem[1]+1])?"show":"hide"]()}},nav:{left:function(B){return A.ajaxNav.navigate(B,[B.activeItem[0]-1,B.activeItem[1]])},right:function(B){return A.ajaxNav.navigate(B,[B.activeItem[0]+1,B.activeItem[1]])},up:function(B){return A.ajaxNav.navigate(B,[B.activeItem[0],B.activeItem[1]-1])},down:function(B){return A.ajaxNav.navigate(B,[B.activeItem[0],B.activeItem[1]+1])}},drag:{start:function(C,B){if(C.target!=B.workspace[0]){return true}B.drag={x:-C.clientX+B.left,y:-C.clientY+B.top+B.topOffset,startX:C.clientX,startY:C.clientY};A(window).bind("mousemove.ajaxNav",function(D){A.ajaxNav.drag.drag(D,B)});A(window).one("mouseup.ajaxNav",function(D){A.ajaxNav.drag.stop(D,B)})},drag:function(C,B){C.preventDefault();C.stopPropagation();B.workspace[0].style.left=(B.drag.x+C.clientX)+"px";B.workspace[0].style.top=(B.drag.y+C.clientY)+"px"},stop:function(C,B){A.ajaxNav.setPosition();A(window).unbind("mousemove.ajaxNav")}},createSubMenu:function(C,E){var D=this.getNav(C,E[0]);var B=A(C.options.subMenu,this.getNav(C,E,"target"));this.createNav(C,D,B,E[0])},createNav:function(D,C,E,B){if(!C.nav){C.nav=[]}E.each(function(F){if(A(this).is(".ajaxNav")){return }var G=typeof B!=="undefined"?[B,F]:[F,0];if(!C.nav[F]){C.nav[F]={url:this.href,target:false};D.backLinkLog[this.href]=G}A.ajaxNav.processLink(D,this,G)});this.processBackLinks(D)},processLink:function(C,B,D){A(B).not(".ajaxNav").addClass("ajaxNav").bind("click.ajaxNav",function(E){this.blur();E.preventDefault();A.ajaxNav.navigate(C,D)})},processBackLinks:function(C,B){var D;A("a:not(.ajaxNav)",B||document).each(function(){if(D=C.backLinkLog[this.href]){A.ajaxNav.processLink(C,this,D)}})},setHash:function(D,F,B){var E=D.cacheIndex+":"+F;if(!D.hashRegExp.test(window.location.hash)){window.location.hash=window.location.hash.length>1?(window.location.hash+";"+E):("#"+E)}else{if(!B){var C=A(window.location.hash.substring(1).split(";")).map(function(){return D.hashRegExp.test(this)?E:this}).get();window.location.hash="#"+C.join(";")}}},getHash:function(B){var C=B.hashRegExp.exec(window.location.hash);return C?[parseInt(C[1]),parseInt(C[2])]:false},hashPoll:function(E){var C,D,B;for(C=0;C<this.cache.length;C++){var D=this.cache[C];var B=this.getHash(D);if(B&&!this.compare(D.activeItem,B)){A.ajaxNav.navigate(D,B)}}setTimeout(function(){A.ajaxNav.hashPoll(E)},100)},compare:function(B,C){return(B[0]==C[0])&&((B[1]||0)==(C[1]||0))},getNav:function(C,E,B){var D=false;if(E.constructor==Number){D=C.nav[E]}else{if(E.constructor==Array){if(E[1]!=0){D=C.nav[E[0]]&&C.nav[E[0]].nav?C.nav[E[0]].nav[E[1]]:(C.options.subMenu?false:undefined)}else{D=C.nav[E[0]]}}}if(D&&B){return D[B]}else{return D}},setPosition:function(C,D){var B=A(window).width();A.each(A.ajaxNav.cache,function(){if(!C||this.options.windowResize){this.topOffset=(this.options.useOverlay&&this.activeItem[1]!=0)?(this.viewport.height()-this.contentHeight)/2:0;if(this.options.windowResize){this.left=this.left-(this.windowWidth-B)/2}this.windowWidth=B;this.workspace.stop().animate({left:this.left,top:this.top+this.topOffset},D||200,"easeout")}})},preloadNeighbors:function(C){var B=C.activeItem;if(B.constructor==Array){this.load(C,[B[0]-1,B[1]]);this.load(C,[B[0]+1,B[1]]);this.load(C,[B[0],B[1]-1]);this.load(C,[B[0],B[1]+1])}else{this.load(C,[B-1,0]);this.load(C,[B+1,0])}},load:function(C,F){var B,E;if((E=this.getNav(C,F))&&(B=E.url)){if(!E.target&&!E.loading){E.loading=true;var D=A.extend(this.parseGetParameters(B),C.options.ajaxParams);A.getJSON(C.options.ajaxFile,D,function(G){E.ready=true;E.title=G.title||G.name||"";A.ajaxNav.addContent(C,F,G);setTimeout(function(){A(E).trigger("ajaxload")},0)})}else{if(E.ready){setTimeout(function(){A(E).trigger("ajaxload")},0)}}}},addContent:function(D,G,B){var C,I,F,E,H;I=this.getNav(D,D.activeItem,"target");F=parseInt(I.css("left"))+(G[0]-D.activeItem[0])*(D.contentWidth+D.options.offset[0]);E=parseInt(I.css("top"))+((G[1]||0)-(D.activeItem[1]||0))*(D.contentHeight+D.options.offset[1]);H=this.getNav(D,G[0]);C=(D.options.find?A(D.options.find,B.content):A(B.content)).css({position:"absolute",left:F,top:E,textAlign:"left",width:D.contentWidth,height:D.contentHeight,display:D.options.fade?"none":"block",cursor:"auto"}).appendTo(D.workspace);if(G[1]>0){H.nav[G[1]]["target"]=C}else{H.target=C}if(D.options.useOverlay){A.ajaxNav.addOverlay(D,G);C.fadeIn(500)}if(D.options.subMenu){this.createSubMenu(D,G)}if(D.options.callback){D.options.callback.apply(C)}},addOverlay:function(D,E){var F=this.getNav(D,E);var B=A('<a href="'+F.url+'" class="contentOverlay" style="background-color: black; cursor: pointer; position: absolute; z-index: 10;"/>');B.css("opacity",0.4);var C=F.target;B.prependTo(C).css({width:C.width(),height:C.height()}).hover(function(){A(this).stop().fadeTo(200,0)},function(){A(this).stop().fadeTo(200,0.4)});this.processLink(D,C,E);if(this.compare(E,D.activeItem)){B.hide()}},navigate:function(F,G,B){if(!B&&this.compare(F.currentTarget,G)){return false}F.currentTarget=G;var I=this.getNav(F,F.activeItem,"target");var C=this.getNav(F,G);if(typeof C=="undefined"){return false}else{this.setHash(F,G)}if(!C){if(G[1]>0){A(this.getNav(F,G[0])).unbind("ajaxload").one("ajaxload",function(){A.ajaxNav.navigate(F,G,true)});this.load(F,[G[0],0])}return true}var K=C.target||false;if(!K){A(C).unbind("ajaxload").one("ajaxload",function(){A.ajaxNav.navigate(F,G,true)});this.load(F,G);return true}F.mainNav.filter("a[href='"+this.getNav(F,F.activeItem[0])["url"]+"']").removeClass(F.options.classActive);F.mainNav.filter("a[href='"+this.getNav(F,G[0])["url"]+"']",F.mainNav).addClass(F.options.classActive);F.activeItem=G;var J=parseInt(I.css("left"))-parseInt(K.css("left"));F.left+=J;var E=parseInt(I.css("top"))-parseInt(K.css("top"));F.top+=E;var D=E&&J?600:450;this.processBackLinks(F,K);if(F.options.trackGA&&window.pageTracker&&C.title){try{pageTracker._trackPageview(C.title)}catch(H){if(window.console){console.log("Tracking error in ajaxNav: "+H)}}}if(F.options.useOverlay){I.children(".contentOverlay").show();K.children(".contentOverlay").hide();if(E||J){A.ajaxNav.setPosition(false,D)}if(F.options.onShow){F.options.onShow.apply(K)}}else{if(F.options.fade){I.stop(false,true).fadeOut(D);if(E||J){A.ajaxNav.setPosition(false,D)}K.stop(false,true).fadeIn(D,F.options.onShow||false)}else{if(E||J){A.ajaxNav.setPosition(false,D)}F.options.onShow.apply(K)}}this.setButtons(F);setTimeout(function(){A.ajaxNav.preloadNeighbors(F)},500);return true}};A.fn.ajaxNav=function(B){var C={mainNav:this,activeItem:[-1,-1],options:A.extend({},A.ajaxNav.defaults,B)};A.ajaxNav.init(C)}})(jQuery);