var ThumbBox=Class.create({initialize:function(){this._placeholder=false;this.isShowing=false;this.views_loaded=false;this._slider=false;this._initpos=false;this._currentpos=0;this._scale=false;},build:function(){var placeholder=new Element('div',{id:'lv_thumbbox'});placeholder.style.display='none';var list=new Element('div',{id:'thumbbox_thumbs'});placeholder.insert(list);document.body.insert(placeholder);this._placeholder=placeholder;this._slider=list;this._placeholder.observe('mousemove',this.move_slider.bindAsEventListener(this));},show:function(){if(!this.isShowing){this.isShowing=true;this._placeholder.appear();}},hide:function(){if(this.isShowing){this._placeholder.hide();this.isShowing=false;this.views_loaded=false;}},load_views:function(views){if(!this.views_loaded){var oList=$('thumbbox_thumbs');oList.style.width='1px';for(var i=0;i<views.length;i++){var img=new Image();Event.observe(img,'load',this.image_loaded.bind(this,img));var oLi=new Element('span');oLi.className='thumbbox-image';oLi.insert(img);oList.insert(oLi);oLi.observe('mouseover',this.hover_thumb);oLi.observe('mouseout',this.unhover_thumb);oLi.observe('click',this.click_thumb);img.src=views[i].href.replace('/big/','/thumbs/');img.hide();}
this.views_loaded=true;}},destroy_thumbs:function(){var t=$('thumbbox_thumbs');var aThumbs=t.select('span.thumbbox-image');for(var i=0;i<aThumbs.length;i++){aThumbs[i].remove();}
this.views_loaded=false;},hover_thumb:function(e){var obj=e.findElement('img');if(!obj)return;obj.addClassName('hover');},unhover_thumb:function(e){var obj=e.findElement('img');if(!obj)return;obj.removeClassName('hover');},click_thumb:function(e){var obj=e.findElement('span');var aViews=Lightview.views;var aLi=obj.up('div').select('span');var n=0;for(var i=0;i<aLi.length;i++){if(aLi[i]==obj){n=i;}}
Lightview.show(aViews[n]);Lightview.position=n;Lightview.thumbbox.set_active(n);},set_active:function(n){if(n>=0){var aImg=this._placeholder.select('img');aImg.each(function(el){el.removeClassName('active');if(!el.visible())el.show();});aImg[n].addClassName('active');this.scroll_into_view(aImg[n]);}
this.calculate();},image_loaded:function(img){var listWidth=parseInt(this._slider.style.width);var t=parseInt((85/parseInt(img.height))*parseInt(img.width));img.style.height='85px';img.style.width=t+"px";this._slider.style.width=(listWidth+t+6)+"px";img.show();this.calculate();},move_slider:function(e){if(!this._scalefactor||!this._initpos){this.calculate();}
var t=parseInt((e.clientX-this._initpos)*this._scalefactor);if(parseInt(this._slider.clientWidth)<parseInt(this._placeholder.clientWidth)){return;}
this._currentpos=t;this._slider.style.left=-(t)+"px";},scroll_into_view:function(img){if(!this._scalefactor||!this._initpos){this.calculate();}
var IO=img.offsetLeft;var CP=this._currentpos;var IP=this._initpos;var PW=this._placeholder.getWidth();var IW=img.getWidth();if((IO+IW)-CP>PW){CP=PW-(IO+IW);this._slider.style.left=(CP)+"px";this._currentpos=-(CP);}
if(IO-CP<0){this._slider.style.left=-(IO)+"px";this._currentpos=IO;}},calculate:function(){this._scalefactor=parseInt(parseInt(this._slider.clientWidth)-(parseInt(this._placeholder.clientWidth)))/parseInt(this._placeholder.clientWidth);this._initpos=parseInt(this._placeholder.offsetLeft);}});if(typeof('Lightview')!='undefined'){Lightview.__show=Lightview.show;Lightview.__buildController=Lightview.buildController;Lightview.__getViews=Lightview.getViews;Lightview.__updateViews=Lightview.updateViews;Lightview.__getBounds=Lightview.getBounds;Lightview.__hide=Lightview.hide;Lightview.thumbbox=false;Lightview.load_thumbbox=false;Lightview.slider=false;Lightview.prototype=Object.extend(Lightview,{show:function(t){this.__show(t);if(this.load_thumbbox){this.thumbbox.show();this.thumbbox.set_active(this.position);}
var aSifr=$$('object, embed');for(var i=0;i<aSifr.length;i++){aSifr[i].hide();aSifr[i].addClassName('sifr_hidden');};},buildController:function(){this.__buildController();if(!this.thumbbox&&(navigator.appVersion.search(/MSIE [4-6]{1}/)==-1)){this.thumbbox=new ThumbBox;this.thumbbox.build();}},getViews:function(v){var t=this.__getViews(v);if(t.length>1&&this.thumbbox){this.load_thumbbox=true;this.thumbbox.load_views(t);}
return t;},updateViews:function(){if(this.load_thumbbox){this.thumbbox.destroy_thumbs();}
this.__updateViews();},getBounds:function(){var t=this.__getBounds();if(this.load_thumbbox){t.height=t.height-100;}
return t;},hide:function(){if(this.load_thumbbox){this.thumbbox.destroy_thumbs();this.thumbbox.hide();this.load_thumbbox=false;}
var aSifr=$$('object, embed');for(var i=0;i<aSifr.length;i++){if(aSifr[i].hasClassName('sifr_hidden')){aSifr[i].show();aSifr[i].removeClassName('sifr_hidden');}}
this.__hide();}});}
