/*______________________________________________________________________
|        ______   |
|      /      /   |
|     /    O /    |      ___________________________________________
|    /    / /     |
|   /    / /  /|  |       U I Z E     J A V A S C R I P T     A P I
|  /____/ /__/_|  |      ___________________________________________
|            |__  |
|_________________|
|
|           TITLE : Uize.Widget.ImageSwap Object
|         VERSION : 1.0
|            TYPE : Object Definition
|          AUTHOR : Chris van Rensburg (http://www.tomkidding.com)
|       COPYRIGHT : (c)2005 Chris van Rensburg
|     DESCRIPTION : Implements a JavaScript object for swapping images with dissolve support
|        REQUIRES : Uize.Widget.js (base class)
|                   Uize.Element.js
|                   Uize.Fade.js
|_______________________________________________________________________*/
(function(){var c_a=true,c_b=false,c_c=Uize.Element;var c_d=Uize.Widget.ImageSwap=Uize.Widget.subclass(function(){var c_e=this;
c_e.c_f=0;c_e.c_g=c_b;c_e.c_h=[0,0,0,0];c_e.fade=new Uize.Fade({duration:1250,acceleration:.5});c_e.fade.addEventHandler('Advance',function(){c_e.c_i(c_e.c_j,c_e.fade.get('progress'))});}),c_k=c_d.prototype;c_k.c_i=function(c_l,c_m){var c_e=this;if(c_e.c_n!=1||c_e.c_o!=1){function c_p(c_q){return c_e.c_r[c_q]+(c_e.c_h[c_q]-c_e.c_r[c_q])*c_m;}var c_s=[c_p(0),c_p(1),c_p(2),c_p(3)],c_t=[0,0];if(c_e.c_u!=='none'||c_e.c_v!=='none'){function c_w(c_x,c_y){function c_z(c_A,c_B,c_C){return c_A+(c_B-c_A)*c_C}if(c_x==='auto')c_x=(c_e.c_r[c_y]+c_e.c_r[c_y+2])/2/c_e.c_h[c_y+2];return c_x==='none'?0:c_z(c_s[0+c_y],c_s[2+c_y]-c_e.c_h[2+c_y],c_x);}c_t[0]=c_w(c_e.c_u,0);c_t[1]=c_w(c_e.c_v,1);c_l.style.left=c_t[0]+'px';c_l.style.top=c_t[1]+'px';}function c_D(c_q){return Math.round(c_s[c_q]-c_t[c_q%2]+Math.floor(c_q/2))+'px '}c_l.style.clip='rect('+c_D(1)+c_D(2)+c_D(3)+c_D(0)+')';}if(c_e.c_E)c_c.setOpacity(c_l,c_m);};c_k.c_F=function(){var c_e=this,c_G=c_e.c_h[2]+1,c_H=c_e.c_h[3]+1,c_I=Math.max(1,c_G*c_e.c_n),
c_J=Math.max(1,c_H*c_e.c_o),c_K=(c_G-c_I)*c_e.c_L,c_M=(c_H-c_J)*c_e.c_N;c_e.c_r=[c_K,c_M,c_K+c_I-1,c_M+c_J-1];};c_d.registerProperties({c_O:'background',c_E:'dissolve',c_P:{name:'src',onChange:function(){var c_e=this;if(c_e.c_g){c_e.fade.stop();var c_j=c_e.getUiElement('image'+c_e.c_f+'Container'),c_Q=1-c_e.c_f,c_R=c_e.getUiElement('image'+c_Q+'Container'),c_S=c_e.getUiElement('image'+c_Q);c_R.style.padding='0px';c_e.c_i(c_j,1);c_e.c_i(c_R,0);var c_T=new Image();c_T.onload=function(){c_R.style.paddingLeft=Math.floor((c_e.c_h[2]+1-c_T.width)/2)+'px';c_R.style.paddingTop=Math.floor((c_e.c_h[3]+1-c_T.height)/2)+'px';function c_U(c_V){c_S.onload=c_S.onerror=c_S.onabort=c_V;}function c_W(){c_S.Uize_Widget_ImageSwap_src=c_e.c_P;c_U(null);c_j.style.zIndex='0';c_R.style.zIndex='1';c_e.c_f=c_Q;c_e.c_j=c_R;c_e.c_F();c_e.fade.start();}if(c_S.Uize_Widget_ImageSwap_src===c_e.c_P){c_W();}else{c_U(c_W);c_S.src=c_e.c_P;}};c_T.src=c_e.c_P;}}},c_u:'viewContentAlignX',c_v:'viewContentAlignY',c_n:'viewSeedSizeX',
c_o:'viewSeedSizeY',c_L:'viewSeedAlignX',c_N:'viewSeedAlignY'});c_d.set({c_O:'#000000',c_E:c_a,html:function(){var c_e=this,c_X=c_c.getById(c_e.get('container')),c_Y=c_c.getDimensions(c_X);c_e.c_h[2]=c_Y.width-1;c_e.c_h[3]=c_Y.height-1;c_e.c_F();if(c_X!=null)c_X.style.overflow='hidden';function c_Z(c_0){return'<div id="[#objectName]_image'+c_0+'Container" style="position:absolute; margin:0px; padding:0px; left:0px; top:0px; width:'+c_Y.width+'px; height:'+c_Y.height+'px; background:'+c_e.c_O+'; overflow:none;"><img id="[#objectName]_image'+c_0+'" src="/inc/blank.gif"/></div>';}c_e.c_g=c_a;return c_Z(0)+c_Z(1);},c_P:'',c_u:'none',c_v:'none',c_n:1,c_o:1,c_L:.5,c_N:.5});})();
