/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:24
*/
KISSY.add("imagezoom/base",function(d,h,k,i,m,n,g,j,a){function c(a){return d.require("component/uibase/"+a)}return n.UIBase.extend([c("boxrender"),c("contentboxrender"),c("positionrender"),c("loadingrender"),6==i.ie?c("shimrender"):null,c("align"),c("maskrender"),j],{initializer:function(){var a=this,c;(c=a.image=a.get("imageNode"))&&j.__imgOnLoad(c,function(){a.imageWrap||(a._render(),a._bind())})},destructor:function(){this.imageWrap&&(this.image.insertBefore(this.imageWrap,a),this.imageWrap.remove())},
show:function(){this.render();this.set("visible",!0)},hide:function(){this.set("visible",!1)},_render:function(){var b=this.image;this.imageWrap=(new g(d.substitute("<span class='{wrapClass}'></span>",{wrapClass:this.get("wrapClass")}))).insertBefore(b,a);this.imageWrap.prepend(b);this.get("showIcon")&&(this.icon=new g(d.substitute("<span class='{iconClass}'></span>",{iconClass:this.get("iconClass")})),this.imageWrap.append(this.icon))},_bind:function(){var b=this,c;b.image.on("mouseenter",function(e){if(b.get("hasZoom")){var f=
b.image.offset();b.set("imageLeft",f.left);b.set("imageTop",f.top);c=d.later(function(){b.set("currentMouse",e);b.show();var f=b.get("align");f.node||(f.node=b.image);b.__set("align",a);b.set("align",f);c=a},50)}}).on("mouseleave",function(){c&&(c.cancel(),c=a)});b.on("afterVisibleChange",function(a){a.newVal?(a=b.icon)&&a.hide():(a=b.icon)&&a.show()})},_uiSetHasZoom:function(a){a?(a=this.icon)&&a.show():(a=this.icon)&&a.hide()},_uiSetImageWidth:function(a){this.image.width(a)},_uiSetImageHeight:function(a){this.image.height(a)}},
{ATTRS:{imageNode:{setter:function(a){return g.one(a)}},wrapClass:{value:"ks-imagezoom-wrap"},width:{valueFn:function(){return this.get("imageWidth")}},height:{valueFn:function(){return this.get("imageHeight")}},imageWidth:{valueFn:function(){var a=this.get("imageNode");return(a=a&&a.width())||400}},imageHeight:{valueFn:function(){var a=this.get("imageNode");return(a=a&&a.height())||400}},imageLeft:{},imageTop:{},hasZoom:{value:!0,setter:function(a){return!!a}},showIcon:{value:!0},iconClass:{value:"ks-imagezoom-icon"},
prefixCls:{value:"ks-"}}})},{requires:"dom,event,ua,anim,component,node,./zoomer".split(",")});KISSY.add("imagezoom",function(d,h){return h},{requires:["imagezoom/base"]});
KISSY.add("imagezoom/zoomer",function(d,h,k){function i(){var a;!this.get("bigImageWidth")||this.get("bigImageHeight");if((a=this.get("bigImageSrc"))&&this.get("preload"))(new Image).src=a;this._isInner=this.get("type")===n}function m(a,c){var b=a[0];b&&b.complete&&b.clientWidth?c():b.onload=function(){setTimeout(c,100)}}var n="inner",g=Math.round,j=Math.min;i.ATTRS={elCls:{value:"ks-imagezoom-viewer"},type:{value:"standard"},preload:{value:!0},bigImageSrc:{valueFn:function(){var a=this.get("imageNode");
if(a)return a.attr("data-ks-imagezoom")}},bigImageWidth:{},bigImageHeight:{},currentMouse:{},lensClass:{value:"ks-imagezoom-lens"},lensHeight:{},lensWidth:{},lensTop:{},lensLeft:{}};d.augment(i,{__renderUI:function(){var a=this,c=a.get("contentEl"),b;b=a.bigImage=(new h('<img src="'+a.get("bigImageSrc")+'" />')).appendTo(c,k);a._isInner?(a.set("align",{node:a.image,points:["cc","cc"]}),a._bigImageCopy=(new h('<img src="'+a.image.attr("src")+'" width="'+a.get("bigImageWidth")+'" height="'+a.get("bigImageHeight")+
'"/>')).prependTo(c,k)):a.lens=(new h('<span class="'+a.get("lensClass")+'"></span>')).appendTo(a.imageWrap,k).hide();a.loading();m(b,function(){a.unloading();if(a._bigImageCopy){a._bigImageCopy.remove();a._bigImageCopy=null}})},__bindUI:function(){var a=this,c=d.one("body");a.on("afterVisibleChange",function(b){b.newVal?(a._isInner&&a._anim(0.4),c.on("mousemove",a._mouseMove,a)):((b=a.lens)&&b.hide(),c.detach("mousemove",a._mouseMove,a))})},__destructor:function(){d.one("body").detach("mousemove",
this._mouseMove,this)},_setLensSize:function(){var a=this.get("width"),c=this.get("height"),b=this.get("bigImageWidth"),l=this.get("bigImageHeight"),e=this.get("imageWidth"),f=this.get("imageHeight");this.set("lensWidth",j(g(e*a/b),e));this.set("lensHeight",j(g(f*c/l),f))},_setLensOffset:function(a){this._setLensSize();if(a=a||this.get("currentMouse")){var c=this.get("imageLeft"),b=this.get("imageTop"),l=this.get("imageWidth"),e=this.get("imageHeight"),f=this.get("lensWidth"),g=this.get("lensHeight"),
d=a.pageX-f/2,a=a.pageY-g/2;d<=c?d=c:d>=l+c-f&&(d=l+c-f);a<=b?a=b:a>=e+b-g&&(a=e+b-g);this.set("lensLeft",d);this.set("lensTop",a)}},_mouseMove:function(a){var c=this.get("imageLeft"),b=this.get("imageTop"),d=this.get("imageWidth"),e=this.get("imageHeight");a.pageX>c&&a.pageX<c+d&&a.pageY>b&&a.pageY<b+e?this.set("currentMouse",a):this.hide()},_anim:function(a){var c=this.get("imageLeft"),b=this.get("imageTop"),d=this.get("imageWidth"),e=this.get("imageHeight"),f=this.get("bigImageWidth"),h=this.get("bigImageHeight"),
c=-g((this.get("lensLeft")-c)*f/d),b=-g((this.get("lensTop")-b)*h/e);this.bigImage.stop();this.bigImage.css({width:d,height:e,left:0,top:0});this._bigImageCopy&&this._bigImageCopy.css({width:d,height:e,left:0,top:0});d+=f-d;e+=h-e;this.bigImage.animate({width:d,height:e,left:c,top:b},a);this._bigImageCopy&&this._bigImageCopy.animate({width:d,height:e,left:c,top:b},a)},_uiSetCurrentMouse:function(a){if(a&&"pageX"in a&&this.bigImage&&!this.bigImage.isRunning()&&this.get("hasZoom")){var c=this.lens;
c&&c.show();this._setLensOffset(a);a={left:-g((this.get("lensLeft")-this.get("imageLeft"))*this.get("bigImageWidth")/this.get("imageWidth")),top:-g((this.get("lensTop")-this.get("imageTop"))*this.get("bigImageHeight")/this.get("imageHeight"))};this._bigImageCopy&&this._bigImageCopy.css(a);this.bigImage.css(a)}},_uiSetLensWidth:function(a){this.lens&&this.lens.width(a)},_uiSetLensHeight:function(a){this.lens&&this.lens.height(a)},_uiSetLensTop:function(a){this.lens&&this.lens.offset({top:a})},_uiSetLensLeft:function(a){this.lens&&
this.lens.offset({left:a})},_uiSetBigImageWidth:function(a){a&&this.bigImage&&this.bigImage.width(a);a&&this._bigImageCopy&&this._bigImageCopy.width(a)},_uiSetBigImageHeight:function(a){a&&this.bigImage&&this.bigImage.height(a);a&&this._bigImageCopy&&this._bigImageCopy.height(a)},_uiSetBigImageSrc:function(a){a&&this.bigImage&&this.bigImage.attr("src",a)},changeImageSrc:function(a){this.image.attr("src",a);this._uiSetHasZoom(this.get("hasZoom"));this.loading()}});i.__imgOnLoad=m;return i},{requires:["node"]});
