/*!
 * Copyright 2006 - 2014 TubePress LLC (http://tubepress.com).
 * This file is part of TubePress (http://tubepress.com).
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
var tubePressDomInjector,tubePressBeacon,TubePress=(function(e,d){var n="tubepress",l="urls",c="base",f="sys",h="js",o=d.location,m=d.document,q=true,p="src/main/web/js",s=e.isFunction,g=d.TubePressJsConfig,i=null,r=false,a=(function(){var z=function(E){return typeof E!=="undefined"},B=function(F){F=F.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var E="[\\?&]"+F+"=([^&#]*)",H=new RegExp(E),G=H.exec(o.search);return G===i?"":decodeURIComponent(G[1].replace(/\+/g," "))},A=function(E){var F=parseInt(E,10);return isNaN(F)?0:F},y=function(H,G,E){if(G()===q){H();return}var F=function(){y(H,G,E)};setTimeout(F,E)},D=function(H){if(!H){return r}var E=Array.prototype.slice.call(arguments),G=E.shift(),F;for(F=0;F<E.length;F+=1){if(!G.hasOwnProperty(E[F])){return r}G=G[E[F]]}return true},C=function(E,F){if(F){return E.replace(/^\/+/,"")}return E.replace(/\/+$/,"")};return{isDefined:z,getParameterByName:B,parseIntOrZero:A,callWhenTrue:y,hasOwnNestedProperty:D,trimSlashes:C}}()),x=(function(){var A=o.search.indexOf(n+"_debug=true")!==-1,D=d.console,y=a.isDefined(D),z=function(){return A&&y},C=function(E){D.log(n+": "+E)},B=function(E){D.dir(E)};return{on:z,log:C,dir:B}}()),u=(function(){var z=r,B="usr",y,D=function(){if(!z){if(a.hasOwnNestedProperty(g,l,c)){y=a.trimSlashes(g[l][c],r)}else{var F=m.getElementsByTagName("script"),E=0,G;for(E;E<F.length;E+=1){G=F[E].src;if(G.indexOf("/"+n+".js")!==-1){y=a.trimSlashes(G.substr(0,G.lastIndexOf("/")).split("?")[0].replace(p,""),r);break}}}}return y},A=function(){var E="ajaxEndpoint",F="php";if(a.hasOwnNestedProperty(g,l,F,f,E)){return g[l][F][f][E]}return D()+"/src/main/web/php/"+E+".php"},C=function(){if(a.hasOwnNestedProperty(g,l,B)){return g[l][B]}return D()+"/"+n+"-content"};return{getBaseUrl:D,getAjaxEndpointUrl:A,getUserContentUrl:C}}()),w=(function(){var z=e({}),y=function(){z.bind.apply(z,arguments)},B=function(){z.unbind.apply(z,arguments)},A=function(){if(x.on()){var C=arguments;x.log("firing event "+C[0]);if(C.length>1){x.dir(C[1])}}z.trigger.apply(z,arguments)};return{subscribe:y,unsubscribe:B,publish:A}}()),j=(function(){var D=[],B=function(J){return D[J]===q},y=function(K,J){if(K.indexOf("http")===0){return K}var L;if(J){L=u.getBaseUrl()}else{L=u.getUserContentUrl()}return L+"/"+a.trimSlashes(K,true)},H=function(K,J){if(x.on()){x.log("Injecting "+J+": "+K)}},I=function(J){m.getElementsByTagName("head")[0].appendChild(J)},G=function(L,J){J=a.isDefined(J)?J:true;L=y(L,J);if(B(L)){return}D[L]=q;var K=m.createElement("link");K.rel="stylesheet";K.type="text/css";K.href=L;H(L,"CSS");I(K)},z=function(L,K){K=a.isDefined(K)?K:true;L=y(L,K);if(B(L)){return}D[L]=q;H(L,"JS");var J=m.createElement("script");J.type="text/javascript";J.src=L;J.async=q;m.getElementsByTagName("head")[0].appendChild(J)},A=function(J){if(a.hasOwnNestedProperty(g,l,h,f,J)){z(g[l][h][f][J])}else{z(p+"/"+J+".js")}},F=function(){A("gallery")},E=function(){A("playerApi")},C=function(){A("ajaxSearch")};return{loadJs:z,loadCss:G,loadGalleryJs:F,loadPlayerApiJs:E,loadAjaxSearchJs:C}}()),t=(function(){var y=function(B,C){var A=x.on(),E,z=d[B],D=function(F){var H=F[0],G=F.slice(1);C[H].apply(this,G)};if(a.isDefined(z)){E=z.length;if(A){x.log("Running "+E+" queue items for "+B)}z.reverse();while(z.length){D(z.pop())}}if(A){x.log(B+" is now connected")}d[B]={push:D}};return{processQueueCalls:y}}()),k=(function(){var y=e.fn.jquery,B=/1\.6|7|8|9\.[0-9]+/.test(y)!==r,A,z=function(C){return A(C)};if(B){A=function(C){return e.parseJSON(C)}}else{A=function(C){if(typeof C!=="string"||!C){return i}C=e.trim(C);if(/^[\],:{}\s]*$/.test(C.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){return(d.JSON&&d.JSON.parse)?d.JSON.parse(C):(new Function("return "+C))()}else{throw"Invalid JSON: "+C}}}return{parse:z}}()),v=(function(){var z=function(A){e(A).fadeTo(0,0.3)},y=function(A){e(A).fadeTo(0,1)};return{applyLoadingStyle:z,removeLoadingStyle:y}}()),b=(function(){var A=function(J,D,G,C,F,I){var E=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,H=function(L){var M=L.responseText,K=C?e("<div>").append(M.replace(E,"")).find(C):M;e(G).html(K);if(s(I)){I()}};if(s(F)){F()}e.ajax({url:D,type:J,dataType:"html",complete:H})},z=function(G,D,E,F,C){e.ajax({url:D,type:G,data:E,dataType:C,complete:F})},B=function(C){v.removeLoadingStyle(C)},y=function(I,D,G,C,F,H){var E=function(){B(G)};v.applyLoadingStyle(G);if(s(H)){E=function(){B(G);H()}}A(I,D,G,C,F,E)};return{loadAndStyle:y,get:z}}());(function(){var z,A=function(){w.publish(n+".window.resize")},y=function(){clearTimeout(z);z=setTimeout(A,150)},B=function(){e(d).resize(y)};e(B)}());(function(){var y="tubePress";t.processQueueCalls(y+"DomInjector",j);t.processQueueCalls(y+"Beacon",w)}());return{Ajax:{Executor:b,LoadStyler:v},AsyncUtil:t,Beacon:w,DomInjector:j,Environment:u,Lang:{Utils:a,JsonParser:k},Logger:x}}(jQuery,window));