/*
 * @require jade/compat/Widget.js
 * @require jade/compat/ImagePreloader.js
 * @require jade/Schedular.js
 * @require jade/ThumbnailUtils.js
 */
jade.compat.ImageSelectionRow=function(a,b){jade.compat.Widget.call(this,a,b);this.items=[];this.imageLoader=new jade.compat.ImagePreloader};
jade.inherit(jade.compat.ImageSelectionRow,jade.compat.Widget);jade.compat.ImageSelectionRow.DIRECTION_NONE=0;jade.compat.ImageSelectionRow.DIRECTION_FORWARD=1;jade.compat.ImageSelectionRow.DIRECTION_BACKWARD=2;jade.compat.ImageSelectionRow.prototype.imageLoader=null;jade.compat.ImageSelectionRow.prototype.items=null;jade.compat.ImageSelectionRow.prototype.visibleItems=5;jade.compat.ImageSelectionRow.prototype.zoomFactor=0.65;jade.compat.ImageSelectionRow.prototype.space=20;
jade.compat.ImageSelectionRow.prototype.horizontalMargin=0;jade.compat.ImageSelectionRow.prototype.verticalMargin=20;jade.compat.ImageSelectionRow.prototype.animSteps=10;jade.compat.ImageSelectionRow.prototype.animDelay=25;jade.compat.ImageSelectionRow.prototype.geometries=null;jade.compat.ImageSelectionRow.prototype.selected=0;jade.compat.ImageSelectionRow.prototype.animationInProgress=!1;jade.compat.ImageSelectionRow.prototype.selectionBorderWidth="3";
jade.compat.ImageSelectionRow.prototype.selectionBorder="";jade.compat.ImageSelectionRow.prototype.selectionBorderStyle="solid";jade.compat.ImageSelectionRow.prototype.selectionBorderColor="green";jade.compat.ImageSelectionRow.prototype.useOpacity=!0;jade.compat.ImageSelectionRow.prototype.offsetX=20;jade.compat.ImageSelectionRow.prototype.offsetY=0;jade.compat.ImageSelectionRow.prototype.manualImagePreload=!1;jade.compat.ImageSelectionRow.prototype.autoRotate=null;
jade.compat.ImageSelectionRow.prototype.preparedDrawData=null;jade.compat.ImageSelectionRow.prototype.itemContainer=null;jade.compat.ImageSelectionRow.prototype.createElements=function(a){var b;this.itemContainer=document.createElement("div");b=this.itemContainer.style;b.display="block";b.position="relative";b.overflow="hidden";a.appendChild(this.itemContainer);jade.compat.Widget.prototype.createElements.call(this,a)};
jade.compat.ImageSelectionRow.prototype.importItems=function(a,b){var c,d;b===void 0&&(b=this.getSelectedItemName());this.removeAllItems();for(c=0,d=a.length;c<d;c++)this.addItem(a[c][0],a[c][1],a[c][2],a[c][3],a.length==5?a[4]:void 0);this.start(b)};
jade.compat.ImageSelectionRow.prototype.addItem=function(a,b,c,d,e){var f,g;this.isBusy()||this.busy();f={name:a,image:b,origWidth:c,origHeight:d,hide:!0,containerElement:null,innerElement:null,geometry:null,clone:e?!0:!1,border:!1};jade.compat.application.getImagesNeedAlphaHack()?(f.innerElement=document.createElement("div"),g=f.innerElement.style,g.width="100%",g.height="100%",g.background="#ccc",g.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+b+"', sizingMethod='scale')",f.containerElement=
document.createElement("div"),g=f.containerElement.style,g.background="none",g.filter="alpha(opacity=100)",f.innerElement.selector=this,f.innerElement.onclick=this.handleImageClick,f.innerElement.ondblclick=this.handleImageDblClick,f.containerElement.appendChild(f.innerElement)):(f.containerElement=document.createElement("img"),f.containerElement.src=b,g=f.containerElement.style,f.containerElement.selector=this,f.containerElement.onmousedown=function(){return!1},
f.containerElement.onclick=this.handleImageClick,f.containerElement.ondblclick=this.handleImageDblClick);f.containerElement.className="imageSelectionRowItem";g.position="absolute";g.display="block";g.visibility="hidden";this.items.push(f);!this.manualImagePreload&&!f.clone&&this.imageLoader.addImageURL(b)};
jade.compat.ImageSelectionRow.prototype.removeAllItems=function(a){var b;for(b=this.itemContainer.childNodes.length-1;b>=0;b--)this.itemContainer.childNodes[b].className=="imageSelectionRowItem"&&this.itemContainer.removeChild(this.itemContainer.childNodes[b]);if(a===void 0||!a)this.items=[]};
jade.compat.ImageSelectionRow.prototype.start=function(a){var b,c;if(this.items.length!==0){for(;this.items.length<this.visibleItems+2;)for(b=0,c=this.items.length;b<c;b++)this.addItem(this.items[b].name,this.items[b].image,this.items[b].origWidth,this.items[b].origHeight,!0);a&&this.setSelectedItemName(a);this.getAutoDrag()&&(this.connect("dragStart",this.handleDragStart,this,!0),this.connect("dragEnd",this.handleDragEnd,this,!0));this.ready();this.invalidate()}};
jade.compat.ImageSelectionRow.prototype.calculatePositions=function(){var a,b,c,d,e,f,g,h;h=this.itemContainer.style;h.top=this.verticalMargin+this.offsetY+"px";h.height=this.getHeight()-this.verticalMargin*2+"px";h.marginLeft=this.horizontalMargin+"px";h.width=this.getWidth()-this.horizontalMargin*2+"px";this.geometries=[];e=1;f=this.zoomFactor;g=this.visibleItems;for(a=1,b=(g-1)/2;a<=b;a++)e+=f*2,f*=this.zoomFactor;e=(this.getWidth()-this.space*(this.visibleItems-1)-this.offsetX*2)/e;c=0;g+=2;for(a=
(-g+1)/2,b=(g-1)/2;a<=b;a++)d={},f=Math.pow(this.zoomFactor,Math.abs(a)),d.width=e*f,d.height=(this.getHeight()-this.verticalMargin*2-this.selectionBorderWidth*2)*f,d.y=(this.getHeight()-d.height-this.verticalMargin*2-this.selectionBorderWidth*2)/2,d.x=c+this.space*(a+(g-1)/2),d.factor=f,c+=d.width,this.geometries.push(d);for(a=0,b=this.geometries.length-1;a<=b;a++)d=this.geometries[a],d.x-=this.geometries[0].width+this.space};
jade.compat.ImageSelectionRow.prototype.prepareDrawData=function(a){var b,c,d,e;this.preparedDrawData={};this.removeAllItems(!0);d=this.visibleItems+2;this.preparedDrawData.i=-d+1>>1;this.preparedDrawData.max=d-1>>1;this.preparedDrawData.geometry=[];this.preparedDrawData.nextGeometry=[];this.preparedDrawData.itemIndex=[];this.preparedDrawData.hide=[];for(b=this.preparedDrawData.i,c=this.preparedDrawData.max;b<=c;b++)e=b+(d-1>>1),this.preparedDrawData.geometry[b]=this.geometries[e],this.preparedDrawData.nextGeometry[b]=
a==jade.compat.ImageSelectionRow.DIRECTION_BACKWARD?e>0?this.geometries[e-1]:this.geometries[0]:e<this.geometries.length-1?this.geometries[e+1]:this.geometries[this.geometries.length-1],this.preparedDrawData.itemIndex[b]=(b+(d-1)/2+this.selected-(d-1)/2+this.items.length)%this.items.length,this.preparedDrawData.hide[b]=b==(-d+1)/2||b==(d-1)/2,this.itemContainer.appendChild(this.items[this.preparedDrawData.itemIndex[b]].containerElement)};
jade.compat.ImageSelectionRow.prototype.draw=function(a){var b,c,d,e,f,g,h,i,j,m,k,n,o,l;if(this.items.length!==0){for(b=0;b<this.items.length;b++)this.items[b].hide=!0;for(b=this.preparedDrawData.i,c=this.preparedDrawData.max;b<=c;b++){f=this.preparedDrawData.itemIndex[b];d=this.preparedDrawData.geometry[b];e=this.preparedDrawData.nextGeometry[b];g=this.items[f];n=d.width-(d.width-e.width)*Math.abs(a)/100;o=d.height-(d.height-e.height)*Math.abs(a)/100;m=d.x-(d.x-e.x)*Math.abs(a)/100;k=d.y-(d.y-e.y)*
Math.abs(a)/100;l=d.factor-(d.factor-e.factor)*Math.abs(a)/100;j=jade.ThumbnailUtils.getThumbnailData(g.origWidth,g.origHeight,n,o);m+=j.x+this.offsetX;k+=j.y;i=g.containerElement.style;i.left=m+"px";i.top=k+"px";i.width=j.width+"px";i.height=j.height+"px";i.visibility="visible";i.border=g.border?this.selectionBorderWidth+"px "+this.selectionBorderStyle+" "+this.selectionBorderColor:"none";if(this.useOpacity)i.opacity=l,i.filter="alpha(opacity="+Math.round(l*100)+")";h=g.innerElement?g.innerElement:
g.containerElement;if(a===0){h.index=f;h.selectionSteps=b;g.geometry={x:m,y:k,width:j.width,height:j.height};if(g.innerElement)h.style.background="#ccc";g.hide=!a&&this.preparedDrawData.hide[b]}else if(g.innerElement)h.style.background="none"}}};
jade.compat.ImageSelectionRow.prototype.handleImageClick=function(a,b,c){this.selector?this.selector.handleImageClick(a?a:window.event,this.index,this.selectionSteps):(this.changeBorderStatus(b),this.sendSignal("selected",this.items[b].name),c!==0&&(c<0?this.backward(Math.abs(c)):this.forward(Math.abs(c))))};
jade.compat.ImageSelectionRow.prototype.handleImageDblClick=function(a,b,c){if(this.selector)return this.selector.handleImageDblClick(a?a:window.event,this.index,this.selectionSteps);c<1&&this.sendSignal("dblClicked",this.items[b].name);return!1};
jade.compat.ImageSelectionRow.prototype.changeBorderStatus=function(a){var b,c;for(b=0,c=this.items.length;b<c;b++)this.items[b].border=!1;if(a!==null)this.items[a].border=!0};
jade.compat.ImageSelectionRow.prototype.forward=function(a){if(!this.animationInProgress&&this.items.length){if(++this.selected>=this.items.length)this.selected=0;a===void 0&&(this.changeBorderStatus(this.selected),this.sendSignal("selected",this.getSelectedItemName()));this.prepareDrawData(jade.compat.ImageSelectionRow.DIRECTION_FORWARD);this.animForward(-100,a)}};
jade.compat.ImageSelectionRow.prototype.startAutoRotation=function(a){this.autoRotate=a;this.changeBorderStatus(null);this.autoRotation()};
jade.compat.ImageSelectionRow.prototype.stopAutoRotation=function(){if(this.autoRotate)this.autoRotate=null,this.changeBorderStatus(this.selected),this.sendSignal("selected",this.getSelectedItemName())};
jade.compat.ImageSelectionRow.prototype.autoRotation=function(){this.autoRotate==jade.compat.ImageSelectionRow.DIRECTION_FORWARD&&(this.forward(0),jade.Schedular.schedule(this.animDelay,this.autoRotation,this));this.autoRotate==jade.compat.ImageSelectionRow.DIRECTION_BACKWARD&&(this.backward(0),jade.Schedular.schedule(this.animDelay,this.autoRotation,this))};
jade.compat.ImageSelectionRow.prototype.backward=function(a){if(!this.animationInProgress&&this.items.length){if(--this.selected<0)this.selected=this.items.length-1;a===void 0&&(this.changeBorderStatus(this.selected),this.sendSignal("selected",this.getSelectedItemName()));this.prepareDrawData(jade.compat.ImageSelectionRow.DIRECTION_BACKWARD);this.animBackward(100,a)}};
jade.compat.ImageSelectionRow.prototype.animForward=function(a,b){a=Math.min(0,a+this.animSteps);this.draw(a);a?(this.animationInProgress=!0,jade.Schedular.schedule(this.animDelay,this.animForward,this,a,b)):(this.animationInProgress=!1,--b>0&&this.forward(b))};
jade.compat.ImageSelectionRow.prototype.animBackward=function(a,b){a=Math.max(0,a-this.animSteps);this.draw(a);a?(this.animationInProgress=!0,jade.Schedular.schedule(this.animDelay,this.animBackward,this,a,b)):(this.animationInProgress=!1,--b>0&&this.backward(b))};
jade.compat.ImageSelectionRow.prototype.getSelectedItemName=function(){return this.items[this.selected].name};
jade.compat.ImageSelectionRow.prototype.setSelectedItemName=function(a){var b,c,d;d=0;for(b=0,c=this.items.length;b<c;b++)if(this.items[b].name==a){d=b;break}this.selected=d;this.changeBorderStatus(d);this.sendSignal("selected",a)};
jade.compat.ImageSelectionRow.prototype.setVisibleItems=function(a){this.visibleItems=a};
jade.compat.ImageSelectionRow.prototype.getVisibleItems=function(){return this.visibleItems};
jade.compat.ImageSelectionRow.prototype.setZoomFactor=function(a){this.zoomFactor=a};
jade.compat.ImageSelectionRow.prototype.getZoomFactor=function(){return this.zoomFactor};
jade.compat.ImageSelectionRow.prototype.setSpace=function(a){this.space=a};
jade.compat.ImageSelectionRow.prototype.getSpace=function(){return this.space};
jade.compat.ImageSelectionRow.prototype.setMargin=function(a,b){b===void 0&&(b=a);this.horizontalMargin=a;this.verticalMargin=b};
jade.compat.ImageSelectionRow.prototype.getMargin=function(){return[this.horizontalMargin,this.verticalMargin]};
jade.compat.ImageSelectionRow.prototype.setAnimSteps=function(a){this.animSteps=a};
jade.compat.ImageSelectionRow.prototype.getAnimSteps=function(){return this.animSteps};
jade.compat.ImageSelectionRow.prototype.setAnimDelay=function(a){this.animDelay=a};
jade.compat.ImageSelectionRow.prototype.getAnimDelay=function(){return this.animDelay};
jade.compat.ImageSelectionRow.prototype.setSelectionBorder=function(a,b,c){this.selectionBorderWidth=a;this.selectionBorderStyle=b;this.selectionBorderColor=c};
jade.compat.ImageSelectionRow.prototype.getSelectionBorder=function(){return this.selectionBorder};
jade.compat.ImageSelectionRow.prototype.setUseOpacity=function(a){this.useOpacity=a};
jade.compat.ImageSelectionRow.prototype.getUseOpacity=function(){return this.useOpacity};
jade.compat.ImageSelectionRow.prototype.setOffsetY=function(a){this.offsetY=a};
jade.compat.ImageSelectionRow.prototype.getOffsetY=function(){return this.offsetY};
jade.compat.ImageSelectionRow.prototype.setOffsetX=function(a){this.offsetX=a};
jade.compat.ImageSelectionRow.prototype.getOffsetX=function(){return this.offsetX};
jade.compat.ImageSelectionRow.prototype.getSelectedItemSize=function(){return{width:parseInt(this.items[this.selected].origWidth),height:parseInt(this.items[this.selected].origHeight)}};
jade.compat.ImageSelectionRow.prototype.getSelectedItemImage=function(){return this.items[this.selected].containerElement.cloneNode(!0)};
jade.compat.ImageSelectionRow.prototype.getSelectedItemGeometry=function(){return this.items[this.selected].geometry};
jade.compat.ImageSelectionRow.prototype.handleDragStart=function(a,b,c){var d,e;if(this.items.length&&(e=this.getSelectedItemGeometry(),d=this.getSelectedItemImage(),b>=e.x&&b<=e.x+e.width&&c>=e.y&&c<=e.y+e.height))d.id=this.getName()+"_dragImg",d.style.position="absolute",d.style.border="none",d.startDragPos={x:b-e.x-3,y:c-e.y-3},this.sendSignal("imgDragStart",d),jade.compat.application.connect("dragOver",this.handleAppDragOver,this)};
jade.compat.ImageSelectionRow.prototype.handleDragEnd=function(a){jade.compat.application.disconnect("dragOver",this.handleAppDragOver,this);this.sendSignal("imgDragEnd")};
jade.compat.ImageSelectionRow.prototype.handleAppDragOver=function(a,b,c,d){this.sendSignal("imgDragging",b,c,d)};
jade.compat.ImageSelectionRow.prototype.getItemsQuantity=function(){return this.items.length};
jade.compat.ImageSelectionRow.prototype.getFirstItemName=function(){return this.items.length?this.items[0].name:""};
jade.compat.ImageSelectionRow.prototype.preloadVisibleImages=function(){var a,b;this.sendSignal("preloadImages","start");this.imageLoader.cancelLoading();this.imageLoader.connect("completed",this.handleImageLoaderCompleted,this);for(a=0,b=this.items.length;a<b;a++)this.items[a].hide||this.imageLoader.addImageURL(this.items[a].image);jade.Schedular.schedule(1,this.imageLoader.start,this.imageLoader)};
jade.compat.ImageSelectionRow.prototype.setManualImagePreload=function(a){this.manualImagePreload=a;this.imageLoader.setAutoStart(!a)};
jade.compat.ImageSelectionRow.prototype.handleImageLoaderCompleted=function(a){this.sendSignal("preloadImages","end");this.imageLoader.disconnect("completed",this.handleImageLoaderCompleted,this)};
jade.compat.ImageSelectionRow.prototype.paint=function(){if(!(this.items.length==0||this.getWidth()==0||this.getHeight()==0)&&this.isReady())this.calculatePositions(),this.prepareDrawData(jade.compat.ImageSelectionRow.DIRECTION_NONE),this.draw(0)};
