﻿Type.registerNamespace('Kontrolit.Ajax');Kontrolit.Ajax.ImagePopupBehavior=function(element){Kontrolit.Ajax.ImagePopupBehavior.initializeBase(this,[element]);this._targetElement=null;this._mode=null;this._fullSizeText=null;this._fullSizeUrl=null;this._maxSize=null;this._body=null;this._screen=null;this._window=null;this._iframe=null;this._isie=null;this._quirksMode=null;this._isGecko=null;this._needsIframeShim=null;this._actionHandler=null;}
Kontrolit.Ajax.ImagePopupBehavior.prototype={initialize:function(){Kontrolit.Ajax.ImagePopupBehavior.callBaseMethod(this,'initialize');if(typeof document.getElementById=='undefined'||typeof document.createElement=='undefined')return;this._targetElement=this.get_element();this._isie=typeof document.uniqueID!='undefined'&&this._getInternetExplorerVersion()<=7;this._quirksMode=(this._isie||typeof window.opera!='undefined')&&(typeof document.compatMode=='undefined'||document.compatMode!='CSS1Compat');this._isGecko=navigator.product=='Gecko'&&navigator.vendor!='Apple Computer, Inc.'&&navigator.vendor!='KDE';this._needsIframeShim=this._isGecko||(typeof document.uniqueID!='undefined'&&typeof window.XMLHttpRequest=='undefined');this._body=document.getElementsByTagName('body')[0];this._actionHandler=Function.createDelegate(this,this._onAction);$addHandler(this._targetElement,this.get_Mode()==0?'click':'mouseover',this._actionHandler);},dispose:function(){$removeHandler(this._targetElement,this.get_Mode()==0?'click':'mouseover',this._actionHandler);Kontrolit.Ajax.ImagePopupBehavior.callBaseMethod(this,'dispose');},_onAction:function(e){if(this._screen)
this._removeLoadingScreen();else{this._showLoadingScreen();var img=new Image;$addHandler(img,'load',Function.createDelegate(this,function(){this._showImageWindow(img,this._targetElement);}));img.onerror=Function.createDelegate(this,function(){this._removeLoadingScreen();});img.src=this.get_FullSizeUrl()!=''?this.get_FullSizeUrl():this._targetElement.href;}
e.preventDefault();},_showLoadingScreen:function(){if(this._screen)return;this._screen=document.createElement('div');this._screen.id='imagePopupLoadingScreen';this._screen.appendChild(document.createTextNode('Loading image ...'));this._body.appendChild(this._screen);var canvas=this._getCanvasSize();var scrolling=this._getScrollingOffset();this._screen.style.width=canvas.width+'px';this._screen.style.paddingTop=(canvas.height/2)+'px';this._screen.style.height=(canvas.height/(this._quirksMode&&this._isie?1:2))+'px';this._screen.style.left=scrolling.left+'px';this._screen.style.top=scrolling.top+'px';$addHandler(this._screen,'click',Function.createDelegate(this,function(){this._removeImageWindow();this._removeLoadingScreen();}));this._screen.style.visibility='visible';},_removeLoadingScreen:function(){if(!this._screen)return;this._screen.parentNode.removeChild(this._screen);this._screen=null;},_showImageWindow:function(img,link){if(this._window)return;this._window=document.createElement('div');this._window.id='imagePopupImageWindow';var canvas=this._getCanvasSize();var scrolling=this._getScrollingOffset();var imgWidth=img.width;var imgHeight=img.height;if(imgWidth>imgHeight){if(imgWidth>canvas.width*this.get_MaxSize()){imgHeight=img.height*((canvas.width*this.get_MaxSize())/imgWidth);imgWidth=canvas.width*this.get_MaxSize();}}else{if(imgHeight>canvas.height*this.get_MaxSize()){imgWidth=imgWidth*((canvas.height*this.get_MaxSize())/imgHeight);imgHeight=canvas.height*this.get_MaxSize();}}
var imgLink=document.createElement('a');imgLink.href=this._targetElement.href;var newImg=imgLink.appendChild(document.createElement('img'));newImg.setAttribute('src',img.src);newImg.setAttribute('title',this.get_FullSizeText());newImg.setAttribute('width',imgWidth);newImg.setAttribute('height',imgHeight);this._window.appendChild(imgLink);var controls=document.createElement('ul');var li=controls.appendChild(document.createElement('li'));li.className='fullScreen';var fullScreen=li.appendChild(document.createElement('a'));fullScreen.setAttribute('href',this._targetElement.href);fullScreen.setAttribute('title',this.get_FullSizeText());fullScreen.appendChild(document.createTextNode(this.get_FullSizeText()));li=controls.appendChild(document.createElement('li'));li.className='close';var close=li.appendChild(document.createElement('a'));close.setAttribute('href','javascript:void("Close the image window")');close.setAttribute('title','Close the image window');close.appendChild(document.createTextNode('Close'));this._window.appendChild(controls);$addHandler(close,'click',Function.createDelegate(this,function(){this._removeImageWindow();this._removeLoadingScreen();}));this._body.appendChild(this._window);if(this._isie){controls.style.width=imgWidth+'px';if(controls.offsetWidth<200)
controls.style.width='200px';}
this._window.style.left=(((canvas.width-this._window.offsetWidth)/2)+scrolling.left)+'px';this._window.style.top=(((canvas.height-this._window.offsetHeight)/2)+scrolling.top)+'px';this._screen.style.backgroundImage='none';this._screen.removeChild(this._screen.firstChild);this._showIframeShim();this._window.style.visibility='visible';},_removeImageWindow:function(){if(!this._window)return;this._window.parentNode.removeChild(this._window);this._window=null;this._removeIframeShim();},_showIframeShim:function(){if(!this._needsIframeShim||!this._window||this._iframe)return;this._iframe=document.createElement('iframe');this._iframe.id='imagePopupIframeShim';this._iframe.src='javascript:false;';this._iframe.tabIndex='-1';this._body.appendChild(this._iframe);this._iframe.style.left=this._screen.style.left;this._iframe.style.top=this._screen.style.top;this._iframe.style.width=this._screen.offsetWidth+'px';this._iframe.style.height=this._screen.offsetHeight+'px'
this._iframe.style.visibility='visible';},_removeIframeShim:function(){if(!this._iframe)return;this._iframe.parentNode.removeChild(this._iframe);this._iframe=null;},_getCanvasSize:function(){if(typeof window.innerWidth!='undefined'){var canvas={'width':window.innerWidth,'height':window.innerHeight};if(this._isGecko){if(this._body.offsetHeight>canvas.height)
canvas.width-=17;else
canvas.width-=1;canvas.height-=1;}}else if(this._quirksMode){canvas={'width':document.body.clientWidth,'height':document.body.clientHeight};}else{canvas={'width':document.documentElement.offsetWidth-(this._needsIframeShim?21:0),'height':document.documentElement.offsetHeight};}
return canvas;},_getScrollingOffset:function(){if(typeof window.pageXOffset!='undefined'){var scrolling={'left':window.pageXOffset,'top':window.pageYOffset};}else if(this._quirksMode){scrolling={'left':document.body.scrollLeft,'top':document.body.scrollTop};}else{scrolling={'left':document.documentElement.scrollLeft,'top':document.documentElement.scrollTop};}
return scrolling;},_getInternetExplorerVersion:function(){var rv=-1;if(navigator.appName=='Microsoft Internet Explorer'){var ua=navigator.userAgent;var re=new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");if(re.exec(ua)!=null)
rv=parseFloat(RegExp.$1);}
return rv;},get_Mode:function(){return this._mode;},set_Mode:function(value){this._mode=value;},get_FullSizeText:function(){return this._fullSizeText;},set_FullSizeText:function(value){this._fullSizeText=value;},get_FullSizeUrl:function(){return this._fullSizeUrl;},set_FullSizeUrl:function(value){this._fullSizeUrl=value;},get_MaxSize:function(){return this._maxSize;},set_MaxSize:function(value){this._maxSize=value;}}
Kontrolit.Ajax.ImagePopupBehavior.registerClass('Kontrolit.Ajax.ImagePopupBehavior',AjaxControlToolkit.BehaviorBase);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();