var Slideshare={moduleId:null,keywordSearchResultCount:0,usernameSearchResultCount:0,query:null,page:1,itemsPerPage:10,offset:0,limit:10,dialog:null,slideshows:{},slideshowsOnLens:[],setModuleId:function(a){this.moduleId=a},setSlideshowsOnLens:function(a){this.slideshowsOnLens=(a?a:[])},id:function(a){return a+this.moduleId},go:function(){var a=$F(this.id("q"));if(this.dialog){this.dialog.close()}var b="width="+400+", height="+500+", location=no, menubar=no, toolbar=no, scrollbars=yes, resizable=yes, status=yes, top="+((screen.availHeight-500)/2)+", left="+((screen.availWidth-400)/2);this.dialog=window.open("/utility/module/slideshare_dialog?q="+a+"&has="+JSON.stringify(this.slideshowsOnLens),"slideshare_search",b);this.dialog.focus()},doSearch:function(a,b){$("summary").innerHTML="";$("summary").setStyle({display:"none"});$("results").innerHTML="";Slideshare.doUsernameSearch(a,function(){Slideshare.doKeywordSearch(a,function(){$("wait").setStyle({display:"none"});if(this.keywordSearchResultCount+this.usernameSearchResultCount<=0){$("summary").innerHTML='There are no results for your search.<br />(Sometimes this isn\'t true.  <a href="javascript:;" onclick="Slideshare.doSearch();">Try again</a>?)';$("summary").show()}})})},moreKeywordResults:function(){this.page++;this.doKeywordSearch(null,function(a){$("wait").setStyle({display:"none"});if(a){$("btn_more_keywords").setStyle({display:"none"})}})},moreUsernameResults:function(){this.offset+=this.limit;this.doUsernameSearch(null,function(a){$("wait").setStyle({display:"none"});if(a){$("btn_more_username").setStyle({display:"none"})}})},doKeywordSearch:function(query,andThen){if(!query){query=this.query}else{this.query=query}$("wait").show();new Ajax.Request("/utility/module/slideshare_search?q="+query+"&page="+this.page+"&items_per_page="+this.itemsPerPage,{method:"get",onSuccess:function(transport){var results=eval("("+transport.responseText+")");var total=results.Slideshows.Meta.TotalResults;var numResults=results.Slideshows.Meta.NumResults;this.keywordSearchResultCount+=total;if(total>0){for(var i=0;i<numResults;i++){var slideshow=results.Slideshows.Slideshow[i];var html='<div class="slideshow" id="slideshow'+slideshow.Id+'" onmouseout="$(this).setStyle({backgroundColor: \'transparent\'});" onmouseover="$(this).setStyle({backgroundColor: \'#eee\'});" style="background-image:url('+slideshow.Thumbnail+');">';html+='<div class="title">'+slideshow.Title+' <span>by <a href="/utility/module/slideshare_dialog?q='+slideshow.Owner+'">'+slideshow.Owner+"</a></div>";html+='<div class="description">'+slideshow.Description.substring(0,75)+"...</div>";if(this.slideshowsOnLens.indexOf(parseInt(slideshow.Id))==-1){html+='<a class="add" href="javascript:Slideshare.addFromDialog(\''+slideshow.Id+"');\">add to my lens</a>"}else{html+='<div class="already">already on your lens</div>'}html+="</div>";$("results").innerHTML+=html;this.slideshows[slideshow.Id]=JSON.stringify(slideshow)}if(results.Slideshows.Meta.ResultOffset+numResults<total){$("btn_more_keywords").show()}}if(andThen){(andThen.bind(this,numResults))()}}.bind(this),onFailure:function(){$("summary").innerHTML="Some sorta error occurred.  Please try again later.";$("wait").setStyle({display:"none"})}.bind(this)})},doUsernameSearch:function(query,andThen){if(!query){query=this.query}else{this.query=query}$("wait").show();new Ajax.Request("/utility/module/slideshare_get_slideshow_by_user?username_for="+query+"&limit="+this.limit+"&offset="+this.offset,{method:"get",onSuccess:function(transport){var results=eval(("("+transport.responseText+")"));var numResults=0;if(!results.SlideShareServiceError){var total=results.User.count;if(total>0&&results.User.Slideshow&&results.User.Slideshow.length>0){numResults=results.User.Slideshow.length;this.usernameSearchResultCount+=total;for(var i=0;i<numResults;i++){var slideshow=results.User.Slideshow[i];var html='<div class="slideshow" id="slideshow'+slideshow.ID+'" onmouseout="$(this).setStyle({backgroundColor: \'transparent\'});" onmouseover="$(this).setStyle({backgroundColor: \'#eee\'});" style="background-image:url('+slideshow.Thumbnail+');">';html+='<div class="title">'+slideshow.Title+' <span>by <a href="/utility/module/slideshare_dialog?q='+results.User.name+'">'+results.User.name+"</a></div>";if(slideshow.Description!=""){html+='<div class="description">'+slideshow.Description.substring(0,75)+"...</div>"}if(this.slideshowsOnLens.indexOf(parseInt(slideshow.ID))==-1){html+='<a class="add" href="javascript:Slideshare.addFromDialog(\''+slideshow.ID+"');\">add to my lens</a>"}else{html+='<div class="already">already on your lens</div>'}html+="</div>";$("results").innerHTML+=html;this.slideshows[slideshow.Id]=JSON.stringify(slideshow)}if((this.offset+numResults)-1<total){$("btn_more_username").show()}}}if(andThen){(andThen.bind(this,numResults))()}}.bind(this),onFailure:function(){$("summary").innerHTML="Some sorta error occurred.  Please try again later.";$("wait").setStyle({display:"none"})}.bind(this)})},addFromDialog:function(b){var a=window.opener.Slideshare.add(b);if(a==0){window.close()}else{if(a==-1){alert("Hmm... somehow you've already added that slideshow.  Look for another one?")}else{if(a==1){$("slideshow"+b).hide()}else{alert("I have no idea what the other window is trying to tell me... go figure.")}}}},add:function(id){if(this.slideshowsOnLens.length==5){return 0}else{if(this.slideshowsOnLens.indexOf(id)>=0){return -1}var hadNone=(this.slideshowsOnLens.length==0);this.slideshowsOnLens.push(id);$(this.id("wait")).setStyle({display:"block"});new Ajax.Request("/utility/module/slideshare_get_slideshow_info?slideshow_id="+id,{method:"get",onSuccess:function(transport){var slideshow=eval(("("+transport.responseText+")")).Slideshow;this.slideshows[id]=JSON.stringify(slideshow);if(hadNone){$(this.id("searchMessage")).setStyle({display:"none"});$(this.id("dragMessage")).setStyle({display:"block"})}$(this.id("slideshows")).innerHTML+='<li id="'+this.id("slideshow")+'" class="draggable"><input type="hidden" name="modules[id'+this.moduleId+'][details][slideshows][]" value="'+escape(this.slideshows[id])+'" /><span>'+slideshow.Title+'</span> <a href="javascript:;" onclick="Slideshare.remove(\''+id+"');\">remove</a></li>";Sortable.create(this.id("slideshows"));$(this.id("wait")).setStyle({display:"none"})}.bind(this),onFailure:function(){alert("Failed to get slideshow info!");$(this.id("wait")).setStyle({display:"none"})}.bind(this)});if(this.slideshowsOnLens.length==5){$(this.id("search")).setStyle({display:"none"});$(this.id("nosearch")).setStyle({display:"block"});return 0}else{return 1}}},reorder:function(){Sortable.create(this.id("slideshows"),{tag:"li"});$(this.id("dragMessage")).setStyle({display:"block"});$(this.id("btnReorder")).setStyle({display:"none"})},remove:function(b){var a=$(Slideshare.id("slideshow"+b));a.parentNode.removeChild(a);Slideshare.slideshowsOnLens=Slideshare.slideshowsOnLens.reject(function(c){return c==b});if(Slideshare.slideshowsOnLens.length<5){$(Slideshare.id("search")).setStyle({display:"block"});$(Slideshare.id("nosearch")).setStyle({display:"none"})}if(Slideshare.slideshowsOnLens.length==0){$(Slideshare.id("searchMessage")).setStyle({display:"block"});$(Slideshare.id("dragMessage")).setStyle({display:"none"});$(Slideshare.id("btnReorder")).setStyle({display:"none"})}},removeAll:function(){$(Slideshare.id("slideshows")).innerHTML="";Slideshare.slideshowsOnLens.clear();Slideshare.slideshows={};$(Slideshare.id("searchMessage")).setStyle({display:"block"});$(Slideshare.id("dragMessage")).setStyle({display:"none"})},activate:function(index,slideshowJSON){var slideshow=eval("("+unescape(slideshowJSON)+")");$(this.id("embed")).innerHTML=slideshow.EmbedCode;for(i=0;i<5;i++){if(parseInt(i)==parseInt(index)){$(this.id("slideshow"+i)).addClassName("active")}else{$(this.id("slideshow"+i)).removeClassName("active")}}},};