/*
  SimpleJsMin From YouYee OpenSource 
  2008 - 2009
*/

org.youyee.controls=org.youyee.controls||{};org.youyee.controls.ImagePreviewer={SLIDE_SHOW_TIME:5000,_html:'<img id="yee_ctrls_ip_img"/><span id="yee_ctrls_ip_caption"></span><a id="yee_ctrls_ip_closebtn" href="javascript:;" onclick="YEE.controls.ImagePreviewer.quit(); return false;"><span>x</span> close</a><div style="clear: both;"></div>',_loading:'loading',_lTemp:'',_dataProvider:null,_curIndex:0,_timer:null,_interval:null,_initialized:false,_dom:null,_img:null,_closeBtn:null,_caption:null,_nextBtn:null,_prevBtn:null,_preLoader:null,_curUrl:'',style:{BORDER_LR:10,BORDER_TOP:10,BORDER_BOTTOM:30},className:{IMG_PREVIEWER:'yee_ctrls_ip',IMG_PREVIEWER_IE:'yee_ctrls_ip_ie',LOADING:'yee_ctrls_ip_loading'},temp:{width:0,height:0},initial:function(){if(this._initialized){return;}
this._initialized=true;this._dom=document.createElement('div');this._dom.className=this.className.IMG_PREVIEWER;this._dom.style.width=this._dom.style.height='200px';if(ua.ie||ua.opera){YEE.Dom.addClassName(this._dom,this.className.IMG_PREVIEWER_IE);}
this._dom.style.position='absolute';this._dom.innerHTML=this._html;document.body.appendChild(this._dom);this._img=$('yee_ctrls_ip_img');this._img.style.display='';this._caption=$('yee_ctrls_ip_caption');this._closeBtn=$('yee_ctrls_ip_closebtn');var _self=this;this._preLoader=new Image();this._preLoader.onload=function(){_self.tWidth=_self._preLoader.width;_self.tHeight=_self._preLoader.height;_self._onImgLoaded();}
YEE.Event.addEventListener(document.body,'keydown',function(evt){if(_self._dom.style.display!='none'){var code=YEE.Keys.getKeyCode(evt)
if(code==YEE.Keys.RIGHT||code==YEE.Keys.RIGHT_MAC){_self.next();}else if(code==YEE.Keys.LEFT||code==YEE.Keys.LEFT_MAC){_self.prev();}else if(code==YEE.Keys.ESC){_self.quit();}}});},showImage:function(caption,url){this._dataProvider=[{caption:caption,url:url}];this.setViewIndex(0);this.pauseSlideShow();},_onImgLoaded:function(){this._hideLoadingText();var _self=this;if(typeof(Tween)!='undefined'){var TWEEN_TIME=0.5;var t1=new Tween(_self.temp,'width',Tween.regularEaseOut,this._img.width,this._preLoader.width,TWEEN_TIME);var t2=new Tween(_self.temp,'height',Tween.regularEaseOut,this._img.height,this._preLoader.height,TWEEN_TIME);t1.start();t2.start();_self._img.style.visibility='hidden';t1.onMotionChanged=function(){_self._img.width=_self.temp.width;_self._img.height=_self.temp.height;_self._setSizeByImg(parseInt(_self.temp.width,10),parseInt(_self.temp.height,10));};t1.onMotionFinished=function(){_self._img.style.visibility='';var t=new Tween(_self.temp,'alpha',Tween.regularEaseOut,0,100,TWEEN_TIME);t.onMotionChanged=function(){YEE.Display.setOpacity(_self._img,_self.temp.alpha);};t.start();};_self._img.src=_self._dataProvider[_self._curIndex].url;}else{this._setSizeByImg(this._preLoader.width,this._preLoader.height);this._img.src=this._dataProvider[this._curIndex].url;}
YEE.Dom.removeClassName(this._dom,this.className.LOADING);},_setSizeByImg:function(width,height){if(typeof(width)=='number'){this._dom.style.width=width+this.style.BORDER_LR*2+'px';}
if(typeof(height)=='number'){this._dom.style.height=height+this.style.BORDER_TOP+this.style.BORDER_BOTTOM+'px';}
this._centerPreviewer();},_showLoadingText:function(){var DELAY=500;var _self=this;clearInterval(this._interval);this._interval=setInterval(function(){if(_self._lTemp.length<3){_self._lTemp=[_self._lTemp,'.'].join('');}else{_self._lTemp='';}
_self._caption.innerHTML=[_self._loading,_self._lTemp].join('');},DELAY);},_hideLoadingText:function(){clearInterval(this._interval);this._caption.innerHTML=this._dataProvider[this._curIndex].caption;},_centerPreviewer:function(){YEE.Display.center(this._dom);},setViewIndex:function(index,dataProvider){this.setDataProvider(dataProvider);if(!dataProvider&&!this._dataProvider){return false;}
if(YEE.controls.StageModal){YEE.controls.StageModal.show();}
var showCaption=false;if(!this._initialized||this._dom.style.display=='none'){showCaption=true;}
if(!this._initialized){this.initial();}
if(showCaption){this._caption.innerHTML=dataProvider[index].caption;}else{this._showLoadingText();}
if(index<0){index=0;}
if(index>this._dataProvider.length-1){index=this._dataProvider.length-1;}
this._curIndex=index;if((this._dom.style.display=='none'||showCaption)&&this._curUrl!=this._dataProvider[index].url){this._img.style.visibility='hidden';}
this._curUrl=this._dataProvider[index].url;this._preLoader.src=this._dataProvider[index].url;YEE.Dom.addClassName(this._dom,this.className.LOADING);this._dom.style.display='';this._centerPreviewer();return true;},quit:function(){if(this._dom){this._dom.style.display='none';this._hideLoadingText();}
if(YEE.controls.StageModal){YEE.controls.StageModal.hide();}
this.pauseSlideShow();},setDataProvider:function(dp){if(dp instanceof Array){this._dataProvider=dp;return true;}
return false;},getDataProvider:function(){return this._dataProvider;},playSlideShow:function(){if(!this._timer){this._timer=new org.youyee.utils.Timer(this.SLIDE_SHOW_TIME);var _self=this;this._timer.onTimer=function(){_self.next();};}
this._timer.start();},next:function(){if(this._curIndex==this._dataProvider.length-1){this._curIndex=-1;}
this.setViewIndex(++this._curIndex);},prev:function(){if(this._curIndex==0){this._curIndex=this._dataProvider.length;}
this.setViewIndex(--this._curIndex);},pauseSlideShow:function(){if(this._timer){this._timer.stop();}}};