var cr = false, boc = null, mt, mq = new Array(), md = new Array();
String.prototype.format = function(o) { var s = this; for (var i = 0; i < arguments.length; i++) s = s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]); return s; }
var HR = {
  GetXHR: function() {
    if (window.XMLHttpRequest) return new XMLHttpRequest();
    for (n in { "Msxml2.XMLHTTP.6.0": 0, "Msxml2.XMLHTTP.3.0": 0, "Msxml2.XMLHTTP": 0, "Microsoft.XMLHTTP": 0 }) { try { return new ActiveXObject(n); } catch (e) { } }; return false;
  },
  Request: function(q, p, f, l, a) {
    var x = HR.GetXHR();
    if (!x) throw new Error("No AJAX interface available");
    x.onreadystatechange = function() { HR.Handle(x, f, l, a) };
    x.open("POST", q[0] == "/" ? q : "/Basket/{0}".format(q), f ? true : false);
    x.setRequestHeader("Content-Type", "application/json");
    if (l) l(x.readyState);
    x.send(JSON.stringify(p || {}));
    if (l && !f) l(x.readyState);
    return f ? x : JSON.parse(x.responseText).d;
  },
  Handle: function(x, f, l, a) {
    if (x.readyState == 4 && x.status == 500) throw new Error(x.responseText);
    if (f && x.readyState == 4 && x.status == 200) f(JSON.parse(x.responseText), a);
    if (l) l(x.readyState);
  },
  HasAJAX: function() { return xhr ? true : false; }
};
if (!this.JSON) { this.JSON = {}; } (function() { function f(n) { return n < 10 ? '0' + n : n; } if (typeof Date.prototype.toJSON !== 'function') { Date.prototype.toJSON = function(key) { return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null; }; String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function(key) { return this.valueOf(); }; } var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' }, rep; function quote(string) { escapable.lastIndex = 0; return escapable.test(string) ? '"' + string.replace(escapable, function(a) { var c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }) + '"' : '"' + string + '"'; } function str(key, holder) { var i, k, v, length, mind = gap, partial, value = holder[key]; if (value && typeof value === 'object' && typeof value.toJSON === 'function') { value = value.toJSON(key); } if (typeof rep === 'function') { value = rep.call(holder, key, value); } switch (typeof value) { case 'string': return quote(value); case 'number': return isFinite(value) ? String(value) : 'null'; case 'boolean': case 'null': return String(value); case 'object': if (!value) { return 'null'; } gap += indent; partial = []; if (Object.prototype.toString.apply(value) === '[object Array]') { length = value.length; for (i = 0; i < length; i += 1) { partial[i] = str(i, value) || 'null'; } v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']'; gap = mind; return v; } if (rep && typeof rep === 'object') { length = rep.length; for (i = 0; i < length; i += 1) { k = rep[i]; if (typeof k === 'string') { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } else { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}'; gap = mind; return v; } } if (typeof JSON.stringify !== 'function') { JSON.stringify = function(value, replacer, space) { var i; gap = ''; indent = ''; if (typeof space === 'number') { for (i = 0; i < space; i += 1) { indent += ' '; } } else if (typeof space === 'string') { indent = space; } rep = replacer; if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) { throw new Error('JSON.stringify'); } return str('', { '': value }); }; } if (typeof JSON.parse !== 'function') { JSON.parse = function(text, reviver) { var j; function walk(holder, key) { var k, v, value = holder[key]; if (value && typeof value === 'object') { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = walk(value, k); if (v !== undefined) { value[k] = v; } else { delete value[k]; } } } } return reviver.call(holder, key, value); } cx.lastIndex = 0; if (cx.test(text)) { text = text.replace(cx, function(a) { return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }); } if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { j = eval('(' + text + ')'); return typeof reviver === 'function' ? walk({ '': j }, '') : j; } throw new SyntaxError('JSON.parse'); }; } } ());

function OpenWindow(u, w, h, n, f) {
  var c = "";
  u = u || "about:blank";
  if (w) c += ",width=" + w;
  if (h && navigator.userAgent.toLowerCase().indexOf("safari") > 0) h = parseInt(h) + 30;
  if (h) c += ",height=" + h;
  c += (w || h) && (f == undefined || f == true) ? ",resizable=no,scrollbars=no" : c += ",resizable=yes,scrollbars=yes";
  var p = window.open(u, n, "left=" + ((screen.width - w) / 2) + ",top=" + ((screen.height - h) / 2 - 100) + ",toolbar=no,location=no,status=no,menubar=no" + c);
  if (p) p.focus();
  return p;
}


function $() {
  var es = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var e = arguments[i];
    if (typeof e == "string") e = document.getElementById(e);
    if (arguments.length == 1) return e;
    es.push(e);
  }
}
function AH(c, t, f, o) {
  if (c.addEventListener) return c.addEventListener(t, f, o);
  if (c.attachEvent) return c.attachEvent("on" + t, f);
}
String.prototype.format = function(o) { var s = this; for (var i = 0; i < arguments.length; i++) s = s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]); return s; }
function AC(t, h, p, a, c) {
  var e = document.createElement(t), k;
  if (h) e.innerHTML = h;
  if (a) for (k in a) e.setAttribute(k, a[k]);
  if (c) e.className = c;
  if (p) {
    if (typeof p == "string") p = document.getElementById(p);
    p = p || document.body;
    p.appendChild(e);
  }
  return e;
}

function ShowProduct(c) {
  location.href = "/Product/{0}".format(c);
}

function GP(c) { return c.id && c.id != "" ? c : c.parentNode ? GP(c.parentNode) : null; }


function QueueBasketMessage(m) {
  var c = AC("DIV", m, $("DivPopupBasketMessage"));
  md.push(c);
  setTimeout(ClearBasketMessage, 3000);
  $("DivPopupBasketMessage").style.display = "block";
}
function ClearBasketMessage() {
  var c = md.shift();
  $("DivPopupBasketMessage").removeChild(c);
  if (md.length == 0) $("DivPopupBasketMessage").style.display = "none";
}


// Sequential
/*function QueueBasketMessage(m) {
mq.push(m);
PingBasketMessage();
}
function PingBasketMessage() {
if (mt) return false;
ShowNextBasketMessage();
}
function ShowNextBasketMessage() {
if (mq.length == 0) {
$("DivPopupBasketMessage").style.display = "none";
if (mt) clearInterval(mt);
mt = null;
} else {
$("DivPopupBasketMessage").innerHTML = mq[0];
$("DivPopupBasketMessage").style.display = "block";
if (!mt) mt = setInterval(ShowNextBasketMessage, 2000);
mq.shift();
}
}*/

function PopupBasket(s) {
  var c = $("DivPopupBasket");
  c.style.display = s ? "block" : "none";
  return false;
}


function PopupTracking(s) {
  var c = $("DivHeaderTrack");
  c.style.display = s ? "block" : "none";
  return false;
}


function PopupCountryList() {
  var c = $("DivCountrySelect"), v = c.className == "countryselectvisible", sc = $("LISelectedCountry");
  c.className = v ? "" : "countryselectvisible";
  $("SpanCountryChange").innerHTML = "(Click to {0}...)".format(v ? "change" : "close");
  if (sc) $("DivCountryList").scrollTop = sc.offsetTop;
  //boc = v ? PopupCountryList : null;
  return false;
}

function PopupImage(c) {
  if (!c) return false;
  var s = c.getAttribute("img");
  if (!s) return false;
  if (c.childNodes.length == 0) {
    var im = AC("IMG", null, c, { "src": s });
  } else {

  }
  c.style.display = c.style.display != "block" ? "block" : "none";
}


function Flash(c, i, t, b, f) {
  c.style.backgroundColor = b[i - 1];
  c.style.color = f[i - 1];
  i--;
  if (i < 1) return false;
  setTimeout(function() { Flash(c, i, t, b, f); }, t);
}

function ChangeCountry(i, r) {
  if (r != undefined) {
    window.location.reload();
  } else {
    HR.Request("SetCountry", { "Country": i }, function(r) { ChangeCountry(i, r) });
  }
}

function ChangeShippingOption(i, r) {
  if (r != undefined) {
    window.location.href = window.location.href;
  } else {
    HR.Request("SetShipping", { "ShippingID": i }, function(r) { ChangeShippingOption(i, r) });
  }
}

function BasketProduct(i, q, a, r) {
  if (r != undefined) {
    QueueBasketMessage("Added {0} <b>{1}</b> to your basket".format(r.Quantity, r.Name));
    GetBasket();
  } else {
    HR.Request("Add", { "ProductID": i, "Quantity": parseInt(q) || 1, "Absolute": a || false }, function(r) { BasketProduct(i, q, a, r) });
  }
}

function GetBasket(r) {
  if (r) {
    var cbi = $("DivBasketItems");
    cbi.innerHTML = "";
    if (r.Items.length > 0) {
      for (var i = 0; i < r.Items.length; i++) {
        var p = r.Items[i], c = AC("DIV", null, cbi);
        c.innerHTML = "<div><label class=\"name\"><a href=\"/Product/{0}\" pid=\"{0}\" action=\"V\">{1}</a></label><label class=\"adjustors\"><a href=\"/Basket/Add/{0}/-1\" pid=\"{0}\" action=\"R\">-</a><a href=\"/Basket/Add/{0}/1\" pid=\"{0}\" action=\"A\">+</a></label><label class=\"qtyprice\">&pound;{2} ({3} @ &pound;{4})</label><br /></div>";
        c.innerHTML = c.innerHTML.format(p.ID, p.Name, p.LineTotal.toFixed(2), p.Quantity, p.Price.toFixed(2));
      }
    } else {
      AC("DIV", "<label class=\"name\">No items in basket</label>", cbi);
    }
    $("SpanTotal").innerHTML = r.Total.toFixed(2);
    $("SpanItems").innerHTML = r.Count;
  } else {
    HR.Request("View", null, function(r) { GetBasket(r) });
  }
}

function HandleBasketClick(e) {
  e = e || window.event;
  var c = e.srcElement || e.target, pid = c.getAttribute("pid"), a = c.getAttribute("action");
  if (pid && !isNaN(pid) && a) {
    if (a == "V") {
      location.href = "/Product/{0}".format(pid);
    } else {
      BasketProduct(pid, a == "R" ? -1 : 1);
    }
  }
  return false;
}

function OpenFBWindow() {
  var u = "http://www.facebook.com/sharer.php?u={0}&t={1}".format(encodeURIComponent(location.href), encodeURIComponent(document.title));
  OpenWindow(u, 600, 300, "FBPopup", true);
}

function OpenTwitWindow() {
  var u = "http://twitter.com/login?redirect_after_login=%2Fhome%3Fstatus%3D{0}%2B{1}".format(encodeURIComponent(location.href), encodeURIComponent(document.title));
  OpenWindow(u, 800, 420, "TwitPopup", false);
}

function MailLink() {
  location.href = "mailto:?subject={0}&body={1}".format(encodeURIComponent(document.title), encodeURIComponent(location.href))
}

function goCheckout(){
_gaq.push(['https://cuffs.tretail.net/Checkout', this]);
location.href = '/Checkout';
}

function checkCountry(c){
$("DivHeaderPhone").style.display = c == "United Kingdom" ? "block" : "none";
}

function Startup() {
AH(document.body, "click", HBOC);
}

function HBOC(e) {
  if (boc) boc();
  boc = null;
}





AH(window, "load", Startup);




var bic = 4, bti = 2500, hbi = 0, hbt, hbic = new Array(), url = new Array("/Category/75", "/Category/65", "/Product/NV-002", "/Category/79");
function FlipHomeBanner(e) {
  PauseFlipHomeBanner();
  var i, ul = $("ULBannerButtons");
  e = e || window.event;
  if (e) i = parseInt((e.srcElement || e.target).getAttribute("i"));
  if (ul.childNodes.length < bic) for (var c = 0; c < bic; c++) AC("LI", null, ul, { "i": c });
  var cs = ul.getElementsByTagName("LI"), t = isNaN(i);
  i = i || hbi; if (i >= bic) i = 0;
  $("DivBanner").style.backgroundImage = "url({0})".format(hbic[i].src);
  $("DivBanner").setAttribute("i", i);
  for (var c = 0; c < cs.length; c++) cs[c].className = c == i ? "selected" : "";
  hbi = i + 1;
  if (t) ResumeFlipHomeBanner();
}
function ClickHomeBanner(e) {
  e = e || window.event;e = e.srcElement || e.target;
  if (e.id != "DivBanner") return;
 location.href = url[parseInt(e.getAttribute("i"))];
}
function PauseFlipHomeBanner() { if (hbt) clearTimeout(hbt); }
function ResumeFlipHomeBanner() { hbt = setTimeout(FlipHomeBanner, bti) }
if (location.pathname == "/" || location.pathname == "/Index.twp") {
  for (var i = 0; i < bic; i++) {
    hbic[hbic.length] = new Image();
    hbic[hbic.length - 1].src = "/Images/home_{0}.jpg".format(i);
  }
}

if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
  ie6 = true;
  document.write("<link rel=\"stylesheet\" href=\"/CSS/IE6.css\" TYPE=\"text/css\">");
}



var _gaq = new Array();
_gaq.push(['_setAccount', 'UA-19750781-1']);
_gaq.push(['_setDomainName', '.cuffsandco.co.uk']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]); 
_gaq.push(['_trackPageview']); 
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(ga, s); 
