/*
 * Mosiac Server general-purpose API wrapper, a component of the 
 * Gloto Platform.  See www.gloto.com for more information,
 * terms, and licensing.
 *
 * Copyright (C) 2005-2010, Gloto Corp.
 * http://www.gloto.com/terms.htm
 */
var Gloto={};Gloto.Api=function(d,c){Gloto.api=this;this.apiKey=d;var e="http://ugc.gloto.com:80/mosaic/api/rest/";var b="http://ugc.gloto.com/api/rest/";function a(f,h,g){this.fullUrl=f;this.callback=h;this.errorCallback=g;this.noCacheIE="&noCacheIE="+(new Date()).getTime();this.headLoc=document.getElementsByTagName("head").item(0);this.scriptId="JscriptId"+a.scriptCounter++}a.scriptCounter=1;a.callbacks={};a.prototype.buildScriptTag=function(){this.scriptObj=document.createElement("script");this.scriptObj.setAttribute("type","text/javascript");this.scriptObj.setAttribute("charset","utf-8");this.scriptObj.setAttribute("src",this.fullUrl+this.noCacheIE+"&scriptId="+this.scriptId+"&callback=Gloto.api.dataHandler");this.scriptObj.setAttribute("id",this.scriptId)};a.prototype.removeScriptTag=function(){this.headLoc.removeChild(this.scriptObj)};a.prototype.addScriptTag=function(){this.headLoc.appendChild(this.scriptObj)};this.dataHandler=function(g){var h=g.scriptId;var f=a.callbacks[h];delete a.callbacks[h];if(f.errorCallback instanceof Function&&g.status!="ok"){f.errorCallback(g)}else{if(f.callback instanceof Function){f.callback(g)}}f.removeScriptTag()};this.call=function(l,j,k,f){var g=e+"?method="+encodeURIComponent(l)+"&apiKey="+encodeURI(Gloto.api.apiKey);for(param in j){g+="&"+encodeURIComponent(param)+"="+encodeURIComponent(j[param])}var h=new a(g,k,f);a.callbacks[h.scriptId]=h;h.buildScriptTag();h.addScriptTag()};this.callMosaic=this.call;this.callUgc=function(l,j,k,f){var g=b+"?method="+encodeURIComponent(l)+"&apiKey="+encodeURI(Gloto.api.apiKey);for(param in j){g+="&"+encodeURIComponent(param)+"="+encodeURIComponent(j[param])}var h=new a(g,k,f);a.callbacks[h.scriptId]=h;h.buildScriptTag();h.addScriptTag()}};function Mosaic(d,c){var b=this;this.viewerMovedListeners=[];this.viewerCenteredListeners=[];this.viewerZoomedListeners=[];this.viewer=(typeof d=="string")?document.getElementById(d):d;c=c||{};this.tileUrlProvider=c.tileUrlProvider||new Mosaic.TileUrlProvider(c.tileBaseUri||"tiles",c.tilePrefix||"tile-",c.tileExtension||"jpg");this.tileSize=c.tileSize||256;this.surfaceClassName=c.surfaceClassName||"surface";this.wellClassName=c.wellClassName||"tiles";this.controlsClassName=c.controlsClassName||"controls";this.tileClassName=c.tileClassName||"tile";this.initialPan=c.initialPan||{x:0.5,y:0.5};this.padding=c.padding||{x:20,y:20};this.fadeTiles=c.fadeTiles||false;if(c.pinchZoomSupport){this.touchManager=new Mosaic.TouchManager(this);this.touchManager.register()}else{this.touchManager={supressClick:false}}this.clampToCenter=c.clampToCenter||false;this.initializeCallback=c.initializeCallback;this.clickCallback=c.clickCallback;this.showSlideshowDetail=c.showSlideshowDetail||function(){};this.hideSlideshowDetail=c.hideSlideshowDetail||function(){};this.addViewerMovedListener(c.moveCallback);this.addViewerZoomedListener(c.zoomCallback);this.zoomLevel=c.initialZoom||1;this.minZoomLevel=Math.abs(c.minZoom||1);this.maxZoomLevel=Math.abs(c.maxZoom||8);if(this.zoomLevel>this.maxZoomLevel){this.zoomLevel=this.maxZoomLevel}this.initialized=false;this.surface=null;this.well=null;this.width=0;this.height=0;this.top=0;this.left=0;this.x=0;this.y=0;this.border=-1;this.mark={x:0,y:0};this.pressed=false;this.tiles=[];this.cache={};this.preferredSize=c.preferredSize;this.preferredCenter=c.preferredCenter;this.indicators=c.indicators||{};var e=c.blankTile||"images/blank.gif";var a=c.loadingTile||"images/blank.gif";this.cache.blank=new Image();this.cache.blank.src=e;if(e!=a){this.cache.loading=new Image();this.cache.loading.src=a}else{this.cache.loading=this.cache.blank}this.moveCount=0;this.slideMonitor=0;this.slideAcceleration=0;this.slideshowCount=0;this.slideshowPaused=false;this.slideshowTimeout;Mosaic.viewer=this;Mosaic.Util.addEventListener(window,"resize",function(){b.resize()},false);Mosaic.Util.registerWheelListener(function(f){b.zoom(f>0?1:(f<0)?-1:0)},true)}Mosaic.MSG_BEYOND_MIN_ZOOM=null;Mosaic.MSG_BEYOND_MAX_ZOOM=null;Mosaic.USE_LOADER_IMAGE=true;Mosaic.USE_SLIDE=true;Mosaic.USE_KEYBOARD=true;Mosaic.MOVE_THROTTLE=3;Mosaic.SLIDE_DELAY=40;Mosaic.SLIDE_ACCELERATION_FACTOR=5;Mosaic.MAX_ACCELERATION=null;Mosaic.SLIDESHOW_ZOOM_INTERVAL=800;Mosaic.DOM_ONLOAD=(navigator.userAgent.indexOf("KHTML")>=0?false:true);Mosaic.prototype={setSize:function(b,c,a){if(typeof b!="number"||b<0){b=0}this.border=b;if(!c&&!a){if(window.innerWidth){c=window.innerWidth;a=window.innerHeight}else{c=(document.compatMode=="CSS1Compat"?document.documentElement.clientWidth:document.body.clientWidth);a=(document.compatMode=="CSS1Compat"?document.documentElement.clientHeight:document.body.clientHeight)}}else{this.fixedSize={width:c,height:a}}c=Math.max(c-2*b,0);a=Math.max(a-2*b,0);if(c%2){c--}if(a%2){a--}this.width=c;this.height=a;this.viewer.style.width=this.width+"px";this.viewer.style.height=this.height+"px";this.viewer.style.top=b+"px";this.viewer.style.left=b+"px"},init:function(e,a,h){this.setSize(e,a,h);if(document.attachEvent){document.body.ondragstart=function(){return false}}if(this.width===0&&this.height===0){this.width=this.viewer.offsetWidth;this.height=this.viewer.offsetHeight}var c=this.tileSize;if(this.zoomLevel>-1&&this.zoomLevel<=this.maxZoomLevel){c=this.tileSize*Math.pow(2,this.zoomLevel)}else{this.zoomLevel=-1;c=this.tileSize/2;do{this.zoomLevel+=1;c*=2}while(c<Math.max(this.width,this.height));if(this.zoomLevel>this.maxZoomLevel){var g=this.zoomLevel-this.maxZoomLevel;this.zoomLevel=this.maxZoomLevel;c/=Math.pow(2,g)}}if(!this.preferredSize){this.preferredSize={width:c,height:c}}if(this.preferredCenter){var j=Math.pow(2,this.zoomLevel-1);this.x=Math.floor(this.width/2)-(this.preferredCenter.x*j);this.y=Math.floor(this.height/2)-(this.preferredCenter.y*j);this.clampOrigin(this)}else{this.x=Math.floor((this.width-this.preferredSize.width)*this.initialPan.x);this.y=Math.floor((this.height-this.preferredSize.height)*this.initialPan.y)}for(var d=this.viewer;d;d=d.offsetParent){this.top+=d.offsetTop;this.left+=d.offsetLeft}for(var b=this.viewer.firstChild;b;b=b.nextSibling){if(b.className==this.surfaceClassName){this.surface=b;b.backingBean=this}else{if(b.className==this.wellClassName){this.well=b;b.backingBean=this}else{if(b.className==this.controlClassName){for(var f=b.firstChild;f;f=f.nextSibling){if(f.className){f.onclick=Mosaic[f.className+"Handler"]}}}}}}this.viewer.backingBean=this;this.prepareTiles();this.initialized=true;if(this.initializeCallback){this.initializeCallback()}},prepareTiles:function(){var d=Math.ceil(this.height/this.tileSize)+1;var f=Math.ceil(this.width/this.tileSize)+1;for(var g=0;g<f;g++){var e=[];for(var b=0;b<d;b++){var a={element:null,posx:0,posy:0,xIndex:g,yIndex:b,qx:g,qy:b};e.push(a)}this.tiles.push(e)}this.surface.onmousedown=Mosaic.mousePressedHandler;this.surface.onmouseup=this.surface.onmouseout=Mosaic.mouseReleasedHandler;this.surface.ondblclick=Mosaic.doubleClickHandler;if(Mosaic.USE_KEYBOARD){window.onkeypress=Mosaic.keyboardMoveHandler;window.onkeydown=Mosaic.keyboardZoomHandler}this.positionTiles({x:0,y:0})},clampOrigin:function(c){var b=this;var f=function(k,h,l,m){var j=(h-k);if((h-k)<(l-(2*m))){if(b.clampToCenter){m=(l-h+k)/2}if(k<m){return m}else{if(h>(l-m)){return(l-m-j)}}}else{if(k>=m){return m}else{if(h<=(l-m)){return(l-m-j)}}}return k};var e=Math.pow(2,viewer.zoomLevel-1);var d={x:c.x+(viewer.preferredSize.width*e),y:c.y+(viewer.preferredSize.height*e)};var a=f(c.x,d.x,viewer.width,viewer.padding.x);var g=f(c.y,d.y,viewer.height,viewer.padding.y);if(a!=c.x||g!=c.y){c.x=a;c.y=g;return true}return false},clampMotion:function(a){if(a&&(a.x||a.y)){var b={x:viewer.x+a.x,y:viewer.y+a.y};if(this.clampOrigin(b)){a.x=b.x-viewer.x;a.y=b.y-viewer.y;return true}}return false},positionTiles:function(a,e){a=a||{x:0,y:0};var g=this.clampMotion(a);for(var h=0;h<this.tiles.length;h++){for(var d=0;d<this.tiles[h].length;d++){var b=this.tiles[h][d];b.posx=(b.xIndex*this.tileSize)+this.x+a.x;b.posy=(b.yIndex*this.tileSize)+this.y+a.y;var f=true;if(b.posx>this.width){do{b.xIndex-=this.tiles.length;b.posx=(b.xIndex*this.tileSize)+this.x+a.x}while(b.posx>this.width);if(b.posx+this.tileSize<0){f=false}}else{while(b.posx<-this.tileSize){b.xIndex+=this.tiles.length;b.posx=(b.xIndex*this.tileSize)+this.x+a.x}if(b.posx>this.width){f=false}}if(b.posy>this.height){do{b.yIndex-=this.tiles[h].length;b.posy=(b.yIndex*this.tileSize)+this.y+a.y}while(b.posy>this.height);if(b.posy+this.tileSize<0){f=false}}else{while(b.posy<-this.tileSize){b.yIndex+=this.tiles[h].length;b.posy=(b.yIndex*this.tileSize)+this.y+a.y}if(b.posy>this.height){f=false}}if(!this.initialized){this.assignTileImage(b,true);b.element.style.top=b.posy+"px";b.element.style.left=b.posx+"px"}if(f){this.assignTileImage(b)}b.element.style.top=b.posy+"px";b.element.style.left=b.posx+"px"}}if(e){this.x+=a.x;this.y+=a.y}},assignTileImage:function(g,c){var h,a;var d=(c?true:false);var b=Math.pow(2,this.zoomLevel);var m=this.preferredSize?(this.preferredSize.width*b)/(2*this.tileSize):b;var e=this.preferredSize?(this.preferredSize.height*b)/(2*this.tileSize):b;if(!d){if((g.xIndex<0)||(g.yIndex<0)||(g.xIndex>=m)||(g.yIndex>=e)){d=true}}if(d){h="blank:"+g.qx+":"+g.qy;a=this.cache.blank.src}else{h=a=this.tileUrlProvider.assembleUrl(g.xIndex,g.yIndex,this.zoomLevel)}if(g.element&&g.element.parentNode&&g.element.relativeSrc!=a){this.well.removeChild(g.element)}var k=this.cache[h];if(!k){k=this.cache[h]=this.createPrototype(a)}if(d||!Mosaic.USE_LOADER_IMAGE||k.complete||(k.image&&k.image.complete)){k.onload=function(){};if(k.image){k.image.onload=function(){}}if(!k.parentNode){g.element=this.well.appendChild(k)}}else{var j="loading:"+g.qx+":"+g.qy;var f=this.cache[j];if(!f){f=this.cache[j]=this.createPrototype(this.cache.loading.src)}f.targetSrc=h;g.element=this.well.appendChild(f);var l=this;k.onload=function(){if(f.parentNode&&f.targetSrc==h){k.style.top=f.style.top;k.style.left=f.style.left;if(l.fadeTiles){k.style.display="none";Mosaic.Util.fade(k)}l.well.replaceChild(k,f);g.element=k}k.onload=function(){};return false};if(!Mosaic.DOM_ONLOAD){k.image=new Image();k.image.onload=k.onload;k.image.src=k.src}}},showIndicator:function(l,a,n,c){var k=Mosaic.Util.getElement(l.element,true);var b=Mosaic.Util.asArray(n);for(key in b){var e=b[key];a=this.isVisible(a,e);if(a){var o=Math.pow(2,this.zoomLevel-1);var f=(l.size-o)/2;c=c||{x:0,y:0};var j=this.x+(o*e.x)-f-c.x;var h=this.y+(o*e.y)-f-c.y;var g=l.size/2;var m=l.extension||".gif";if(this.inRange(j+g,0,this.width)&&this.inRange(h+g,0,this.height)){var d=Mosaic.Util.createElement({type:"img",className:"indicator",parentNode:k,src:"images/"+l.baseFileName+"-"+o+m});d.style.left=j+"px";d.style.top=h+"px"}else{}}}k.tileId=a?n:null},createPrototype:function(b){var a=document.createElement("img");a.src=b;a.relativeSrc=b;a.className=this.tileClassName;a.style.width=this.tileSize+"px";a.style.height=this.tileSize+"px";return a},addViewerMovedListener:function(a){if(a){this.viewerMovedListeners.push(a)}},addViewerCenteredListener:function(a){if(a){this.viewerCenteredListeners.push(a)}},addViewerZoomedListener:function(a){if(a){this.viewerZoomedListeners.push(a)}},clearViewerCenteredListeners:function(){this.viewerCenteredListeners=[]},notifyViewerZoomed:function(){var a=(100/(this.maxZoomLevel+1))*(this.zoomLevel+1);for(var b=0;b<this.viewerZoomedListeners.length;b++){this.viewerZoomedListeners[b]({x:this.x,y:this.y,level:this.zoomLevel,percentage:a})}},notifyViewerMoved:function(d){d=d||{x:0,y:0};var b=this.mark.motion||{x:0,y:0};var a={x:this.x+(d.x-this.mark.x),y:this.y+(d.y-this.mark.y)};this.mark.lastNotify=a;for(var c=0;c<this.viewerMovedListeners.length;c++){this.viewerMovedListeners[c]({x:a.x,y:a.y,dx:a.x-this.x-b.x,dy:a.y-this.y-b.y,point:d})}this.mark.motion={x:a.x-this.x,y:a.y-this.y}},notifyViewerCentered:function(){for(var a=0;a<this.viewerCenteredListeners.length;a++){this.viewerCenteredListeners[a]()}},zoom:function(d){if(this.zoomLevel+d<this.minZoomLevel){if(Mosaic.MSG_BEYOND_MIN_ZOOM){alert(Mosaic.MSG_BEYOND_MIN_ZOOM)}return}else{if(this.zoomLevel+d>this.maxZoomLevel){if(Mosaic.MSG_BEYOND_MAX_ZOOM){alert(Mosaic.MSG_BEYOND_MAX_ZOOM)}return}}this.blank();var b=this.preferredCenter||this.getCenterTile();this.zoomLevel+=d;var c=Math.pow(2,this.zoomLevel-1);var a={x:Math.floor(this.width/2)-(b.x*c),y:Math.floor(this.height/2)-(b.y*c)};this.clampOrigin(a);this.x=a.x;this.y=a.y;this.positionTiles({x:0,y:0});this.notifyViewerZoomed()},clear:function(){this.blank();this.initialized=false;this.tiles=[]},blank:function(){for(imgId in this.cache){var a=this.cache[imgId];a.onload=function(){};if(a.image){a.image.onload=function(){}}if(a.parentNode){this.well.removeChild(a)}}},setPreferredCenter:function(b){var a=b?{x:(b.x-this.x),y:(b.y-this.y)}:null;this.preferredCenter=this.getCenterTile(a)},moveViewer:function(b){var a={x:(b.x-this.mark.x),y:(b.y-this.mark.y)};this.positionTiles(a);this.setPreferredCenter({x:this.x+Math.floor(this.width/2-(this.x+a.x)),y:this.y+Math.floor(this.height/2-(this.y+a.y))});this.notifyViewerMoved({x:a.x+this.mark.x,y:a.y+this.mark.y});this.mark.x=b.x-a.x;this.mark.y=b.y-a.y},getCenterTile:function(a){function d(g,f,e){return g<f?f:(g>e?e:g)}a=a||{x:Math.floor(this.width/2-this.x),y:Math.floor(this.height/2-this.y)};var b=Math.pow(2,this.zoomLevel-1);var c={x:d(Math.floor(a.x/b),0,preferredSize.width),y:d(Math.floor(a.y/b),0,preferredSize.height)};return c},setCenterTile:function(b){var c=Mosaic.Util.asArray(b);var a=this.width,h=this.height,f=0,e=0;for(key in c){var g=c[key];a=Math.min(a,g.x);h=Math.min(h,g.y);f=Math.max(f,g.x);e=Math.max(e,g.y)}var d=Math.pow(2,this.zoomLevel-1);while(((f-a)*d>this.width)||((e-h)*d>this.height)){this.zoom(-1);d=Math.pow(2,this.zoomLevel-1)}this.recenter({x:(a+f)*d/2,y:(h+e)*d/2},true)},recenter:function(d,f,g){if(this.slideshowPaused){return}if(f){d.x+=this.x;d.y+=this.y}var j={x:Math.floor((this.width/2)-d.x),y:Math.floor((this.height/2)-d.y)};if(!g){this.setPreferredCenter(d)}if(this.clampMotion(j)){d.x=Math.floor((this.width/2)-j.x);d.y=Math.floor((this.height/2)-j.y)}if(j.x||j.y){if(Mosaic.USE_SLIDE){var a=j;var e,c;if(a.x===0){e=0;c=this.slideAcceleration}else{var b=Math.abs(a.y/a.x);e=Math.round(Math.pow(Math.pow(this.slideAcceleration,2)/(1+Math.pow(b,2)),0.5));c=Math.round(b*e)}j={x:Math.min(e,Math.abs(a.x))*(a.x<0?-1:1),y:Math.min(c,Math.abs(a.y))*(a.y<0?-1:1)}}this.positionTiles(j,true);this.notifyViewerMoved();if(Mosaic.USE_SLIDE){var h=this;if(Mosaic.MAX_ACCELERATION==null||(Mosaic.MAX_ACCELERATION&&this.slideAcceleration<Mosaic.MAX_ACCELERATION)){this.slideAcceleration+=Mosaic.SLIDE_ACCELERATION_FACTOR}this.slideMonitor=setTimeout(function(){h.recenter({x:d.x+j.x,y:d.y+j.y},false,true)},Mosaic.SLIDE_DELAY)}}else{this.notifyViewerCentered()}},startSlideshow:function(){this.slideshowCount=0;var a=this;clearTimeout(this.slideshowTimeout);this.slideshowTimeout=setTimeout(function(){if(a.zoomLevel<4){a.zoom(1);a.startSlideshow()}else{if(a.zoomLevel>4){a.zoom(-1);a.startSlideshow()}else{a.centerSlideshowTile()}}},Mosaic.SLIDESHOW_ZOOM_INTERVAL)},toggleSlideshow:function(b){if(this.slideshowPaused){this.hideSlideshowDetail();clearTimeout(this.slideshowTimeout);this.slideshowPaused=false;this.startSlideshow()}else{this.slideshowPaused=true;clearTimeout(this.slideshowTimeout);var a=this;this.slideshowTimeout=setTimeout(function(){a.toggleSlideshow(b)},b)}},focusSlideshowTile:function(c,b){Mosaic.MAX_ACCELERATION=null;Mosaic.SLIDE_ACCELERATION_FACTOR=b;if(this.indicators&&this.indicators.highlight){this.showIndicator(this.indicators.highlight,true,c,null)}var e=4;var d=false;if(this.slideshowCount!=0&&this.slideshowCount%3==0){if(this.slideshowCount==6){e=2;d=true}else{e=Mosaic.Util.random(2,4)}}var a=this;function f(){if(a.zoomLevel<6){a.slideshowTimeout=setTimeout(function(){a.zoom(1);f()},Mosaic.SLIDESHOW_ZOOM_INTERVAL)}else{function g(){a.hideSlideshowDetail();if(a.zoomLevel>e){a.slideshowTimeout=setTimeout(function(){a.zoom(-1);g()},Mosaic.SLIDESHOW_ZOOM_INTERVAL)}else{a.slideshowCount++;a.slideshowTimeout=setTimeout(function(){if(d){a.centerSlideshow()}else{a.centerSlideshowTile()}},1000)}}for(var h=0;h<70;h++){setTimeout(function(){Mosaic.viewer.panDown()},600+(h*8))}setTimeout(function(){a.showSlideshowDetail(c[0])},700);a.slideshowTimeout=setTimeout(g,8000)}}this.slideshowTimeout=setTimeout(f,1000)},centerSlideshow:function(){this.slideshowCount=0;if(this.indicators&&this.indicators.highlight){this.showIndicator(this.indicators.highlight,false)}var c={x:Math.floor(preferredSize.width/2),y:Math.floor(preferredSize.height/2)};var b=[c];var a=this;this.addViewerCenteredListener(function(){a.clearViewerCenteredListeners();a.slideshowTimeout=setTimeout(function(){a.startSlideshow()},17000)});this.setCenterTile(c)},centerSlideshowTile:function(){Mosaic.MAX_ACCELERATION=30;var b=Mosaic.SLIDE_ACCELERATION_FACTOR;this.slideAcceleration=0;Mosaic.SLIDE_ACCELERATION_FACTOR=1;if(this.indicators&&this.indicators.highlight){this.showIndicator(this.indicators.highlight,false)}var f=Mosaic.Util.random(0,preferredSize.width);var e=Mosaic.Util.random(0,preferredSize.height);var d={x:f,y:e};var c=[d];var a=this;this.addViewerCenteredListener(function(){a.clearViewerCenteredListeners();a.slideshowTimeout=setTimeout(function(){a.focusSlideshowTile(c,b)},200)});this.setCenterTile(d)},resize:function(){if(this.initialized&&!this.fixedSize){var a={x:Math.floor(this.width/2),y:Math.floor(this.height/2)};this.setSize(this.border);this.recenter(a)}},resolveCoordinates:function(a){return{x:(a.pageX||(a.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft)))-this.left,y:(a.pageY||(a.clientY+(document.documentElement.scrollTop||document.body.scrollTop)))-this.top}},press:function(a){this.activate(true);this.mark=a},release:function(b){this.activate(false);var a={x:(b.x-this.mark.x),y:(b.y-this.mark.y)};if(this.touchManager.suppressClick){this.touchManager.suppressClick=false}else{if(a.x===0&&a.y===0&&this.clickCallback){this.clickCallback({coords:b,absolute:{x:b.x-this.x,y:b.y-this.y},zoom:this.zoomLevel})}}this.x+=a.x;this.y+=a.y;this.mark={x:0,y:0}},activate:function(a){this.pressed=a;this.surface.onmousemove=(a?Mosaic.mouseMovedHandler:function(){})},pointExceedsBoundaries:function(a){return(a.x<this.x||a.y<this.y||a.x>(this.tileSize*Math.pow(2,this.zoomLevel)+this.x)||a.y>(this.tileSize*Math.pow(2,this.zoomLevel)+this.y))},inRange:function(c,b,a){return(c>=b)&&(c<a)},panDown:function(){viewer.positionTiles({x:0,y:-Mosaic.MOVE_THROTTLE},true);Mosaic.viewer.notifyViewerMoved()},panRight:function(){viewer.positionTiles({x:-Mosaic.MOVE_THROTTLE,y:0},true);Mosaic.viewer.notifyViewerMoved()},panUp:function(){viewer.positionTiles({x:0,y:Mosaic.MOVE_THROTTLE},true);Mosaic.viewer.notifyViewerMoved()},panLeft:function(){viewer.positionTiles({x:Mosaic.MOVE_THROTTLE,y:0},true);Mosaic.viewer.notifyViewerMoved()},isVisible:function(b,a){return(b&&this.inRange(a.x,0,preferredSize.width)&&this.inRange(a.y,0,preferredSize.height))}};Mosaic.TileUrlProvider=function(b,a,c){this.baseUri=b;this.prefix=a;this.extension=c};Mosaic.TileUrlProvider.prototype={assembleUrl:function(b,a,c){return this.baseUri+"/"+this.prefix+c+"-"+b+"-"+a+"."+this.extension+(Mosaic.REVISION_FLAG?"?r="+Mosaic.REVISION_FLAG:"")}};Mosaic.mousePressedHandler=function(c){c=c?c:window.event;if(c.button<2){var a=this.backingBean;var b=a.resolveCoordinates(c);if(a.pointExceedsBoundaries(b)){c.cancelBubble=true}else{a.press(b)}}return false};Mosaic.mouseReleasedHandler=function(b){b=b?b:window.event;var a=this.backingBean;if(a.pressed){a.release(a.resolveCoordinates(b))}};Mosaic.mouseMovedHandler=function(b){b=b?b:window.event;var a=this.backingBean;a.moveCount++;if(a.moveCount%Mosaic.MOVE_THROTTLE===0){a.moveViewer(a.resolveCoordinates(b))}};Mosaic.zoomInHandler=function(b){b=b?b:window.event;var a=this.parentNode.parentNode.backingBean;a.zoom(1);return false};Mosaic.zoomOutHandler=function(b){b=b?b:window.event;var a=this.parentNode.parentNode.backingBean;a.zoom(-1);return false};Mosaic.doubleClickHandler=function(c){c=c?c:window.event;var a=this.backingBean;var b=a.resolveCoordinates(c);if(!a.pointExceedsBoundaries(b)){if(a.slideMonitor){clearTimeout(this.slideMonitor);a.slideMonitor=0}a.slideAcceleration=0;a.recenter(b)}};Mosaic.keyboardMoveHandler=function(a){a=a?a:window.event;if(a.keyCode==40){Mosaic.viewer.panDown()}if(a.keyCode==39){Mosaic.viewer.panRight()}if(a.keyCode==38){Mosaic.viewer.panUp()}if(a.keyCode==37){Mosaic.viewer.panLeft()}};Mosaic.keyboardZoomHandler=function(a){a=a?a:window.event;if(a.keyCode==109){Mosaic.viewer.zoom(-1)}if(a.keyCode==107){Mosaic.viewer.zoom(1)}};Mosaic.TouchManager=function(d){var a=this;this.suppressClick=false;var c=null;function b(e){c={x:e.pageX,y:e.pageY}}this.register=function(){document.body.ontouchstart=function(f){if(f.touches.length==1){b(f.touches[0])}};document.body.ontouchmove=function(g){g.preventDefault();if(g.touches.length==1){a.suppressClick=true;var h=g.touches[0];var f={x:h.pageX-c.x,y:h.pageY-c.y};d.positionTiles(f,true);d.setPreferredCenter({x:d.x+Math.floor(d.width/2-(d.x+f.x)),y:d.y+Math.floor(d.height/2-(d.y+f.y))});Mosaic.viewer.notifyViewerMoved();b(h)}};document.body.ongesturestart=function(f){c=null};document.body.ongestureend=function(f){if(f.scale!=1){d.zoom((f.scale>1)?1:-1)}}}};Mosaic.Util={addEventListener:function(d,c,e,b){var a=true;if(d.addEventListener){d.addEventListener(c,e,b)}else{if(d.attachEvent){a=d.attachEvent("on"+c,e,b)}else{d["on"+c]=e}}return a},registerWheelListener:function(c,a){function b(d){var e=0;if(!d){d=window.event}if(d.wheelDelta){e=d.wheelDelta/120;if(window.opera){e=-e}}else{if(d.detail){e=-d.detail/3}}if(e){c(e)}if(d.preventDefault){d.preventDefault()}d.returnValue=false}if(window.addEventListener){window.addEventListener("DOMMouseScroll",b,false)}window.onmousewheel=document.onmousewheel=b},findTarget:function(c,a){var b;if(window.event){b=window.event.srcElement}else{if(c){b=c.target}else{b=window}}if(!a&&b.nodeType==3){b=b.parentNode}return b},getMousePosition:function(b){var a=0;var c=0;if(!b){b=window.event}if(b.pageX||b.pageY){a=b.pageX;c=b.pageY}else{if(b.clientX||b.clientY){a=b.clientX+document.body.scrollLeft;c=b.clientY+document.body.scrollTop}}return{x:a,y:c}},asArray:function(a){if(a&&a.constructor.toString().indexOf("Array")==-1){return[a]}else{return a}},closure:function(a,b){return function(){a(b)}},setIf:function(b,d,c){c=Mosaic.Util.asArray(c);for(i in c){var a=c[i];if(d[a]){b.setAttribute(a,d[a])}}},clear:function(a){var b=this.getElement(a);if(b){while(b.firstChild){b.removeChild(b.firstChild)}return b}else{return null}},getElement:function(c,b){var a;if(typeof(c)=="string"){a=document.getElementById(c)}else{a=c}if(a&&b){this.clear(a)}return a},toggle:function(a){a=Mosaic.Util.getElement(a);if(a.style.display!="none"){a.style.display="none"}else{a.style.display="block"}},createElement:function(c){var b=c.type||"span";var a=document.createElement(b);if(c.text){a.innerHTML=c.text}this.setIf(a,c,["id","name","value","href","src","style","disabled","target","title","size","multiple","rows","cols","wrap","width","height","align","valign","cellpadding","cellspacing","border"]);if(c.className){a.setAttribute("class",c.className);a.setAttribute("className",c.className)}if(c.onclick){a.onclick=c.onclick}if(c.onmouseover){a.onmouseover=c.onmouseover}if(c.onmouseout){a.onmouseout=c.onmouseout}if(c.onchange){a.onchange=c.onchange}if(c.onfocus){a.onfocus=c.onfocus}if(c.onblur){a.onblur=c.onblur}if(c.childNode){a.appendChild(c.childNode)}if(c.parentNode){this.getElement(c.parentNode).appendChild(a)}return a},opacity:function(a,b){a=Mosaic.Util.getElement(a);if(b!==undefined){a.style.opacity=b;a.style["-ms-filter"]="progid:DXImageTransform.Microsoft.Alpha(opacity="+b*100+")";a.style.filter="alpha(opacity="+b*100+")";a.style.zoom=1}return Number(a.style.opacity)},fade:function(b){function a(d){var e=Mosaic.Util.opacity(d);if(e<1){Mosaic.Util.opacity(d,e+0.1);setTimeout(function(){a(d)},20)}}b=Mosaic.Util.getElement(b);var c=b.style.display=="block";if(!c){Mosaic.Util.opacity(b,0);b.style.display="block";a(b)}else{b.style.display="none"}},crop:function(d,g,f,b,c,e,a){d=Mosaic.Util.getElement(d);if(a){a=a/(b-g);g=Math.floor(a*g);b=Math.ceil(a*b);d.style.height=a+"px"}if(e){e=e/(c-f);f=Math.floor(e*f);c=Math.ceil(e*c);d.style.width=e+"px"}d.style.clip="rect("+g+"px,"+c+"px,"+b+"px,"+f+"px)";d.style.position="absolute";d.style.left=-f;d.style.top=-g},random:function(a,b){return Math.floor(a+(Math.random()*(b-a)))}};

