function get_slug(href){var rg=href.split('/');if(rg.length==0)
return;var slug=rg[rg.length-1];if(slug.length==0&&rg.length>1){slug=rg[rg.length-2];}
return slug;}
String.prototype.format=function(){var pattern=/\{\d+\}/g;var args=arguments;return this.replace(pattern,function(capture){return args[capture.match(/\d+/)];});}
var satchmo=satchmo||{};satchmo.add_to_cart_success=function(data,productname){var msg=" ("+data["cart_count"]+")";$('#id_cart').text(msg);satchmo.show_success_msg(data,msg_added_to_cart);}
satchmo.add_to_wishlist_success=function(data,productname){satchmo.show_success_msg(data,msg_added_to_wischlist);}
satchmo.show_success_msg=function(data,msg_format){var msg=msg_format.format(data["name"]);$('#ajax_message').text(msg);var popMargLeft=($('#ajax_message').width()+20)/2;$('#ajax_message').css({'margin-left':-popMargLeft});$('#ajax_message').fadeIn().delay(1000).fadeOut();}
satchmo.show_ajax_error=function(xhr,status,error){var msg=xhr.responseText;$('#ajax_message').text(msg);$('#ajax_message').css("display","block");}
satchmo.add_to_cart=function(productname){$.ajax({type:"POST",url:url_satchmo_smart_add,dataType:"json",error:function(xhr,status,errorText){satchmo.show_ajax_error(xhr,status,errorText);},data:{productname:productname,quantity:1},success:function(data){satchmo.add_to_cart_success(data);}});}
satchmo.add_to_wishlist=function(productname){$.ajax({type:"POST",url:url_satchmo_wishlist_add_ajax,dataType:"json",error:function(xhr,status,errorText){satchmo.show_ajax_error(xhr,status,errorText);},data:{productname:productname,quantity:1},success:function(data){satchmo.add_to_wishlist_success(data);}});}
var enquire={init:function(){appliedMedia=false;jQuery(document).ready(function($){if(is_desktop()){$("#media-nav").append('<ul><li class="label">'+text_views+': </li><li><a href="#" class="desktop" title="'+text_title_desktop+'">'+text_desktop+'</a></li><li><a href="#" class="mobile" title="'+text_title_mobile+'">'+text_mobile+'</a></li><li><a href="#" class="print" title="'+text_title_print+'">'+text_print+'</a></li></ul>');$("#media-nav  a.mobile").click(function(){selectStylesheetsByMedia('handheld');return false;});$("#media-nav a.print").click(function(){selectStylesheetsByMedia('print');return false;});$("#media-nav a.desktop").click(function(){selectStylesheetsByMedia('screen');return false;});$("link[rel=stylesheet], style").each(function(){$(this).data("media",this.media);});recordedMedia=$.cookie('logos_style');if(recordedMedia){selectStylesheetsByMedia(recordedMedia);}else{detectAppliedMedia();}}
$("a.fl").click(function(){var href=$(this).attr('href');satchmo.add_to_cart(get_slug(href));return false;});$("a.atw").click(function(){var href=$(this).attr('href');satchmo.add_to_wishlist(get_slug(href));return false;});if($("body").hasClass("logos_screen")){$(".selected").filter(":first").focus();}
$(document).ajaxSend(function(event,xhr,settings){function getCookie(name){var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}
function sameOrigin(url){var host=document.location.host;var protocol=document.location.protocol;var sr_origin='//'+host;var origin=protocol+sr_origin;return(url==origin||url.slice(0,origin.length+1)==origin+'/')||(url==sr_origin||url.slice(0,sr_origin.length+1)==sr_origin+'/')||!(/^(\/\/|http:|https:).*/.test(url));}
function safeMethod(method){return(/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));}
if(!safeMethod(settings.type)&&sameOrigin(settings.url)){xhr.setRequestHeader("X-CSRFToken",getCookie('csrftoken'));}});});function is_desktop(){return($("#logo a img").css("display")=='none');}
function switchDisplayMode(media){$("#media-nav a").each(function(){this.href="#";$(this).removeClass('disabled');});if(media=='handheld'){$("body").addClass("logos_handheld");$("body").removeClass("logos_print");$("body").removeClass("logos_screen");$("#media-nav a.mobile").removeAttr("href").addClass("disabled");}else if(media=='print'){$("body").addClass("logos_print");$("body").removeClass("logos_handheld");$("body").removeClass("logos_screen");$("#media-nav a.print").removeAttr("href").addClass("disabled");}else{$("body").addClass("logos_screen");$("body").removeClass("logos_handheld");$("body").removeClass("logos_print");$("#media-nav a.desktop").removeAttr("href").addClass("disabled");}}
function detectAppliedMedia(){if(is_desktop()){if(!appliedMedia||appliedMedia!='screen'){switchDisplayMode("screen");appliedMedia="screen";}}else{if(!appliedMedia||appliedMedia!='handheld'){switchDisplayMode("handheld");appliedMedia="handheld";}}}
function selectStylesheetsByMedia(media){switchDisplayMode(media);$("link[rel=stylesheet], style").each(function(){if($(this).data&&($(this).data("media").indexOf(media)>=0||$(this).data("media").indexOf("all")>=0)){this.disabled=false;}else{this.media=$(this).data("media");this.disabled=true;}});recordedMedia=$.cookie('logos_style');if(recordedMedia!=media){$.cookie('logos_style',media,{path:'/'});}}}};jQuery.cookie=function(key,value,options){if(arguments.length>1&&String(value)!=="[object Object]"){options=jQuery.extend({},options);if(value===null||value===undefined){options.expires=-1;}
if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days);}
value=String(value);return(document.cookie=[encodeURIComponent(key),'=',options.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));}
options=value||{};var result,decode=options.raw?function(s){return s;}:decodeURIComponent;return(result=new RegExp('(?:^|; )'+encodeURIComponent(key)+'=([^;]*)').exec(document.cookie))?decode(result[1]):null;};enquire.init();
