if(!Array.prototype.indexOf)
{Array.prototype.indexOf=function(elt)
{var len=this.length>>>0;var from=Number(arguments[1])||0;from=(from<0)?Math.ceil(from):Math.floor(from);if(from<0)
from+=len;for(;from<len;from++)
{if(from in this&&this[from]===elt)
return from;}
return-1;};}
var compare=function(){var self=this;this.locale_to_name={us:"amazon.com",uk:"amazon.co.uk",de:"amazon.de",fr:"amazon.fr",ca:"amazon.ca",jp:"amazon.co.jp",es:"amazon.es",it:"amazon.it"};this.sort_column=6;this.init=function(price_table,locale_urls){self.price_table=price_table;self.locale_urls=locale_urls;$("ul.tabs li").click(function(){$("ul.tabs li").removeClass("active");$(this).addClass("active");self.loadPrices($(this).text().split(" ")[0].toLowerCase().replace(/[0-9]/,""));createCookie("preferred-compare-tab",$(this).text(),365*2);return false;});var tab_text=readCookie("preferred-compare-tab")||$("ul.tabs li:first").text();var tab=$("ul.tabs li:contains('"+ tab_text+"')");if(!tab[0]){tab=$("ul.tabs li:first");}
tab.click();}
this.loadPrices=function(type){$("#price-table tbody tr").remove();if(type=="all"){var sorted_list=[]
$.each(self.price_table,function(key,value){var results=[];$.each(self.price_table[key],function(locale,locale_value){results.push([key,locale]);});sorted_list=sorted_list.concat(results);})
sorted_list.sort(function(a,b){return self.price_table[a[0]][a[1]][self.sort_column]- self.price_table[b[0]][b[1]][self.sort_column];});for(index in sorted_list){var type=sorted_list[index][0];var locale=sorted_list[index][1];if(self.price_table[type]){var p=self.price_table[type][locale];$("#price-table tbody").append("<tr><td class='all_"+ type+"'>"+ self.locale_to_name[locale].replace("amazon","")+" ("+ type+")</td><td>"+ p[1]+"</td><td>"+ p[3]+"</td><td>"+(p[4]==0.0?"<span class='free'>free shipping</span>":p[5])+"</td><td>"+ p[7]+"</td><td><a href='http://www."+ self.locale_to_name[locale]+ self.locale_urls[locale]+"'>buy</a></td></tr>");}}}else{var sorted_list=[];if(self.price_table[type]){$.each(self.price_table[type],function(key,value){sorted_list.push(key);});sorted_list.sort(function(a,b){return self.price_table[type][a][self.sort_column]- self.price_table[type][b][self.sort_column];});for(index in sorted_list){var locale=sorted_list[index];if(self.price_table[type]&&self.price_table[type][locale]){var p=self.price_table[type][locale];$("#price-table tbody").append("<tr><td class='all_"+ type+"'>"+ self.locale_to_name[locale]+"</td><td>"+ p[1]+"</td><td>"+ p[3]+"</td><td>"+(p[4]==0.0?"<span class='free'>free shipping</span>":p[5])+"</td><td>"+ p[7]+"</td><td><a href='http://www."+ self.locale_to_name[locale]+ self.locale_urls[locale]+"'>buy</a></td></tr>");}}
for(locale in self.locale_to_name){if(!self.price_table[type][locale]){$("#price-table tbody").append("<tr><td class='all_"+ type+"'>"+ self.locale_to_name[locale]+"</td><td>-</td><td>-</td><td>-</td><td>-</td><td><a href='#'></a></td></tr>");}}}}
$("#price-table tbody tr").click(function(e){window.location.href=$(this).find("a").attr("href");})}
return this;}
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else var expires="";document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
var initSearch=function(){$("#search-form").submit(function(){window.location.href=$(this).attr("action")+ encodeURIComponent($("#search").val());return false;})
$("#search-button").click(function(){$("#search-form").submit();return false;});}
var siteClickHandler=function(){var country=$(this).attr("href").slice(1);$(".locale-item").hide();if(country=="all"){var items=[];$.each($(".locale-item"),function(item){var link=$(this).find("a").attr("href");if(items.indexOf(link)==-1){items.push(link);$(this).show();}});}else{$(".locale-"+country).show()}
$(".filter-site li").removeClass("filter-selected")
$(this).parent("li").addClass("filter-selected")
createCookie("preferred-site",country,365*2);return false;}
var sectionClickHandler=function(){var section=$(this).text()
$(".filter-section li").removeClass("filter-selected")
$(this).parent("li").addClass("filter-selected")
createCookie("preferred_section",section,365*2);return true;}
var initList=function(){$(".filter-site li a").click(siteClickHandler);$(".filter-section li a").click(sectionClickHandler);var selected_site=readCookie("preferred-site")||"all";$(".filter-site li a").each(function(index,obj){if($(obj).attr("href")=="#"+ selected_site){$(obj).click();}})
$(".search-price.red").attr("title","Used (including shipping costs)")
$(".search-price.green").attr("title","Third Party (including shipping costs)")
$(".search-price.blue").attr("title","New (Amazon) (including shipping costs)")
$(".search-price").click(function(){if($(this).hasClass("red")){createCookie("preferred-compare-tab","Used",365*2);}else if($(this).hasClass("green")){createCookie("preferred-compare-tab","Third Party",365*2);}else if($(this).hasClass("blue")){createCookie("preferred-compare-tab","New (Amazon)",365*2);}
location.href=$(this).parents(".locale-item").find("a").attr("href");})}
$(function(){$("#change_country").click(function(){$("#selector_country").show();$("#current_country").hide();})
$("#select_country").change(function(){location.href='?country='+ $(this).val();createCookie("country",$(this).val(),365*2);})})
