dojo.provide("memory.ImagePreloader");
dojo.require("dojo.lang.declare");
dojo.declare("memory.ImagePreloader",null,function(_1,_2,_3){
if(arguments.length==0){
return;
}
this.imgUrlBase=_1;
this.callback=_3;
this.nLoaded=0;
this.nProcessed=0;
this.aImages=new Array;
this.nImages=_2.length;
for(var f=0;f<this.nImages;f++){
this.preload(_2[f]);
}
},{preload:function(_5){
var _6=new Image;
this.aImages.push(_6);
_6.onload=dojo.lang.hitch(this,"onload");
_6.onerror=dojo.lang.hitch(this,"onerror");
_6.onabort=dojo.lang.hitch(this,"onabort");
_6.src=this.imgUrlBase+_5;
},onComplete:function(){
this.nProcessed++;
if(this.nProcessed==this.nImages){
this.callback(this.aImages,this.nLoaded);
}
},onload:function(){
this.nLoaded++;
this.onComplete();
},onerror:function(){
this.onComplete();
},onabort:function(){
this.onComplete();
}});

dojo.provide("memory.widget.ImageViewer");
dojo.require("memory.ImagePreloader");
dojo.require("dojo.lang.common");
dojo.require("dojo.lang.func");
dojo.require("dojo.widget.*");
dojo.require("dojo.lfx.*");
dojo.widget.defineWidget("memory.widget.ImageViewer",dojo.widget.HtmlWidget,function(){
this.endSlide=false;
this.callback=null;
this.isLoading=false;
},{templatePath:dojo.uri.moduleUri("memory.widget","templates/ImageViewer.html"),templateCssPath:dojo.uri.moduleUri("memory.widget","templates/ImageViewer.css"),preloadSize:5,imgUrls:[],imgUrlBase:"",transitionInterval:2000,imgWidth:800,imgHeight:600,stopped:false,_cIdx:0,cacheUrls:[],_urlsIdx:0,_dspIdx:0,_dir:"n",img:null,fadeAnim:null,postMixInProperties:function(){
this.width=this.imgWidth+"px";
this.height=this.imgHeight+"px";
},fillInTemplate:function(){
dojo.html.setOpacity(this.img,0.9999);
},start:function(){
this.stopped=false;
this.endSlide=false;
this._urlsIdx=0;
this._dspIdx=0;
this._cIdx=0;
this.img.src=this.imgUrlBase+"blank.jpg";
this.preLoad("_start");
},_start:function(_1,_2){
this._addToCache(_1);
this.isLoading=false;
this.next();
},_addToCache:function(_3){
if(!_3||_3.length==0){
return;
}
for(var f=0;f<_3.length;f++){
this.cacheUrls[this._cIdx++]=_3[f].src;
}
},stop:function(){
this.stopped=true;
this.img.src=this.imgUrlBase+"blank.jpg";
},setDelay:function(){
},setImages:function(_5){
if(dojo.lang.isString(_5)){
_5=_5.split(";");
}
this.imgUrls=_5;
},setPhotoCallback:function(_6){
if(_6){
this.callback=_6;
}
},preLoad:function(_7){
if(this._urlsIdx>=this.imgUrls.length){
return;
}
var _8=[];
for(var f=0;f<this.preloadSize;f++){
if(this._urlsIdx>this.imgUrls.length-1){
break;
}
_8.push(this.imgUrls[this._urlsIdx++]);
}
if(_8&&_8.length>0){
this.isLoading=true;
this.preload=new memory.ImagePreloader(this.imgUrlBase,_8,dojo.lang.hitch(this,_7));
}
},_preloadComp:function(_a,_b){
this._addToCache(_a);
this.isLoading=false;
},_displayImage:function(){
if(this.fadeAnim){
this.fadeAnim.stop();
}
this.fadeAnim=dojo.lfx.fadeOut(this.img,this.transitionInterval,null);
dojo.event.connect(this.fadeAnim,"onEnd",this,"_endAnim");
this.fadeAnim.play();
},_endAnim:function(){
var _c=0;
if(this._dir=="n"){
_c=this._dspIdx-1;
}else{
if(this._dir=="p"){
_c=--this._dspIdx;
this._dspIdx-=1;
}
}
this.img.src=this.cacheUrls[this._dspIdx];
this.fadeAnim=dojo.lfx.fadeIn(this.img,this.transitionInterval,null);
this.fadeAnim.play();
this._fireCallback("nextSlide",_c,this._dspIdx++);
},next:function(){
if(this.stopped||this.loadTimer){
return;
}
this._dir="n";
if(this._dspIdx>=this.imgUrls.length){
this.endSlide=true;
this._fireCallback("nextSlide",this._dspIdx-1,-1);
this.stop();
this._fireCallback("endSlide",-1,-1);
return;
}
if(this._dspIdx<this._cIdx){
this._displayImage();
}
if(this.isLoading){
this.loadTimer=dj_global.setInterval(dojo.lang.hitch(this,"timerHandler"),2000);
}else{
if(this._urlsIdx<this.imgUrls.length){
this.preLoad("_preloadComp");
}else{
this._displayImage();
}
}
},timerHandler:function(){
if(this.isLoading){
return;
}
dj_global.clearInterval(this.loadTimer);
this.next();
},previous:function(){
if(this.stopped||this.loadTimer){
return;
}
if((this._dspIdx-1)<=0){
alert("At beginning of images");
return;
}
this._dir="p";
this._displayImage();
},_fireCallback:function(_d,_e,_f){
if(this.callback&&dojo.lang.isFunction(this.callback[_d])){
this.callback[_d](_e,_f);
}
}});

dojo.provide("memory.widget.SlideShow");
dojo.require("dojo.widget.SlideShow");
dojo.require("dojo.lang.common");
dojo.require("dojo.lang.func");
dojo.require("dojo.widget.*");
dojo.widget.defineWidget("memory.widget.SlideShow",dojo.widget.SlideShow,function(){
this.endSlide=false;
this.callback=null;
this.prevImage=-1;
this.nextImage=-1;
},{templatePath:dojo.uri.moduleUri("memory.widget","templates/SlideShow.html"),start:function(){
this.stopped=false;
this.endSlide=false;
this.prevImage=-1;
this.nextImage=-1;
this._urlsIdx=0;
this._background="img2";
this._foreground="img1";
this.img2.src=this.imgUrlBase+this.imgUrls[this._urlsIdx++]+this._getUrlSuffix();
if(this.imgUrls.length<2){
this.endSlide=true;
}
this._endTransition();
},stop:function(){
this.stopped=true;
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onerror"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onerror"));
},setImages:function(_1){
if(dojo.lang.isString(_1)){
_1=_1.split(";");
}
this.imgUrls=_1;
this.imgUrls.push("blank.jpg");
},setPhotoCallback:function(_2){
if(_2){
this.callback=_2;
}
},_getEventObj:function(_3,_4){
return {srcObj:_3,srcFunc:_4,adviceObj:this,adviceFunc:"_backgroundImageLoaded",once:true,delay:this.delay};
},setDelay:function(_5){
if(_5>0){
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onload"));
dojo.event.kwDisconnect(this._getEventObj(this["img1"],"onerror"));
dojo.event.kwDisconnect(this._getEventObj(this["img2"],"onerror"));
this.delay=_5*1000;
}
},_loadNextImage:function(){
if(this.endSlide){
this._fireCallback("nextSlide",this.nextImage,-1);
this.stop();
this._fireCallback("endSlide",-1,-1);
return;
}else{
this.prevImage=this.nextImage;
this.nextImage=this._urlsIdx-1;
this._fireCallback("nextSlide",this.prevImage,this.nextImage);
}
dojo.event.kwConnect(this._getEventObj(this[this._background],"onload"));
dojo.event.kwConnect(this._getEventObj(this[this._background],"onerror"));
dojo.html.setOpacity(this[this._background],1);
this[this._background].src=this.imgUrlBase+this.imgUrls[this._urlsIdx++];
if(this._urlsIdx>(this.imgUrls.length-1)){
this.endSlide=true;
}
},_fireCallback:function(_6,_7,_8){
if(this.callback&&dojo.lang.isFunction(this.callback[_6])){
this.callback[_6](_7,_8);
}
}});

dojo.provide("memory.KCController");
dojo.require("memory.widget.SlideShow");
dojo.require("memory.widget.ImageViewer");
dojo.require("dojo.lang.declare");
dojo.require("dojo.lang.common");
dojo.require("dojo.event.*");
dojo.require("dojo.rpc.JsonService");
dojo.require("dojo.debug");
dojo.require("dojo.uri.*");
dojo.require("dojo.string.Builder");
dojo.declare("memory.KCController",null,function(){
this.photoProps=null;
},{init:function(){
this.connectWidgetEvent("start","onClick","startMemorization");
this.connectNodeEvent("allDemoProp","onclick","selDemoProps");
this.connectNodeEvent("clearDemoProp","onclick","clrDemoProps");
this.focusField("test_time");
this.clrDemoProps();
},connectNodeEvent:function(id,_2,_3){
var _4=dojo.byId(id);
if(_4){
dojo.event.connect(_4,_2,this,_3);
}
},connectWidgetEvent:function(_5,_6,_7){
var _8=dojo.widget.byId("start");
if(_8){
dojo.event.connect(_8,"onClick",this,"startMemorization");
}
},focusField:function(_9){
var n=dojo.byId(_9);
if(n&&n.focus){
n.focus();
}
},validatePhotoProps:function(_b){
if(_b["test_time"]==""){
_b["test_time"]=0;
}
if(_b["photo_time"]==""){
_b["photo_time"]=0;
}
if(_b["test_time"]==0&&_b["photo_time"]==0){
alert("Either time limit for test or max photo time is required");
this.focusField("test_time");
return false;
}
return true;
},startMemorization:function(){
this.photoProps=null;
var _c={};
var _d=this.getFormValues("memForm");
if(!this.validatePhotoProps(_d)){
return;
}
_c["photos"]=_d;
var _e=this.getFormValues("demoForm");
_c["demographics"]=_e;
if(dojo.lang.isFunction(memory.photoRpc["getPhotos"])){
this.dialogHandler(true,"Loading please wait...");
memory.photoRpc.getPhotos(_c).addBoth(this,"_startMemorization");
}else{
alert("ERROR: getPhotos() method not found");
}
},getImages:function(){
var _f=[];
if(!this.photoProps){
return _f;
}
for(var f=0;f<this.photoProps.length;f++){
_f.push(this.photoProps[f].photo_file);
}
return _f;
},_setupSlideShow:function(_11,_12,_13,_14,_15){
var _16=this.getFormValues(_12);
var _17=false;
var tt=parseFloat(_16.test_time);
var pt=parseFloat(_16.photo_time);
if(pt>0){
_17=true;
tt=0;
}else{
tt*=60;
}
var wt="ImageViewer";
if(_17){
wt="SlideShow";
}
var _1b=null;
if(this.slideShow){
_1b=this.slideShow.domNode;
}else{
_1b=dojo.byId("slideShow");
}
var _1c={transitionInterval:700,imgUrlBase:"/memory/images/kc/",imgWidth:400,imgHeight:600};
wt="memory:"+wt;
this.slideShow=dojo.widget.createWidget(wt,_1c,_1b);
this.slideShow.setPhotoCallback(_13);
this.slideShow.setImages(_11);
this.slideShow.setDelay(pt);
var fct=function(){
this[_15](this.slideShow,tt);
};
var cc=dojo.widget.byId("clientContainer");
cc.addOnLoad(dojo.lang.hitch(this,fct));
cc.setUrl(_14);
},_startMemorization:function(_1f){
if(_1f instanceof Error){
this.dialogHandler(false);
alert("Error fetching photos for memorization - "+_1f.message);
return;
}
this.dialogHandler(false);
this.photoProps=_1f;
var _20=this.getImages();
var _21={"nextSlide":dojo.lang.hitch(this,"nextSlide"),"prevSlide":dojo.lang.hitch(this,"prevSlide"),"endSlide":dojo.lang.hitch(this,"endSlide")};
this._setupSlideShow(_20,"memForm",_21,"kc_memory_entry.html","_memoryEntryLoaded");
},_memoryEntryLoaded:function(_22,_23){
dojo.widget.byId("BtnContainer").hide();
if(_23>0){
this.memTimer=dj_global.setInterval(dojo.lang.hitch(this,"stopMemorization"),_23*1000);
}
_22.start();
},nextSlide:function(_24,_25){
this.dspIndex=_25;
this.displayUserData(this.dspIndex);
},prevSlide:function(_26,_27){
this.dspIndex=_27;
this.displayUserData(this.dspIndex);
},endSlide:function(){
this.stopMemorization();
},stopMemorization:function(){
if(this.memTimer){
dj_global.clearInterval(this.memTimer);
}
if(this.slideShow){
this.slideShow.stop();
}
var cc=dojo.widget.byId("clientContainer");
cc.addOnLoad(dojo.lang.hitch(this,"_startLoaded"));
cc.setUrl("StartTest.html");
},_startLoaded:function(){
var btn=dojo.widget.byId("startTest");
if(btn){
dojo.event.connect(btn,"onClick",this,"startTest");
}
},startTest:function(){
this.fisherYatesShuffle(this.photoProps);
var _2a=this.getImages();
var _2b={"nextSlide":dojo.lang.hitch(this,"testNext"),"prevSlide":dojo.lang.hitch(this,"testPrev"),"endSlide":dojo.lang.hitch(this,"testEnd")};
this._setupSlideShow(_2a,"testForm",_2b,"kc_memory_entry.html","_testEntryLoaded");
},_testEntryLoaded:function(_2c,_2d){
dojo.widget.byId("empEntry").hide();
dojo.widget.byId("empInfo").hide();
dojo.widget.byId("BtnContainer").show();
var btn=dojo.widget.byId("infoBtn");
dojo.event.connect(btn,"onClick",this,"_showEmpInfo");
if(_2d>0){
this.memTimer=dj_global.setInterval(dojo.lang.hitch(this,"testEnd"),_2d*1000);
}
_2c.start();
},_showEmpInfo:function(){
dojo.widget.byId("empInfo").show();
var pp=this.photoProps[this.dspIndex];
if(!pp){
pp=this._defaultEntryData();
}
this.setFldValue("photoName",pp.firstname+" "+pp.lastname);
this.setFldValue("jobFunction",pp.job_function);
this.setFldValue("empLocation",pp.floor);
},testNext:function(_30,_31){
this.dspIndex=_31;
dojo.widget.byId("empInfo").hide();
},testPrev:function(_32,_33){
this.dspIndex=_33;
dojo.widget.byId("empInfo").hide();
},testEnd:function(){
this._stopTest();
},_stopTest:function(){
if(this.memTimer){
dj_global.clearInterval(this.memTimer);
}
if(this.slideShow){
this.slideShow.stop();
}
var _34="<h1>Memorization Completed</h1>";
var cc=dojo.widget.byId("clientContainer");
if(cc){
cc.setContent(_34);
}
},_formatResult:function(_36){
var sb=new dojo.string.Builder("<tr><td><img width=\"80\" height=\"120\" src=\"/memory/images/kc/");
sb.append(_36.photo_file).append("\"/></td><td><table><tr><th style=\"dataHdr\">Staff Info</th></tr>");
sb.append(this._formatData(_36.key_feature_tip));
sb.append(this._formatData(_36.first_celebrity_link));
sb.append(this._formatData(_36.second_celebrity_link));
sb.append(this._formatData(_36.first_name_tip));
sb.append(this._formatData(_36.last_name_tip));
sb.append(this._formatData(_36.rhymes));
sb.append(this._formatData(_36.general_tips));
sb.append("</table></td></tr>");
return sb.toString();
},_formatData:function(_38){
var sb=new dojo.string.Builder("<tr><td style=\"memData\">").append(_38).append("</td></tr>");
return sb.toString();
},fisherYatesShuffle:function(_3a){
var i=_3a.length;
if(i==0){
return false;
}
while(--i){
var j=Math.floor(Math.random()*(i+1));
var _3d=_3a[i];
var _3e=_3a[j];
_3a[i]=_3e;
_3a[j]=_3d;
}
},_defaultEntryData:function(){
return {firstname:"",lastname:"",photo_file:"",floor:"",job_function:"",key_feature_tip:"",first_celebrity_link:"",second_celebrity_link:"",first_name_tip:"",last_name_tip:"",rhymes:"",general_tips:""};
},setFldValue:function(fld,_40){
var n=dojo.byId(fld);
if(n){
n.innerHTML=_40;
}
},displayUserData:function(_42){
var pp=this.photoProps[_42];
if(!pp){
pp=this._defaultEntryData();
}
this.setFldValue("photoName",pp.firstname+" "+pp.lastname);
this.setFldValue("jobFunction",pp.job_function);
this.setFldValue("empLocation",pp.floor);
this.setFldValue("key_feature_tip",pp.key_feature_tip);
this.setFldValue("first_celebrity_link",pp.first_celebrity_link);
this.setFldValue("second_celebrity_link",pp.second_celebrity_link);
this.setFldValue("first_name_tip",pp.first_name_tip);
this.setFldValue("last_name_tip",pp.last_name_tip);
this.setFldValue("rhymes",pp.rhymes);
this.setFldValue("general_tips",pp.general_tips);
},dialogHandler:function(_44,_45){
if(_45){
var msg=dojo.byId("statusMsg");
if(msg){
msg.innerHTML=_45;
}
}
var _47=dojo.widget.byId("statusDialog");
if(_44){
_47.show();
}else{
_47.hide();
}
},_fp:function(_48){
return "<div class=\"photoProps\">"+_48+"</div>";
},updateProperties:function(_49){
if(this.photoProps==null){
return;
}
var pp=this.photoProps[_49];
if(!pp){
return;
}
var _4b=dojo.byId("photoName");
_4b.innerHTML=pp.first_name+" "+pp.last_name;
var ap=dojo.widget.byId("addInfo");
ap.setContent(sb.toString());
},getFormValues:function(_4d){
var _4e=dojo.byId(_4d);
if(!_4e){
return {};
}
var _4f={};
for(var f=0;f<_4e.elements.length;f++){
var el=_4e.elements[f];
if(el.name==""){
continue;
}
if((el.type!="select-multiple"&&el.type!="checkbox"&&el.type!="radio")||(el.type=="radio"&&el.checked)){
_4f[el.name]=el.value;
}else{
if(el.type=="checkbox"&&el.checked){
if(typeof (_4f[el.name])=="undefined"){
_4f[el.name]=[];
}
_4f[el.name].push(el.value);
}else{
if(el.type=="select-multiple"){
if(typeof (_4f[name])=="undefined"){
_4f[el.name]=[];
}
for(var opt=0,optlen=el.options.length;opt<optlen;opt++){
if(el.options[opt].selected){
_4f[name].push(el.options[opt].value);
}
}
}
}
}
}
return _4f;
},setCheckboxes:function(_53,_54){
var _55=dojo.byId(_53);
if(!_55){
return;
}
for(var f=0;f<_55.elements.length;f++){
if(_55.elements[f].type=="checkbox"){
_55.elements[f].checked=_54;
}
}
},selDemoProps:function(){
this.setCheckboxes("demoForm",true);
return false;
},clrDemoProps:function(){
this.setCheckboxes("demoForm",false);
return false;
}});
memory.appController=new memory.KCController();
memory.photoRpc=new dojo.rpc.JsonService("../php/kc.smd");

