/*
 * Copyright (c) 2009 Andreas Blixt <andreas@blixt.org>
 * Contributors: Aaron Ogle <aogle@avencia.com>
 * This and more JavaScript libraries: http://blixt.org/js
 * MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * Hash handler
 * Keeps track of the history of changes to the hash part in the address bar.
 */
var Hash=(function(){var g=this,e=document.documentMode,f=g.history,j=g.location,k,c,b,d=function(){var l=j.href.indexOf("#");return(l==-1?"":j.href.substr(l+1))},h=function(){var l=d();if(l!=c){oldHash=c;c=l;k(l,oldHash)}},a=function(l){try{var n=b.contentWindow.document;n.open();n.write("<html><body>"+l+"</body></html>");n.close();c=l}catch(m){setTimeout(function(){a(l)},10)}},i=function(){try{b.contentWindow.document}catch(m){setTimeout(i,10);return}a(c);var l=c,n=null;setInterval(function(){var o,p;try{o=b.contentWindow.document.body.innerText;if(o!=l){n=l;l=o;j.hash=c=o;k(o,n)}else{p=d();if(p!=c){a(p)}}}catch(q){}},50)};return{init:function(l,m){if(k){return}k=l;c=d();l(c);if(g.ActiveXObject){if(!e||e<8){b=m;i()}else{g.attachEvent("onhashchange",h)}}else{if(f.navigationMode){f.navigationMode="compatible"}setInterval(h,50)}},go:function(l){if(l==c){return}if(b){a(l)}else{var m=d();j.hash=c=l;k(l,m)}},getHash:d}})();
/*
 * Copyright (c) 2009 Andreas Blixt <andreas@blixt.org>
 * This and more JavaScript libraries: http://blixt.org/js
 * MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * jQuery hash plugin (Depends on jQuery, Hash)
 * Plugin for detecting changes to the hash and for adding history support for
 * hashes to certain browsers.
 */
(function(i,e){var d="jquery-history",f="/media/js/hash/blank.html",a="hashchange",j="hash.fn",h,c=this,b=document.documentMode,g=function(k,l){i.event.trigger(a,[k,l])};i.hash={init:function(l){if(h){return}h=1;var k;if(c.ActiveXObject&&(!b||b<8)){i("body").prepend('<iframe id="'+d+'" style="display:none;" src="'+(l||f)+'"></iframe>');k=i("#"+d)[0]}e.init(g,k)},go:e.go};i.fn.hash=function(l,m){var k=this.data(j);if(k){this.unbind("click",k)}if(typeof l=="string"){k=function(){e.go(l);return false};this.data(j,k);this.click(k);if(m||m===undefined){this.attr("href","#"+l)}}return this};i.fn[a]=function(k){return this.bind(a,k)}})(jQuery,Hash);var REFINER_INIT=function(l,p,h,n){window.onunload=function(){};var i=function(r,q){return{first:r?1:0,q_type:null,cur_item_ids:q||[],item_yes:[],item_no:[],next_rs:[],old_next_rs:{}}};var b=i(1,n),j=new Image(),e=0;j.src="/media/img/loading-32px.gif";var g={xhr:null,start:function(q){if(g.xhr){try{g.xhr.abort();g.xhr=null}catch(r){}}if(!q){if(b.first){$("#question-widget").html(j);$("#gamma").html("")}else{$("#question-widget .question").addClass("loading")}}},clean:function(){$("#question-widget .question").removeClass("loading")},done:function(){g.xhr=null}};var c=function(s){s=typeof(s)=="string"?s:Hash.getHash();var q=s.match(/^(s(\d*)\.)?((-?\d+\.)+)?(q=(.*))?$/),r={h:(q&&q[3]?q[3]:""),page:1,hash:s};if(q){if(q[2]){r.page=parseInt(q[2])}if(q[1]){r.see_more=1}if(q[6]){r.query=q[6]}if(r.page<2&&s.substring(0,1)=="s"){r.redir=s.substring(s.split(".")[0].length+1)}}else{if(s){r.redir=""}}if(b.q_type!==null){r.q_type=b.q_type}if(b.item_yes.length){r.item_yes=b.item_yes.join(",")}if(b.item_no.length){r.item_no=b.item_no.join(",")}return r};var f=function(q){if(q){q=q.split(".");q.pop();return q}return[]};var o=function(){var q=$("#gamma>.big-header input.text");if(q.length){q.placeholder().keyup(function(s){if(s.keyCode==13){var u=q.val();if(u){var r=c(),t="";if(r.h){t+=r.h}t+="q="+encodeURIComponent(u);$("#gamma>.big-header .indicator").show();$.hash.go(t);return false}}})}};var k=function(){if($(".yesno-activities").size()){var r=function(){$("#item-all-2").css("background","transparent");$("#item-all-2 .procon .left-css-notch").css("border-right-color","#fff");$("#item-all-2-over").hide()};var s=function(){$("#item-all-2").css("background","#ddd");$("#item-all-2 .procon .left-css-notch").css("border-right-color","#ddd");$("#item-all-2-over").show()};var q=$("#item-all-2");$(".refiner-activities").append($('<li id="item-all-2-over" />').css({position:"absolute",left:0,bottom:0,padding:0,margin:0,border:0,width:q.outerWidth()+"px",height:q.outerHeight()+"px",backgroundColor:"#fff",opacity:0.85}));$("#item-all-2").hover(null,s);$("#item-all-2-over").hover(r,null);s()}};var d=function(C,r,z){if(typeof(r)=="undefined"&&typeof(z)=="undefined"){return}var q=z=="_q_type",w=typeof(z)=="object"&&z.tran=="_feedback",H=/q=/.test(r)||(typeof(z)=="string"&&/q=/.test(z)),I=false,B=q||w||H,v,t=b.first,A=false,G=++e,s;if(b.first&&!r){b.first=0;return}g.start(w);if(b.first){b.first=0}var x=c(r),E=(typeof(z)=="string"?c(z):null),D,F;if(typeof(x.redir)!="undefined"){$.hash.go(x.redir)}if(B){s=b.old_next_rs.prior_r}else{b.old_next_rs={}}if(w){$.extend(x,z.data)}if(E&&x.h==E.h&&E.page&&x.page&&E.page!=x.page){B=true;I=true}if(!B&&E){D=f(x.h);F=f(E.h);if(F.length==D.length+1){s=F.pop();if(("."+D.join(".")+".").split("."+s+".").length==2){s=null}if(s){b.next_rs.push(s)}}if(!B&&!s&&b.next_rs.length){b.next_rs.pop();if(b.next_rs.length){s=b.next_rs[b.next_rs.length-1];x.is_next=1}}}if(s){x.prior_r=s}if(!t&&(w||I||H)){x.no_question=1;g.clean()}var u={url:p,data:x,type:(t?"get":"post"),dataType:"json",cache:false,error:function(J,K){$.hunchError({textStatus:K},true);g.done()},success:function(J,K){if(G<e){return}g.done();if(!x.no_question){$("#question-widget").html(J.question)}if(!q){$("#gamma").html(J.results);o();k()}if(J.query){$("#gamma>.big-header a.clear-search").click(function(){var L=Hash.getHash();L=L.split("q=")[0];if(/s(\d+)\./.test(L)){L=L.split(".");L[0]="s";L=L.join(".")}$("#gamma>.big-header .indicator").show();$.hash.go(L)})}if(I){window.scrollTo(0,$("#beta").offset().top-9)}if(J.is_done){b.next_rs=[];$(".topic-widget").hide()}}};var y=$.ajax(u);if(!w){g.xhr=y}};$(window).hashchange(d);$.hash.init();b.first=0;o();k();var m=function(r,s){b.q_type=r;b.old_next_rs[s]=b.next_rs;b.next_rs=b.old_next_rs[r]||[];var q=parseInt($("#question-widget .question").idPrefix());b.old_next_rs["qid"+s]=q;b.old_next_rs.prior_r=(b.old_next_rs["qid"+r]?-b.old_next_rs["qid"+r]:null);d(null,Hash.getHash(),"_q_type")};$("#topic-qs:not(.hover)").live("click",function(){return m("topic","thays")});$("#thays-qs:not(.hover)").live("click",function(){return m("thays","topic")});var a=function(u,x,q,v,t){var w={train_item:1,item_id:u,pos:x,feedback:q,source:"refiner"},s={tran:"_feedback",data:w},r;if(w.feedback=="yes"){b.item_yes.push(w.item_id)}else{if(w.feedback=="no"){b.item_no.push(w.item_id)}}$("button",v).remove();r=(t?'<img src="/media/img/loading-333-fff-16px.gif" class="'+t+'" >':'<div style="height:18px;"><img src="/media/img/loading-333-fff-16px.gif" /></div>');v.append(r);d(null,Hash.getHash(),s);return false};$("div.feedback button").live("click",function(){var q=this.id.split("-");return a(q[0],q[1],q[2],$(this).closest("div"))});$("button.yes").live("click",function(){return a($.idPrefix(this),1,"yes",$(this).parent(),"left")});$("button.no").live("click",function(){return a($.idPrefix(this),1,"no",$(this).parent(),"left")});$("#flag-question").hunchflag({url:h,title:"Flag this question:",dataFunc:function(){return{id:$(".question").idPrefix(),topic_id:l,what:"qanda"}},flags:[["Offensive","offensive"],["Poor quality <span>Ex: bad photo, not helpful</span>","quality"],["Irrelevant","irrelevant"],["Duplicate <span>(please specify)</span>","duplicate"]],live:1});$("button#refiner-start-over").live("click",function(){window.location=window.location.href.split("#")[0];return false})};