$(document).ready(function(){$("#lnk_browser").hide();$("#lnk_hide_browser").hide();$("#lnk_ajax_loading").hide();linkerFrontend.loadLinkList();linkerFrontend.loadList();$("#lnk_location a.navigable").livequery("click",function(){linkerFrontend.loadList($(this).attr("rel"),$(this).attr("title"));return false});$("#lnk_resources a.navigable").livequery("click",function(){linkerFrontend.loadList($(this).attr("rel"),$(this).attr("title"));return false});$("#lnk_resources a.linkable").livequery("click",function(){linkerFrontend.select($(this).attr("id"),$(this).attr("title"));return false});$("#lnk_selected_resources div a").livequery("click",function(){linkerFrontend.unselect($(this).attr("rel"));return false});$("#lnk_show_browser").click(function(){$("#lnk_browser").show();$("#lnk_show_browser").hide();$("#lnk_hide_browser").show()});$("#lnk_hide_browser").click(function(){$("#lnk_browser").hide();$("#lnk_hide_browser").hide();$("#lnk_show_browser").show()});$("#lnk_ajax_loading").ajaxStart(function(){$(this).show()});$("#lnk_ajax_loading").ajaxStop(function(){$(this).hide()})});var linkerFrontend={selected:{},history:[],base_url:"",deleteIconUrl:"",currentIdx:0,currentCrl:"",loadLinkList:function(){var a=this.base_url+"?cmd=getLinkList";if(linkerFrontend.currentCrl){a=a+"&crl="+escape(linkerFrontend.currentCrl)}$.getJSON(a,function(b){if(!Claroline.json.isResponse(b)){alert("Invalid response");return}if(Claroline.json.isError(b)){Claroline.json.handleJsonError(b);return}var d=Claroline.json.getResponseBody(b);if(d.length){for(var c=0;c<d.length;c++){linkerFrontend.addSelected(d[c].crl,d[c].name)}}})},loadList:function(c,b){var a=this.base_url;if(typeof c!="undefined"){a=a+"?crl="+escape(c)}$.getJSON(a,function(e){if(!Claroline.json.isResponse(e)){alert("Invalid response");return}if(Claroline.json.isError(e)){Claroline.json.handleJsonError(e);return}var g=Claroline.json.getResponseBody(e);if(typeof b=="undefined"){b=g.name}var h;if(!linkerFrontend.inHistory(g.crl)){linkerFrontend.history.push({crl:g.crl,fullname:g.name,name:b})}if(c){while((h=linkerFrontend.history.pop())){if(h.crl==c){linkerFrontend.history.push(h);break}}}linkerFrontend.renderBreadcrumbs(g.name);$("#lnk_back_link").empty();if(linkerFrontend.history.length>1){$("<a />").text("["+Claroline.getLang("Up")+"]").attr("onclick","linkerFrontend.loadList('"+g.parent+"');return false;").appendTo("#lnk_back_link")}else{$("<br />").appendTo("#lnk_back_link")}$("#lnk_resources").empty();var f;for(var d in g.resources){f=g.resources[d];if(f.isNavigable){$("#lnk_resources").append('<a class="navigable" rel="'+f.crl+'" title="'+f.name+'">'+f.name+"</a>")}else{$("#lnk_resources").append("<span>"+f.name+"</span>")}if(f.isLinkable){$("#lnk_resources").append(' <a class="linkable" id="'+f.crl+'" title="'+f.name+'">['+Claroline.getLang("Attach")+"]</a>")}$("<br />").appendTo("#lnk_resources")}})},inHistory:function(b){for(var a=0;a<linkerFrontend.history.length;a++){if(linkerFrontend.history[a].crl==b){return true}}return false},renderBreadcrumbs:function(c){$("#lnk_location").empty();var b=[];for(var a=0;a<linkerFrontend.history.length;a++){b.push('<a class="breadcrumb navigable" href="#" rel="'+linkerFrontend.history[a].crl+'" title="'+linkerFrontend.history[a].name+'">'+linkerFrontend.history[a].name+"</a>")}$("#lnk_location").append(b.join(" &gt; "))},submit:function(){},select:function(b,a){this.selected[b]=a;this.addSelected(b,a)},unselect:function(a){delete this.selected[a];this.removeSelected(a)},unselectAll:function(){},renderSelected:function(){$("#lnk_selected_resources").empty();var b=0;for(var a in this.selected){$("#lnk_selected_resources").append('<div id="'+a+'"><a href="#" rel="'+a+'"><img src="'+this.deleteIconUrl+'" alt="'+Claroline.getLang("Delete")+'" /></a>'+this.selected[a]+"</div>");$("#lnk_hidden_fields").append('<input name="resourceList['+b+']" value="'+a+'" type="hidden">');b++}},addSelected:function(c,a){var b=false;$("#lnk_selected_resources div a").each(function(d){if($(this).attr("rel")==c){b=true}});if(!b){$("#lnk_selected_resources").append('<div id="'+c+'"><a href="#" rel="'+c+'"><img src="'+this.deleteIconUrl+'" alt="'+Claroline.getLang("Delete")+'" /></a>'+a+"</div>");$("#lnk_hidden_fields").append('<input name="resourceList['+this.currentIdx+']" value="'+c+'" type="hidden">');this.currentIdx++}},removeSelected:function(a){$("#lnk_selected_resources div a").each(function(b){if($(this).attr("rel")==a){$(this).parent().remove()}});$("#lnk_hidden_fields input").each(function(b){if($(this).attr("value")==a){$(this).remove()}})}};