$.enswerme.search={};$.enswerme.search.bind_save_search=function(){$("#btn_saved_search").click(function(){var query=$("#search_query").attr("value");$.post("/saved_search/add/",{query:query},function(result){$.jGrowl(result.flash);},'json');return false;});}
$.enswerme.search.toggle_filter=function(){$("#contents_filtering a.filter").click(function(){var $this=$(this);var f_class=$this.attr("rel");var $items=$("li#"+f_class);if($items.hasClass("closed")){$items.removeClass("closed");}
else{$items.addClass("closed");}
return false;});};$.enswerme.search.LoadingTab=Class({init:function($img_tab_loading){this.img_tab_loading=$img_tab_loading;},loading:function(){this.img_tab_loading.css('display','block');},finish:function(){this.img_tab_loading.css('display','none');},finish_timeout:function(){var img_tab_loading=this.img_tab_loading;setTimeout(function(){img_tab_loading.css('display','none');},600);}});$.enswerme.search.bind_view_cluster_videos=function(){var q=$("#search_query").attr('value');$(".cluster_detail a.video").click(function(){var $this=$(this);var cid=$this.attr("id").replace("cl_video_btn_","");var vindex=$this.find('span.vindex').text();var data={'q':q,'a':5,'vindex':vindex};var href="/search/cluster/"+cid+"/videos/";var $cluster_videos=$("#cluster_videos_"+cid);var $download_videos=$("#download_videos_"+cid);var $img_tab=$($this.find("img.tab_btn"));var $img_tab_loading=$($this.find("img.loading_img"));var loadingTab=new $.enswerme.search.LoadingTab($img_tab_loading);if($cluster_videos.is(":hidden")){$(".cluster_videos").not(this).css("display","none");if($cluster_videos.children(".cluster").length>0){loadingTab.loading();}
else{$.ajax({url:href,dataType:'html',data:data,beforeSend:function(req){loadingTab.loading();},success:function(data){$cluster_videos.html(data);},complete:function(req,stat){loadingTab.finish_timeout();}});}
$cluster_videos.css('display','block');$this.addClass("selected");if($download_videos.length>0){$("#dn_video_btn_"+cid).removeClass("selected");$download_videos.css('display','none');}
if($cluster_videos.children(".cluster").length>0){loadingTab.finish_timeout();}}else{loadingTab.loading();$cluster_videos.css('display','none');$this.removeClass("selected");loadingTab.finish_timeout();}
return false;});};$.enswerme.search.bind_view_download_videos=function(){$(".cluster_detail a.download").click(function(){var $this=$(this);var cid=$this.attr("id").replace("dn_video_btn_","");var href="/search/download/"+cid+"/videos/";var $cluster_videos=$("#cluster_videos_"+cid);var $download_videos=$("#download_videos_"+cid);var $img_tab=$($this.find("img.tab_btn"));var $img_tab_loading=$($this.find("img.loading_img"));var loadingTab=new $.enswerme.search.LoadingTab($img_tab_loading);if($download_videos.is(":hidden")){$(".cluster_videos").not(this).css("display","none");if($download_videos.children(".cluster").length){loadingTab.loading();}
else{$.ajax({url:href,dataType:'html',beforeSend:function(req){loadingTab.loading();},success:function(data){$download_videos.html(data);},complete:function(req,stat){loadingTab.finish_timeout();}});}
$download_videos.css('display','block');$this.addClass("selected");if($cluster_videos.length>0){$cluster_videos.css('display','none');$("#cl_video_btn_"+cid).removeClass("selected");}
if($download_videos.children(".cluster").length){loadingTab.finish_timeout();}}else{loadingTab.loading();$download_videos.css('display','none');$this.removeClass('selected');loadingTab.finish_timeout();}
return false;});};$.enswerme.search.bind_more_text_video=function(){$("#text_videos a#btn_more_text_video").click(function(){var $this=$(this);$this.css('display','none');var $loading=$("#text_video_loading_img");$loading.css('display','block');var q=$("#text_video_info span.q").text();var total=parseInt($("#text_video_info span.total").text(),10);var length=$("#text_videos dl").length;if(length==total){$this.remove();}
$.ajax({async:true,url:"/search/textvideo/append/",dataType:"html",data:{q:q,start:length},beforeSend:function(req){},success:function(result){$("#text_videos dl:last").after(result);if(length==$("#text_videos dl").length){$this.remove();}},complete:function(req,stat){if($loading){$loading.css('display','none');$this.css('display','block');}}});});};$.enswerme.search.bind_paginator=function(sel,loading){var $sel=$(sel);var $pagination_links=$(sel+" div.pagination li a");$pagination_links.live("click",function(){var $this=$(this);var href=$this.attr("href");var $loading=$(loading);$loading.css('display','block');setTimeout(function(){$.ajax({async:false,url:href,dataType:"html",beforeSend:function(req){},success:function(result){$sel.html(result);},complete:function(req,stat){}});},800);return false;});};$.enswerme.search.init=function(){$.enswerme.search.bind_view_cluster_videos();$.enswerme.search.bind_view_download_videos();$.enswerme.search.toggle_filter();$.enswerme.search.bind_save_search();$.enswerme.search.bind_more_text_video();$.enswerme.search.bind_paginator('#playlist_list','#playlist_loading_img');$.enswerme.search.bind_paginator('#download_list','#download_loading_img');}
