ComCore.Spotlight=Class.create();ComCore.Spotlight.prototype={initialize:function(B,A,C){debug("ComCore.Spotlight");this.peopleResults=$(B);this.peopleSpotlightBlock=$(A);this.peopleNewResults=[];this.lastUserID="";this.updateAllowed=true;if(C){this.maxResults=C}else{this.maxResults=40}if(ComCore.Login.isLoggedIn()===true){this.periodicalExecuterPeople=new PeriodicalExecuter(this.fetchNewPeopleResults.bind(this),10)}if(this.peopleSpotlightBlock){this.peopleSpotlightBlock.observe("click",this.onSpotlightTeaserClick.bind(this))}this.peopleResults.observe("mouseover",this.stopAutoUpdate.bind(this));this.peopleResults.observe("mouseout",this.resumeAutoUpdate.bind(this));var D=document;if(Prototype.Browser.IE){D.observe("onfocusout",this.stopAutoUpdate.bind(this));D.observe("onfocusin",this.resumeAutoUpdate.bind(this))}else{window.onblur=this.stopAutoUpdate.bind(this);window.onfocus=this.resumeAutoUpdate.bind(this);if(!window.onblur){D.onblur=window.onblur.bind(this);D.focus=window.onfocus.bind(this)}}},stopAutoUpdate:function(){this.periodicalExecuterPeople.stop();this.updateAllowed=false},resumeAutoUpdate:function(){this.periodicalExecuterPeople.restart();this.updateAllowed=true},fetchNewPeopleResults:function(){if(this.peopleNewResults.length>0){debug("still adding new results");return }var E;if($("peopleSearchForm")){E=Form.serialize("peopleSearchForm",true)}else{E=[]}delete E.action;if(this.lastUserID===""){var B=this.peopleResults.down("li");if(B){E.lastUserID=B.getClassData("peopleResult")}}else{E.lastUserID=this.lastUserID}debug(E.lastUserID);var A="/people/view=results&type=update";var D=this;var C=new Ajax.Request(A,{method:"post",parameters:E,onSuccess:function(G,F){D.filterResultsUpdateReceived(G,F)}})},filterResultsUpdateReceived:function(B,A){if(this.updateAllowed){if(A.lastuserid){this.lastUserID=A.lastuserid}var C=this;B.responseJSON.each(function(D){C.peopleNewResults.push({url:D.url,imgurl:D.imgurl,userid:D.userid,tooltip:D.tooltip})});this.addNewResultsPeople()}},addNewResultsPeople:function(){if(this.peopleNewResults.length>0){var A=this.peopleNewResults.shift();this.addNewResult(A.url,A.imgurl,A.userid,A.tooltip,true)}},addNewResult:function(A,J,C,I,F){var E=this;var B=false;C=parseInt(C,10);var G=this.peopleResults.select("li");if(F){G.each(function(L){var M=parseInt(L.getClassData("peopleResult"),10);if(C===M){B=L}})}var K='<li class="newPeopleResult peopleResult_'+C+'" style="display:none"><a href="'+A+'" class="enableTooltip" title="'+I+'"><img src="'+J+'"/></a></li>';this.peopleResults.insert({top:K});var D=this.peopleResults.down("li.newPeopleResult");debug("ADD URL: "+A+" IMG: "+J+"USERID: "+C+" "+D);if(D){if(B===false){B=this.peopleResults.select("li").last()}var H=new Effect.Parallel([Effect.BlindLeft(B,{sync:true,afterFinish:function(){debug("length: "+G.length);if(G.length>=E.maxResults){B.remove()}E.addNewResultsPeople()}}),Effect.BlindRight(D,{sync:true,afterFinish:function(){}})],{duration:0.2})}},onSpotlightTeaserClick:function(C){var A=C.findElement("a");var B=this;if(A){ComCore.Dialog.initialize();ComCore.Dialog.getContent("/people/view=addspotlight");ComCore.Dialog.registerExitCallBack(function(D){});ComCore.Dialog.registerCloseCallBack(function(D){});ComCore.Dialog.registerSetContentSuccessCallback(function(D){});ComCore.Dialog.ajaxProxy.registerProxySuccessCallBack(function(D){if(D.responseJSON){if(D.responseJSON.result==="FLOOD_ALREADY"){ComCore.Dialog.close()}else{if(D.responseJSON.result===true){B.profileInSpotlight();ComCore.Dialog.close()}}}});C.stop()}},profileInSpotlight:function(){var A=this.peopleSpotlightBlock.down("a");var B=ComCore.Login.getUserID();this.addNewResult(ComCore.Page.getContextURL(),A.down("img").src,B,A.down("img").alt,true)},_eoo:true};ComCore.SpotlightControl=null;ComCore.Queuer.add(function(A){if($("spotlightMaxOffset")){ComCore.SpotlightControl=new ComCore.Spotlight("spotlightGrid","spotlightTeaser",$("spotlightMaxOffset").value)}else{ComCore.SpotlightControl=new ComCore.Spotlight("spotlightGrid","spotlightTeaser")}});