var pageTracker;try{pageTracker=_gat._getTracker("UA-163731-3");pageTracker._trackPageview()
}catch(e){$.log("WARN: Couldn't track pageview.")}var R={VERSION:"1.32",c:{debug:(($.url.attr("protocol")=="file"||$.url.param("debug"))?true:false),per_set:9,restock_threshold:18,am:{store:"US",minimum_price:1001,maximum_price:2000,indices:["Books","DVD","VideoGames","Jewelry","Apparel","Music","Toys"]}},d:{stack:[],sets:[],current_set:0,requests_active:0,more_data_needed:false,display_blocked:false,current_item_link:"",am:{itempage:1,last_itempage:false,last_itempage_count:0,US:{indices:["Apparel","Beauty","Books","Classical","DVD","Electronics","GourmetFood","HomeGarden","Jewelry","Kitchen","Music","MusicalInstruments","OfficeProducts","OutdoorLiving","PCHardware","Photo","Shoes","SilverMerchants","Software","SportingGoods","Tools","Toys","Video","VideoGames","Watches","Wireless"],priceless:[],currency:"$",affid:"randomli-20",coco:"us"},CA:{indices:["Books","Classical","DVD","ForeignBooks","Music","Software","SoftwareVideoGames","Video","VideoGames"],priceless:[],currency:"CDN$",affid:"randomli08-20",coco:"ca"},DE:{indices:["Books","PCHardware","SoftwareVideoGames","DVD","Electronics","ForeignBooks","Photo","OutdoorLiving","HomeGarden","Classical","Kitchen","Music","Software","Toys","SportingGoods","Video","Watches","VideoGames","Tools"],priceless:["Toys","Watches"],currency:"\u20AC",affid:"randomli-21",coco:"de"},FR:{indices:["Books","Classical","DVD","Electronics","ForeignBooks","Kitchen","Music","Software","SoftwareVideoGames","Video","VideoGames","Watches"],priceless:["Watches"],currency:"\u20AC",affid:"randomli07-21",coco:"fr"},UK:{indices:["Apparel","Books","Classical","DVD","Electronics","HomeGarden","Kitchen","Music","OutdoorLiving","Software","SoftwareVideoGames","Toys","Video","VideoGames","Watches"],priceless:["Watches"],currency:"\u20A4",affid:"randomli01-21",coco:"uk"}}},Form:{init:function(){var price_range=R.c.am.minimum_price+"-"+R.c.am.maximum_price;
if($.url.param("s")){if($.url.param("s").match(/^[a-z]{2}$/i)){R.c.am.store=$.url.param("s").toUpperCase()
}}$("#settings #price_range").val(price_range);$("#settings #store").val(R.c.am.store);
R.Form.updateCurrentIndices();$("#adv_settings").hide();$("#toggle_adv_settings .closed").show();
$("#toggle_adv_settings .opened").hide();$(".currency").html(R.d.am[R.c.am.store].currency)
},submit:function(){var price_range=$("#settings #price_range").val().split(/-/);
R.c.am.minimum_price=Number(price_range[0]);R.c.am.maximum_price=Number(price_range[1]);
R.c.am.store=$("#settings #store").val();$(".currency").html(R.d.am[R.c.am.store].currency);
R.Form.updateCurrentIndices();R.d.am.itempage=1;R.d.am.last_itempage=false;R.d.am.last_itempage_count=0;
R.d.stack=[];R.d.sets=[];R.d.current_set=0;R.Display.clear();R.Stack.triggerUpdate();
R.Form.setCookie()},setCookie:function(){$.cookies.set("conf",$.compactJSON(R.c.am),{hoursToLive:672})
},getCookie:function(){var cookie=$.cookies.get("conf");if(cookie){var conf=$.secureEvalJSON(cookie);
if(conf.store&&conf.maximum_price&&conf.indices){if(typeof conf.indices!=="string"){R.c.am=conf
}}}},updateCurrentIndices:function(){var indices_selected=$.map($("#settings INPUT[name='cb_index']:checked"),function(n,i){return n.value
});if(indices_selected.length==0){indices_selected=R.c.am.indices}indices_selected=$.grep(indices_selected,function(n,i){return($.inArray(n,R.d.am[R.c.am.store].indices)>-1)?true:false
});if(indices_selected.length>0){R.c.am.indices=indices_selected}var indices_all=$.sliceArray(R.d.am[R.c.am.store].indices,4);
for(var a=0;a<4;a++){var div=$("#indices_col_"+a);div.empty();$.each(indices_all[a],function(n,i){var is_active=($.inArray(i,R.c.am.indices)!=-1);
var name="";var name_trans=$("#translation .tr_i_"+i).get();if(name_trans.length==1){name=name_trans[0].innerHTML
}else{name=i.replace(/([A-Z])([a-z])/g," $1$2");name=$.trim(name)}div.append(["<label><input type='checkbox' name='cb_index' value='",i,"' ",(is_active?"checked='checked'":""),"/>",name,"</label>"].join(""))
})}}},Stack:{triggerUpdate:function(){if(R.d.stack.length<R.c.restock_threshold&&R.d.am.last_itempage===false&&(R.d.requests_active==0||(R.d.requests_active>0&&R.d.more_data_needed===true))){var indices=R.c.am.indices;
$.log("triggerUpdate:"+$.dump(indices));R.d.requests_active+=indices.length;R.Display.throbberShow();
$.each(indices,function(){var am_url=R.Stack.buildAmURL(this);$.log("[Stack.triggerUpdate] URL:\n"+am_url);
$.getScript(am_url)});$.log("[Stack.triggerUpdate] Everything requested")}},amCallback:function(data_arr){R.d.requests_active--;
$.log("data_arr.length: "+data_arr.length);if(data_arr.length<10){R.d.am.last_itempage_count++
}if(R.d.am.last_itempage_count==R.c.am.indices.length){R.d.am.last_itempage=true
}data_arr=$.grep(data_arr,function(item){if(typeof item!=="object"){return false
}var price_n_num=Number(item.price_n_num);var price_u_num=Number(item.price_u_num);
var too_low=item.price_n.match(/Too low/i)?true:false;var has_price=(item.price_n!=""||item.price_u!="");
var is_available=(parseInt(item.total_n,10)>0||parseInt(item.total_u,10)>0);var is_good_price=((price_n_num>=R.c.am.minimum_price&&price_n_num<=R.c.am.maximum_price)||(price_u_num>=R.c.am.minimum_price&&price_u_num<=R.c.am.maximum_price));
return(item.image&&!too_low&&has_price&&is_good_price&&is_available)});var arr=R.Stack.normalize(data_arr);
delete (data_arr);R.d.stack=$.makeArray(R.d.stack).concat(arr);var requests_done=R.c.am.indices.length-R.d.requests_active;
var progress=Math.floor((100/R.c.am.indices.length)*requests_done);if(progress<"100"){progress+="% done"
}else{progress=""}$("#progressbar").text("Loading… "+progress);if(R.d.requests_active>0){return
}R.d.am.itempage++;R.d.stack=$.shuffle(R.d.stack);$.log("R.d.stack.length: "+R.d.stack.length);
if(R.d.stack.length<R.c.restock_threshold&&R.d.am.last_itempage===false){$.log("[amCallback] More data needed, requesting more");
R.d.more_data_needed=true;R.Stack.triggerUpdate()}else{$.log("[Stack.amCallback] Got enough data, continuing");
R.d.more_data_needed=false;R.Display.throbberHide();R.Display.refresh();R.Display.unblock()
}},buildAmURL:function(index){index=String(index);var seed=new Date().getTime();
var url=["http://xml-",R.d.am[R.c.am.store].coco,".amznxslt.com/onca/xml","?Service=AWSECommerceService","&AssociateTag=",R.d.am[R.c.am.store].affid,"&AWSAccessKeyId=1XC18EP4SDREGSM8SWR2","&CallBack=R.Stack.amCallback","&Condition=All","&ContentType=text/javascript","&ItemPage=",R.d.am.itempage,"&Keywords=+","&MerchantId=All","&Operation=ItemSearch","&ResponseGroup=Medium,ItemAttributes,Offers,Reviews","&SearchIndex=",index,"&SubscriptionId=1XC18EP4SDREGSM8SWR2","&Style=http%3A//random.li/xslt/itemsearch.xsl","&seed=",seed].join("");
if($.inArray(index,R.d.am[R.c.am.store].priceless)===-1){url+=["&MaximumPrice=",R.c.am.maximum_price,"&MinimumPrice=",R.c.am.minimum_price].join("")
}return url},normalize:function(arr){var new_arr=[];$.each(arr,function(){var item={title:this.title,product_group:this.product_group,price_n:null,price_n_num:Number(this.price_n_num),price_u:null,price_u_num:Number(this.price_u_num),image:this.image,image_l:(this.image_l!="")?this.image_l:this.image,review:$("#translation .tr_noreview").text(),stars:"img/stars-0-0.gif",stars_text:"not yet rated",link:this.url};
if(this.product_group!=this.binding){item.product_group+=", "+this.binding}if(this.by.length>0){item.title=[this.by.join(", "),this.title].join(": ")
}if(this.price_n!=""){item.price_n=this.price_n.replace(/EUR\s*/,"\u20AC");item.price_n=item.price_n.replace(/CDN\$\s*/,"$")
}else{item.price_n=null;item.price_n_num=null}if(this.price_u!=""){item.price_u=this.price_u.replace(/EUR\s*/,"\u20AC");
item.price_u=item.price_u.replace(/CDN\$\s*/,"$")}else{item.price_u=null;item.price_u_num=null
}if(this.reviews.length>0){var review="";var er_longest=0;var er_index=0;var num_er=this.reviews.length;
for(var a=0;a<num_er;a++){if(this.reviews[er_index].length>er_longest){er_index=a;
er_longest=this.reviews[er_index].length}}review=this.reviews[er_index];review=review.replace(/<\/?p[^>]*>/gi,"<br/><br/>");
review=review.replace(/<(?!br)[^>]*>/gi," ");review=review.replace(/(<br\/?>\s*<br\/?>\s*)+/gmi,"$1");
review=review.replace(/^\s*(<br\/?>\s*)+/gmi,"");try{item.review=decodeURIComponent(escape(review))
}catch(e){item.review=review}}if(this.stars!=""){item.stars=["img/stars-",this.stars.replace(/\./,"-"),".gif"].join("");
item.stars_text=this.stars+" stars"}new_arr.push(item)});return new_arr}},Set:{decrease:function(){R.d.current_set--;
if(R.d.current_set<0){R.d.current_set=0}R.Set.generate()},increase:function(){R.d.current_set++;
R.Set.generate()},generate:function(){if(R.d.stack.length<=R.c.per_set&&R.d.am.last_itempage===false&&R.d.requests_active>0){R.Display.block()
}if(!R.d.sets[R.d.current_set]&&R.d.stack.length>=R.c.per_set){var new_set=[];for(var a=0;
a<R.c.per_set;a++){try{new_set.push(R.d.stack.shift())}catch(e){$.log("[R.Set.generate](1): "+e)
}}R.d.sets[R.d.current_set]=new_set;R.Stack.triggerUpdate()}}},Display:{refresh:function(){R.Set.generate();
R.Display.setPrevNext();R.Display.drawItems();try{pageTracker._trackPageview(["/",R.c.am.store,"/",R.c.am.minimum_price,"-",R.c.am.maximum_price].join(""))
}catch(e){$.log("WARN: Couldn't track pageview.")}},clear:function(){for(var a=0;
a<R.c.per_set;a++){$("#item"+a).css("background-image","none");$("#item"+a+" P").text("")
}},drawItems:function(){R.Display.clear();for(var a=0;a<R.c.per_set;a++){var background_image="none";
var title="";var price_n="";var price_u="";if(R.d.sets[R.d.current_set]){if(R.d.sets[R.d.current_set][a]){var item=R.d.sets[R.d.current_set][a];
title=item.title;price_n=item.price_n;price_u=item.price_u;background_image="url('"+item.image+"')"
}}$("#item"+a).css("background-image",background_image);$("#item"+a+" H3").text(["Item ",(a+1),": ",title].join(""));
if(price_n){$("#item"+a+" P.new").html("<span class='offscreen'>"+$("#translation .tr_new").text()+": </span>"+price_n)
}if(price_u){$("#item"+a+" P.used").html("<span class='offscreen'>"+$("#translation .tr_new").text()+": </span>"+price_u)
}}$.log(["R.d.current_set: ",R.d.current_set,"\n","R.d.stack.length: ",R.d.stack.length,"\n","R.d.sets.length: ",R.d.sets.length,"\n","R.d.am.itempage: ",R.d.am.itempage,"\n","R.c.am.indices: ",R.c.am.indices,"\n","R.c.am.maximum_price: ",R.c.am.maximum_price,"\n","R.c.am.store: ",R.c.am.store,"\n"].join(""))
},showDetails:function(pos){var item=R.d.sets[R.d.current_set][pos];R.d.current_item_link=item.link;
$.log($.dump(item));$("#details").fadeOut("fast",function(){$("#details_welcome").remove();
$("#details .d_title, #details .d_price_n, #details .d_price_u, #details .d_review").empty();
$("#details DIV").show();$("#details .d_image IMG").attr("src",item.image_l);$("#details .d_link").attr("href",item.link);
$("#details .d_title").html(["<a href='",item.link,"' target='_blank'>",item.title," <span class='smaller'>[",item.product_group,"]</span></a>"].join(""));
if(item.price_n){var string=$("#translation .tr_new").text();$("#details .d_price_n").html(string+": "+item.price_n)
}if(item.price_u){var string=$("#translation .tr_used").text();$("#details .d_price_u").html(string+": "+item.price_u)
}$("#details .d_review").html(item.review);var background_image="url('"+item.stars+"')";
var string=$("#translation .tr_rating").text();$("#details_middle").css("background-image",background_image);
$("#details_middle .rating").text(string+": "+item.stars_text)});$("#details").fadeIn("fast")
},setPrevNext:function(){if(R.d.current_set===0){$("#navi .prev").css("visibility","hidden")
}else{$("#navi .prev").css("visibility","visible")}if(R.d.am.last_itempage===true){$("#navi .next").css("visibility","hidden")
}else{$("#navi .next").css("visibility","visible")}},throbberShow:function(){$("#throbber").css("visibility","visible")
},throbberHide:function(){$("#throbber").css("visibility","hidden")},block:function(){$.blockUI({message:$("#modals #fetching")});
R.d.display_blocked=true},unblock:function(){$.unblockUI();R.d.display_blocked=false
},prettify:function(){$('<span class="r_title">R<span class="smallcaps">ANDOM.LI</span></span>').replaceAll("SPAN:contains('RANDOM.LI')");
$.each($("LEGEND"),function(v,k){var t=$(k).text().toUpperCase();$(k).html([t.substring(0,1),'<span class="smallcaps">',t.substring(1),"</span>"].join(""))
})}},Debug:{dumpURLs:function(){var urls=[];$.each(["US","CA","DE","FR","UK"],function(){R.c.am.store=this;
$.each(R.d.am[this].indices,function(){urls.push(R.Stack.buildAmURL(this))})});
$.log(urls.join("\n"))}}};$(document).ready(function(){if(($.browser.msie&&$.browser.version=="6.0")||$.url.param("ie6")){$.blockUI({message:$("#modals #ie6zomg")})
}else{$("console.log").ready(function(){$.debug(R.c.debug);$.log("main.js v"+R.VERSION)
});$("#navi .prev A").click(function(e){R.Set.decrease();R.Display.refresh()});
$("#navi .next A").click(function(e){R.Set.increase();R.Display.refresh()});$("#settings INPUT[type='submit']").click(function(e){R.Display.block();
R.Form.submit();e.preventDefault()});$("#toggle_adv_settings").click(function(e){$("#adv_settings").slideToggle("slow");
$("#toggle_adv_settings .closed").toggle();$("#toggle_adv_settings .opened").toggle();
e.preventDefault()});$("#fs_indices A.mark_all").click(function(e){$("#fs_indices INPUT[type='checkbox']").attr("checked","checked");
e.preventDefault()});$("#fs_indices A.clear_all").click(function(e){$("#fs_indices INPUT[type='checkbox']").attr("checked","");
e.preventDefault()});$("DIV.item").click(function(e){var a=this.id.replace(/[^\d]+/g,"");
a=parseInt(a,10);R.Display.showDetails(a)});$("#radio .toggle").click(function(e){var h=($("#radio .player").css("height")=="0px")?"180px":"0px";
$("#radio .player").animate({height:h},500)});R.Display.block();R.Display.prettify();
R.Form.getCookie();R.Form.init();R.Stack.triggerUpdate();$("#details DIV").hide();
$("#details_welcome").html($("#welcome").html()).show();if(!$.url.param("nokb")){$(document).keypress(function(e){var allowed=[13,43,44,45,48,49,50,51,52,53,54,55,56,57];
if($.inArray(e.which,allowed)==-1||R.d.display_blocked===true){return}switch(e.which){case 13:if(R.d.current_item_link!==""){window.open(R.d.current_item_link,"_blank")
}break;case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:R.Display.showDetails(e.which-49);
break;case 44:R.Set.increase();R.Display.refresh();break;case 48:R.Set.decrease();
R.Display.refresh();break}})}}});