
var wedgeDisplayMode = 'canvas';
var Controller;
(function() {
var cId = 0;
var animator = {
limit : 0,
registry : {},
speed : 1,
timer : null,
register : function (task) {
if (! (task.target.id in this.registry) ) {
this.registry[task.target.id] = {};
}
this.registry[task.target.id][task.attr] = task;
},
start : function() {
if (this.timer) {
return;
}
this.limit = 0;
this.timer = setInterval(function(){animator.run();},this.speed);
},
stop : function() {
clearInterval(this.timer);
this.timer = null;
registry = {};
},
run : function() {
var done = 0;
for (var element in this.registry) {
var e = this.registry[element];
for (var attr in e) {
e[attr].go();
done++;
if (!e[attr].isActive) {
delete e[attr];
}
}
}
if (!done) {
this.stop();
}
},
addTask : function(task) {
this.register(task);
this.start();
},
};
Controller = {
controls : {},
currentWidth : null,
deferred : {}, /* deferred content gets registered here */
formIds : 0,
forms : {},
gadgets : {},
gadgetTags : [ 'div' , 'ul', 'input', 'li', 'td' ],
plog : [],
scrollTimer : null,
registeredControl : function(node) {
var controlElement = node.ascendDOMTree(function(node) {return (node.id in Controller.controls);});
if (controlElement) {
return this.controls[controlElement.id];
}
},
registerForm : function(node) {
var formElement = node.ascendDOMTree(function(node) { return (node.tagName === 'FORM'); });
if (!formElement.id) {
formElement.id = '_form_' + (++this.formIds);
}
if (!this.forms[formElement.id]) {
this.forms[formElement.id] = formElement;
}
return formElement.id;
},
formSubmit : function(formId, name, value) {
var hidden = document.createElement('input');
hidden.setAttribute('type', 'hidden');
hidden.setAttribute('name', name);
hidden.setAttribute('value', value);
this.forms[formId].appendChild(hidden);
this.forms[formId].submit();
},
initGadget : function(node) {
if (!this.gadgets[node.id]) {
var gadget;
switch (node.getAttribute('behavior')) {
case 'List' :
gadget = new List(node);
break;
case 'Scroll' :
gadget = new Scroll(node);
break;
case 'Expand' :
gadget = new Expand(node);
break;
case 'Overlay' :
gadget = new Overlay(node);
break;
case 'Link' :
gadget = new LinkingElement(node);
break;
}
}
},
freeNode : function(node) {
delete this.gadgets[node.id];
node.processTags(
{
tagName : this.gadgetTags,
hasAttribute : 'behavior'
},
function(node) {
if (node.id) {
delete Controller.gadgets[node.id];
}
}
);
},
initNode : function(node,isNewPage) {
if (isNewPage) {
setTimeout(function(){
node.processTags(
{tagName : 'img', hasAttribute : 'dsrc'},
loadImg
);
}, 10);
node.processTags(
{ tagName : 'div', hasAttribute : 'noRender' },
markRendered
);
}
node.processTags(
{ tagName : 'canvas', hasAttribute : 'type' },
draw
);
node.processTags(
{ tagName : this.gadgetTags, hasAttribute : 'behavior' },
function(node){
Controller.initGadget(node);
}
);
if (isNewPage && document.body.hasAttribute('postloadurl')) {
node.processTags(
{tagName : 'span', hasAttribute : 'deferred'},
function(node) {
Controller.registerDeferredContent(node);
}
);
Controller.loadDeferredContent();
}
},
registerDeferredContent : function(node) {
var deferredContentType = node.getAttribute('deferred');
var id = node.getAttribute('id');
if (! (deferredContentType in this.deferred) ) {
this.deferred[deferredContentType] = {};
}
this.deferred[deferredContentType][id] = node;
},
loadDeferredContent : function() {
var q = [];
var nodeMap = {};
var url = document.body.getAttribute('postloadurl');
if (!url) {
return;
}
for (var deferredContentType in this.deferred) {
for (var id in this.deferred[deferredContentType]) {
q.push(deferredContentType + '=' + id);
if (! (deferredContentType in nodeMap) ) {
nodeMap[deferredContentType] = {};
}
nodeMap[deferredContentType][id] = this.deferred[deferredContentType][id];
delete this.deferred[deferredContentType][id];
}
}
if (!q.length) {
return;
}
var qs = q.join('&');
url += '&' + qs;
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
var responses = req.responseText.parseJSON();
for (var deferredContentType in responses) {
for (var id in responses[deferredContentType]) {
var node = nodeMap[deferredContentType][id];
if (node) {
node.replaceWithSource(responses[deferredContentType][id]);
}
}
}
}
};
req.open("GET", url, true);
req.send(null);
},
click : function(target) {
var clickTarget = this.registeredControl(target);
if (clickTarget) {
clickTarget.click();
}
},
init : function() {
scrollTop();
addEventListener('load',
function(event) {
Controller.initNode(document.body,true);
Controller.setAspect();
document.body.setAttribute('onorientationchange', "Controller.setAspect(this)");
},
0
);
},
setAspect : function() {
var aspect = "tall";
switch (window.orientation) {
case 0 : aspect = "tall"; break;
case 180 : aspect = "tall"; break;
case 90 : aspect = "wide"; break;
case -90 : aspect = "wide"; break;
}
if (aspect != document.body.getAttribute("aspect")) {
document.body.setAttribute("aspect", aspect);
}
},
lockScroll : function() {
this.scrollTimer = setInterval(
function() {
if (window.pageYOffset > 1) {
scrollTop();
}
},
100
);
},
unlockScroll : function() {
clearInterval(this.scrollTimer);
this.scrollTimer = null;
}
};
Controller.init();
function markRendered(node) {
node.processTags(
{tagName : 'canvas'},
function(node) {node.setAttribute("rendered",1);}
);
}
function markUnrendered(node) {
node.processTags(
{tagName : 'canvas'},
function(node) {node.removeAttribute("rendered");}
);
}
function scrollTop() {
setTimeout(scrollTo, 100, 0, 1);
}
var drawfuncs = {
'button' : drawButton,
'button-left' : drawButton,
'button-right': drawButton,
'button-round': drawButton,
'image-button': drawImageButton,
'stars' : drawStars,
};
var symfuncs = {
'wedge-down' : drawWedgeDown,
'wedge-up' : drawWedgeUp,
};
var symimgs = {
'wedge-down' : "http://g-ecx.images-amazon.com/images/G/01/anywhere/chrome/boxed_arrow_down._V156379827_.png",
'wedge-up' : "http://g-ecx.images-amazon.com/images/G/01/anywhere/chrome/boxed_arrow_up._V156379787_.png",
};
function loadImg(img) {
img.src = img.getAttribute("dsrc");
img.removeAttribute("dsrc");
}
function draw(canvas) {
if (canvas.hasAttribute("rendered")) {
return;
}
var encl;
if (! canvas.hasAttribute("id") ) {
canvas.id = canvas.getAttribute('type') + (++cId);
}
if (canvas.hasAttribute("text") || canvas.hasAttribute("action")) {
encl = document.createElement('div');
encl.addClass("button");
encl.style.width = canvas.getAttribute('width');
encl.style.height = canvas.getAttribute('height');
canvas.reparent(encl);
if (canvas.hasAttribute('action')) {
encl.setAttribute('action',canvas.getAttribute('action'));
encl.id = '_' + canvas.id;
} else if (canvas.hasAttribute('formInput')) {
var formId = Controller.registerForm(canvas);
var formValue = canvas.getAttribute('formValue') || canvas.getAttribute('text') || 1;
encl.setAttribute("onClick",
"Controller.formSubmit('" +
formId +
"', '" +
canvas.getAttribute('formInput') +
"', '" +
formValue +
"')"
);
encl.id = '_' + canvas.id;
}
} else {
encl = canvas;
}
drawfuncs[canvas.getAttribute("type")](encl, canvas);
}
var colWhite = rgba([255, 255, 255, 1.0]);
var colBlack = rgba([ 0, 0, 0, 1.0]);
var colShadow = rgba([ 0, 0, 0, 0.7]);
var colOrange = rgba([255, 119, 0, 1.0]);
var colDarkBlue = rgba([ 0, 0, 102, 1.0]);
var colYellow = rgba([255, 165, 0, 1.0]);
var colors = {
'red' :
{ color : [255, 0, 0, 1], fade : .5 , text : colWhite },
'black':
{ color : [0, 0, 0, 1], fade : .5 , text : colWhite },
'gray' :
{ color : [180, 180, 180, 1], fade : .5 , text : colBlack },
'yellow' :
{ color : [251, 192, 50, 1], fade : .75 , text : colDarkBlue, border : colDarkBlue },
'blue' :
{ color : [0, 0, 255, 1], fade : .75 , text : colWhite },
'lightBlue' :
{ color : [140, 160, 190, 1], fade : .75 , text : colWhite, border : rgba([180, 180, 180, 1]) },
'bone' :
{ color : [226, 226, 190, 1], fade : .5 , text : colDarkBlue, border : rgba([155, 155, 113, 1.0]) },
'amazonOrange' :
{ color : [228, 121, 17, 1], fade : .75 , text : colDarkBlue, border :colDarkBlue },
'preorderYellow' :
{ color : [255, 255, 135, 1], fade : .75 , text : colDarkBlue, border :colDarkBlue },
'white' :
{ color : [255, 255, 255, 1], fade : 1, text : colOrange, border : rgba([155, 155, 113, 1.0]) },
};
function drawButton(cont, c) {
c.setAttribute("rendered", 0);
var context = c.getContext("2d");
var type = c.getAttribute("type");
var color = colors[c.getAttribute("color")] || colors['red'];
color['textShadow'] = (color.text == colWhite ? colShadow : colWhite);
var text = c.getAttribute("text");
var symbol = c.getAttribute("symbol");
var typeSize = c.getAttribute("textSize");
var h = c.height;
var w = c.width;
var isSmall = Math.min(w, h) <= 20;
if (color.fade < 1) {
var lowerColor = rgba(color.color);
var upperColor = rgba( [Math.floor(255 - (255-color.color[0]) * color.fade ),
Math.floor(255 - (255-color.color[1]) * color.fade ),
Math.floor(255 - (255-color.color[2]) * color.fade ),
1.0
]
);
var gr = context.createLinearGradient(w/2, h, w/2, 0);
gr.addColorStop(0, lowerColor);
gr.addColorStop(0.5, lowerColor);
gr.addColorStop(0.5001, upperColor);
gr.addColorStop(0.75, upperColor);
gr.addColorStop(1, colWhite);
context.fillStyle = gr;
} else {
context.fillStyle = rgba(color.color);
}
var lw = c.getAttribute("leeway") || 3;
var r = c.getAttribute("radius") || h/5;
var hh = (h-(2*lw))/2;
var xmin = lw; var xmax = w-lw;
var ymin = lw; var ymax = h-lw;
var aoff = (h-(2*lw))/(2.75);
if (type == 'button-round') {
context.arc(w/2, h/2, hh, 0, 6.2832, 1);
} else {
if (type == 'button-left') {
context.moveTo(xmin + aoff, ymin);
} else {
context.moveTo(xmin + r, ymin);
}
if (type == 'button-right') {
context.lineTo(xmax - aoff, ymin );
context.lineTo(xmax, ymin + hh);
context.lineTo(xmax - aoff, ymax );
} else {
context.lineTo(xmax - r, ymin );
context.arcTo( xmax, ymin, xmax, ymin + r, r);
context.lineTo(xmax, ymax - r );
context.arcTo( xmax, ymax, xmax - r, ymax, r);
}
if (type == 'button-left') {
context.lineTo(xmin + aoff, ymax );
context.lineTo(xmin, ymin + hh);
context.lineTo(xmin + aoff, ymin );
} else {
context.lineTo(xmin + r, ymax);
context.arcTo( xmin, ymax, xmin, ymax - r, r);
context.lineTo(xmin, ymin + r);
context.arcTo( xmin, ymin, xmax + r, ymin, r);
}
}
context.fill();
if (isSmall) {
context.strokeStyle = colWhite;
context.lineWidth = 2.5;
context.stroke();
}
context.strokeStyle = color.border || colBlack;
context.lineWidth = Math.min(Math.min(w,h)/20, 1.5);
context.stroke();
if (text && cont.tagName == 'DIV') {
buttonText(
cont,
text,
{
'fontWeight' : 'bold',
'fontSize' : typeSize || Math.max((3/4) * hh, 11),
'color' : color.text,
}
);
}
if (symbol) {
context.save();
context.translate(w/2, h/2);
context.moveTo(0, 0);
context.beginPath();
context.fillStyle = color.text;
context.strokeStyle = color.text;
symfuncs[symbol](context, xmax-xmin, ymax-ymin);
}
c.setAttribute("rendered", 1);
}
function drawWedgeDown (context, w, h) {
context.save();
context.scale(h/100, h/100);
context.moveTo(-30, -27);
context.lineTo( 30, -27);
context.lineTo( 0, 32);
context.lineTo(-30, -27);
context.fill();
context.restore();
}
function drawWedgeUp (context, w, h) {
context.save();
context.rotate(3.1415);
drawWedgeDown(context, w, h);
context.restore();
}
function buttonText(cont, string, style) {
var text = document.createElement('div');
text.innerHTML = string;
for (var property in style) {
text.style[property] = style[property];
}
text.setStyle( {
position : 'absolute',
left : 0,
width : cont.style.width,
textAlign : 'center'
} );
cont.appendChild(text);
text.style.top = Math.floor((cont.getAttr('height') - text.clientHeight) / 2) + "px";
}
var starCoordinates = [
[ 50, 0], [ 62, 36], [100, 36], [ 69, 59], [ 81,100],
[ 50, 78], [ 19,100], [ 31, 59], [ 0, 36], [ 38, 36],
];
function drawStars(containingDiv,canvas) {
var context = canvas.getContext("2d");
context.fillStyle = colYellow;
context.lineWidth = 4;
var ratingPercentage = canvas.getAttribute("percentage");
context.scale(canvas.width/500,canvas.height/100);
for (var j = 0; j < 5; j++) {
context.beginPath();
var xOffset = j * 100;
var fillPercent
= ratingPercentage > 20 * (j + 1) ? 100
: ratingPercentage < 20 * j ? 0
: .05* (ratingPercentage - (20 * j))
;
context.moveTo(
starCoordinates[0][0] + xOffset,
starCoordinates[0][1]
);
for (var i = 1; i < starCoordinates.length; i++) {
context.lineTo(
starCoordinates[i][0] + xOffset,
starCoordinates[i][1]
);
}
context.lineTo(
starCoordinates[0][0] + xOffset,
starCoordinates[0][1]
);
context.stroke();
if (fillPercent) {
context.save();
context.clip();
context.fillRect( xOffset, 0, 100*fillPercent, 100);
context.restore();
}
}
canvas.setAttribute("rendered", 1);
}
function drawImageButton(cont, i) {
i.setAttribute("rendered", 0);
var color = rgba((colors[i.getAttribute("color")] || colors['red']).color);
var symbol = i.getAttribute("symbol");
var h = i.height;
var w = i.width;
i.src = symimgs[symbol];
i.style.backgroundColor = color;
i.setAttribute("rendered", 1);
}
var buttonDefaults = {
type : 'button'
};
function newButton (attrs) {
var button = document.createElement('canvas');
for (attr in buttonDefaults) {
button.setAttribute(attr, buttonDefaults[attr]);
}
for (attr in attrs) {
button.setAttribute(attr, attrs[attr]);
}
draw(button);
return(button);
}
var imageButtonDefaults = {
type : 'image-button'
};
function newImageButton (attrs) {
var button = document.createElement('img');
for (attr in buttonDefaults) {
button.setAttribute(attr, imageButtonDefaults[attr]);
}
for (attr in attrs) {
button.setAttribute(attr, attrs[attr]);
}
draw(button);
return(button);
}
function newSymbolButton (attrs) {
if (wedgeDisplayMode === 'canvas') {
return newButton(attrs);
} else if (wedgeDisplayMode === 'images') {
return newImageButton(attrs);
}
}
Controller.newSymbolButton = newSymbolButton;
function Task(target,attr,limit,finish,speed) {
this.target = target;
this.attr = attr;
this.stepIncr = speed == 'f' ? 4
: speed == 'x' ? 4
: speed == 's' ? 1
: 2
;
this.start = target.getAttr(attr);
this.limit = limit;
if (typeof finish === 'function') {
this.finish = finish;
}
}
Task.easePcts = {
0 : 0, 1 : 0, 2 : .0004,
3 : .0020, 4 : .0064, 5 : .0156,
6 : .0324, 7 : .0600, 8 : .1024,
9 : .1640, 10 : .2500, 11 : .3495,
12: .4464, 13 : .5385, 14 : .6244,
15: .7031, 16 : .7744, 17 : .8385,
18: .8964, 19 : .9495, 20 : 1.0000
};
Task.prototype = {
isActive : true,
step : 0,
go : function() {
this.step+=this.stepIncr;
if ( this.target.adjust(this.attr, this.amount(), this.limit) ) {
if (this.finish) {
this.finish(this.target);
}
this.isActive = false;
}
},
amount : function () {
if (Element.fractionalAttrs[this.attr] || this.speed == 'x') {
return (this.limit - this.start) / (20/this.stepIncr);
} else {
var e = Task.easePcts[this.step];
var target = this.start + mRound(e *(this.limit - this.start));
var d = target - this.target.getAttr(this.attr);
return d ? d
: this.start > this.limit ? -1
: 1
;
}
},
stop : function() {
this.isActive = false;
},
};
function Control(control, gadget, action) {
this.action = action || control.getAttribute('action');
this.element = control;
this.gadget = gadget;
control.setAttribute("onclick", 'Controller.click(this)');
if (! control.id) {
control.id = "_ctl_" + (++Control.idSequence);
}
Controller.controls[control.id] = this;
}
Control.idSequence = 0;
Control.prototype = {
enabled : true,
disable : function() {
if (!this.enabled || !this.element) {
return;
}
this.element.fadeTo(.30);
this.element.onClick = null;
this.enabled = false;
},
click : function() {
if (this.enabled) {
this.gadget.doAction(this.action, this);
}
},
enable: function() {
if (this.enabled || !this.element) {
return
}
this.element.fadeTo(1);
this.element.onClick = this.action;
this.enabled = true;
},
updatePosition : function() {
}
};
function List(list) {
this.element = list;
for (var i in List.elementAttributes) {
var e = List.elementAttributes[i];
if (this.element.hasAttribute(e)) {
this[e] = this.element.getAttribute(e) - 0;
}
}
this.url = this.element.getAttribute("url");
if (this.element.hasAttribute("controls")) {
var controls = $(this.element.getAttribute("controls"));
if (controls) {
var controlDivs = controls.getElementsByTagName('div');
for (var i =0; i < controlDivs.length; i++) {
for (var a in List.controlActions) {
var action = List.controlActions[a];
if (controlDivs[i].getAttribute("action") == action) {
this.controls[action] = new Control(controlDivs[i], this);
}
}
}
}
}
if (this.element.getAttribute("display")) {
this.display = $(this.element.getAttribute("display"));
}
Controller.gadgets[this.element.id] = this;
if (this.last == 0) {
var aList = this;
setTimeout(function(){aList.doAction('showMore');},1);
}
}
List.elementAttributes = ['first', 'getSize', 'last', 'limit' ];
List.controlActions = ['showMore', 'showNext', 'showPrevious'];
List.prototype = {
controls : {},
first : 1,
getSize : 5,
last : 5,
limit : 50,
doAction : function(action,control) {
switch(action) {
case 'showMore' :
ajax(this);
this.last += this.getSize;
break;
case 'showPrevious' :
this.removeRows(this.getSize);
this.last = (this.first - this.getSize - 1);
ajax(this);
this.first -= this.getSize;
this.last += this.getSize;
break;
case 'showNext' :
ajax(this);
this.removeRows(this.getSize);
this.first += this.getSize;
this.last += this.getSize;
break;
}
},
uri : function() {
var count = Math.min(this.getSize, this.limit - this.last );
var pos = Math.max(this.last + 1, 1);
$sep = this.url.indexOf('?') >= 0 ? "&" : "?";
return this.url + $sep + 'pos=' + pos + '&count=' + count;
},
addWaiter : function() {
var waiter = document.createElement('li');
waiter.addClass('waiting');
this.element.appendChild(waiter);
var prev = waiter.previousTag();
if (prev) {
waiter.addClass(prev.getAttribute('class'));
}
return waiter;
},
updateDisplay : function(text) {
if (this.display) {
this.display.innerHTML = text;
}
},
removeRows : function(rows) {
rows = Math.min(rows, (this.last - this.first) + 1);
var items = this.element.getElementsByTagName('li');
for (var i = 1; i <= rows; i++) {
Controller.freeNode(items[0]);
this.element.removeChild(items[0]);
}
},
enableControl : function(control) {
if (this.controls[control]) {
this.controls[control].enable();
}
},
disableControl : function(control) {
if (this.controls[control]) {
this.controls[control].disable();
}
},
updatePosition : function() {
if (this.last > this.limit) {
this.last = this.limit;
}
if (this.first <= 1) {
this.disableControl('showPrevious');
}
if (this.first > 1) {
this.enableControl('showPrevious');
}
if (this.last >= this.limit) {
this.disableControl('showNext');
this.disableControl('showMore');
}
if (this.last < this.limit) {
this.enableControl('showNext');
this.enableControl('showMore');
}
this.updateDisplay( this.first === this.last ?
this.first :
(this.first + '-' + this.last) );
},
};
function Scroll (div) {
this.leftControl = new Control( $(div.getAttribute('leftControl')), this, 'scrollLeft' );
this.rightControl = new Control( $(div.getAttribute('rightControl')), this, 'scrollRight' );
this.scrollBy = div.getAttribute('scrollBy') - 0;
this.element = div;
this.updateControls();
Controller.gadgets[this.element.id] = this;
}
Scroll.prototype = {
doAction : function(action) {
switch (action) {
case 'scrollLeft' :
this.scroll(-1);
break;
case 'scrollRight' :
this.scroll(1);
break;
}
},
updateControls : function() {
var pos = this.element.hScrolled();
if (pos == -1) {
this.leftControl.disable();
this.rightControl.enable();
} else if (pos == 1) {
this.leftControl.enable();
this.rightControl.disable();
} else {
this.leftControl.enable();
this.rightControl.enable();
}
},
scroll : function(direction) {
var hook = this;
var finish = function() {
hook.updateControls();
};
this.element.hScrollBy(this.scrollBy * direction, finish);
}
};
function Expand(item) {
this.content = $(item.getAttribute("content"));
var buttonScale = item.getAttribute("buttonScale") || 1.0;
if (item.hasAttribute("focusOnClose")) {
this.focusOnClose = item.getAttribute("focusOnClose") == "yes";
}
if (item.hasAttribute("peers")) {
this.peers = item.getAttribute("peers").split(' ');
} else {
this.aUp = newSymbolButton({symbol : 'wedge-up',
height : 17 * buttonScale,
width : 19 * buttonScale,
color : 'white'});
this.aUp.style.display = 'none';
this.aUp.addClass("indicator");
this.aDn = newSymbolButton({symbol : 'wedge-down',
height : 17 * buttonScale,
width : 19 * buttonScale,
color : 'white'});
this.aDn.addClass("indicator");
}
var toggleLink = document.createElement('a');
toggleLink.setAttribute('action','toggle');
toggleLink.id = 'toggle' + item.getAttribute("content");
if (this.aUp && this.aDn) {
toggleLink.appendChild(this.aDn);
toggleLink.appendChild(this.aUp);
}
while (item.childNodes.length > 0) {
toggleLink.appendChild(item.childNodes[0]);
}
item.appendChild(toggleLink);
this.element = item;
this.control = new Control(toggleLink,this);
if (item.hasAttribute("speed")) {
this.speed = item.getAttribute("speed");
}
Controller.gadgets[this.element.id] = this;
}
Expand.prototype = {
collapsed : true,
focusOnClose : true,
speed : 'm',
doAction : function (action) {
switch (action) {
case 'toggle' :
if (this.collapsed) {
this.open();
} else {
this.close(this.focusOnClose);
}
break;
}
},
open : function() {
this.collapsed = false;
if (this.aUp && this.aDn) {
this.aUp.style.display = this.aDn.style.display;
this.aDn.style.display = 'none';
}
if (this.content.hasAttribute('noRender')) {
this.content.removeAttribute('noRender');
var content = this.content;
setTimeout(function(){
markUnrendered(content);
Controller.initNode(content, false);
},0);
}
this.content.expand(null, this.speed);
this.closePeers();
},
close : function(focus) {
this.collapsed = true;
if (this.aUp && this.aDn) {
this.aDn.style.display = this.aUp.style.display;
this.aUp.style.display = 'none';
}
if (focus) {
this.content.collapse(this.focuser(), this.speed);
} else {
this.content.collapse(null, this.speed);
}
},
focuser : function() {
var element = this.element;
return function() { element.scrollFocus(); };
},
closePeers : function() {
if (this.peers) {
for (var i = 0; i <= this.peers.length ; i++) {
if (Controller.gadgets[this.peers[i]]) {
Controller.gadgets[this.peers[i]].close(0);
}
}
}
}
};
function Overlay(element) {
var opener = $(element.getAttribute("openControl"));
opener.setAttribute('action', 'open');
var closer = $(element.getAttribute("closeControl"));
closer.setAttribute('action', 'close');
this.openControl = new Control(opener, this);
this.closeControl = new Control(closer, this);
this.element = element;
}
Overlay.prototype = {
open : false,
doAction : function (action) {
switch (action) {
case 'open' :
scrollTop();
this.element.slideOn();
Controller.lockScroll();
break;
case 'close' :
scrollTop();
this.element.slideOff();
Controller.unlockScroll();
break;
}
},
};
function LinkingElement(element) {
this.url = element.getAttribute('url');
this.control = new Control(element,this,'go');
}
LinkingElement.prototype = {
doAction : function() {
window.location = this.url;
}
};
Element.prototype.adjust = function(attr, amount, limit) {
var current = Number(this.getAttr(attr));
var set = current + amount;
var done;
if (amount < 0) {
done = (set <= limit);
} else {
done = (set >= limit);
}
if (done) {
set = limit;
}
this.setAttr(attr, set);
return done;
};
Element.prototype.getAttr = function(attr) {
return Element.pxAttrs[attr] ? this[Element.pxAttrs[attr]]
: (attr in this) ? this[attr]
: this.style[attr]
;
};
Element.prototype.setAttr = function(attr, value) {
if (Element.pxAttrs[attr] && typeof value === 'number' ) {
value = value + 'px';
}
if (attr in this) {
this[attr] = value;
} else {
this.style[attr] = value;
}
};
Element.prototype.collapse = function(finish, speed) {
this.setAttr('height', 0);
if (typeof finish === 'function') {
finish(this);
}
};
Element.prototype.expandTo = function(targetHeight, finish, speed) {
this.setAttr('height', targetHeight);
if (typeof finish === 'function') {
finish(this);
}
};
Element.prototype.expand = function(finish, speed) {
this.expandTo(this.scrollHeight, finish, speed);
};
Element.prototype.slideOn = function(finish) {
this.style.display = 'block';
animator.addTask(new Task(this, 'top', 0, finish));
};
Element.prototype.slideOff = function(finish) {
animator.addTask(new Task(this,'top',-480,function(e){ e.style.display = 'none'; }));
};
Element.prototype.fadeTo = function( opacity, finish) {
animator.addTask(new Task(this,'opacity', opacity, finish));
};
Element.prototype.hScrollBy = function(scroll, finish) {
var scrollMax = this.scrollWidth - this.clientWidth;
var scrollTarget = this.scrollLeft + scroll;
scrollTarget = scrollTarget < 0 ? 0
: scrollTarget > scrollMax ? scrollMax
: scrollTarget
;
animator.addTask(new Task(this, 'scrollLeft', scrollTarget, finish));
};
Element.prototype.hScrolled = function() {
return this.scrollLeft <= 0 ? -1
: this.scrollLeft >= this.scrollWidth - this.clientWidth ? 1
: 0
;
};
Element.prototype.scrollFocus = function () {
if (pageYOffset > this.offsetTop) {
scrollTo(0, Math.max(1, this.offsetTop-50));
}
};
Element.prototype.addClass = function(c) {
var currentClass = this.getAttribute("class") || '';
for (var i = 0; i <= arguments.length ; i++) {
if (arguments[i]) {
currentClass += (currentClass ? " " : '') + arguments[i];
}
}
this.setAttribute("class", currentClass);
};
Element.prototype.hasClass = function(c) {
var re = new RegExp("(^|\\s)"+c+"($|\\s)");
return re.exec(this.getAttribute("class")) != null;
};
Element.prototype.removeClass = function(c) {
var currentClass = this.getAttribute("class") || '';
var re = new RegExp("/(^|\\s)"+c+"($|\\s)/g");
currentClass.replace(re,'');
this.setAttribute("class", currentClass);
};
Element.pxAttrs = {
height : 'clientHeight',
width : 'clientWidth',
top : 'offsetTop'
};
Element.fractionalAttrs = {
opacity : 1
};
Element.prototype.setStyle = function(s) {
for (styleName in s) {
this.style[styleName] = s[styleName];
}
};
Element.prototype.ascendDOMTree = function(test) {
if (!(typeof test === 'function')) {
return null;
}
var node = this;
while(node && (!node.isElement() || !test(node))) {
node = node.parentNode;
}
return node;
};
Element.prototype.reparent = function(newParent) {
this.parentNode.replaceChild(newParent, this);
newParent.appendChild(this);
};
Element.prototype.replaceWithSource = function(source) {
var par = this.parentNode;
par.insertBefore(source.toFragment(), this);
par.removeChild(this);
return par;
};
Node.prototype.isElement = function() {
return this.nodeType == Node.ELEMENT_NODE;
};
Node.prototype.processTags = function(spec,func,skip) {
var tagNames = (typeof spec.tagName === 'object') ? spec.tagName
: [spec.tagName]
;
for (var i = 0; i < tagNames.length; i++) {
var tags = this.getElementsByTagName(tagNames[i]);
for (var j = 0; j < tags.length; j++) {
if (tags[j].hasAttribute(spec.hasAttribute) || !spec.hasAttribute) {
func(tags[j]);
}
}
}
};
Node.prototype.previousTag = function(name) {
if (!name) {
name = this.nodeName;
}
var prev = this.previousSibling;
while (prev && (prev.nodeName != name)) {
prev = prev.previousSibling;
}
return prev;
};
String.prototype.toFragment = function() {
var holder = document.createElement('div');
holder.innerHTML = this;
return $$(holder);
};
String.prototype.parseJSON = function (filter) {
var j;
function walk(k, v) {
var i;
if (v && typeof v === 'object') {
for (i in v) {
if (Object.prototype.hasOwnProperty.apply(v, [i])) {
v[i] = walk(i, v[i]);
}
}
}
return filter(k, v);
}
var ts = this.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"/g, '');
if (/^[ ,:{}\[\]0-9.\-+Eaeflnr-u\n\r\t]*$/.test(ts)) {
j = eval('(' + this + ')');
return typeof filter === 'function' ? walk('', j) : j;
}
throw new SyntaxError('parseJSON');
};
function rgba(a) {
return 'rgba(' + a.join(',') + ')';
}
function ajax(list) {
list.disableControl('showNext');
list.disableControl('showPrevious');
var url = list.uri();
var target = list.addWaiter();
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
var parent = target.replaceWithSource(req.responseText);
Controller.initNode(parent, true);
list.updatePosition();
}
};
req.open("GET", url, true);
req.send(null);
}
function $$(e) {
var r = document.createRange();
r.selectNodeContents(typeof e === 'object' ? e : $(e));
var f = r.extractContents();
r.detach();
return f;
}
function mRound(i) {
return i < 0 ? Math.floor(i) : Math.ceil(i);
}
})();
function $(element) {
return document.getElementById(element);
}
'use strict';(function(){var l,C,v,n;function B(a,b,c){if(c=a[b])if(c=document.getElementById(c))return a[b]=c;delete a[b]}function L(a,b){for(var c in b)!a.hasOwnProperty(c)&&b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function G(a,b,c){if(!a)return-1;for(var d=0,e=a.length;d<e;d++)if(a[d][b]==c)return d;return-1}function H(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function u(a,b,c){var d="on"+b;if(a.addEventListener)a.addEventListener(b,c,!1);else if(a.attachEvent)a.attachEvent(d,
c);else{var e=a[d];a[d]=function(){var a=e.apply(this,arguments),b=c.apply(this,arguments);return a===void 0?b:b===void 0?a:b&&a}}}function r(a,b,c){if(c)a.setAttribute(b,c);else return a.getAttribute(b)}function z(a){var b=0,c=0;if(a.offsetParent){do b+=a.offsetLeft,c+=a.offsetTop;while(a=a.offsetParent)}return{left:b,top:c}}function D(a){return"<b>"+a+"</b>"}function M(){var a=function(){var a=void 0;window.XMLHttpRequest?a=new XMLHttpRequest:window.ActiveXObject&&(a=new ActiveXObject("Microsoft.XMLHTTP"));
return a}();return{call:function(b,c){if(a&&b)try{a.open("GET",b,!0),a.send(null)}catch(d){window.ueLogError&&window.ueLogError(d,{logLevel:"ERROR",attribution:"ISS Recent Searches : "+c+" Feature",message:c+" Operation Failed when calling "+b})}}}}function N(a){var b,c,d,e,f=a||0;return{callSuggestionsService:function(a){b=a;c=document.getElementsByTagName("head").item(0);d="JscriptId"+f;e=document.createElement("script");r(e,"type","text/javascript");r(e,"charset","utf-8");r(e,"src",b);r(e,"id",
d);c.appendChild(e)},cleanup:function(){try{c.removeChild(e)}catch(a){}},counter:f}}function E(a){var b=document.getElementsByTagName("*"),a=RegExp("(^|\\s)"+a+"(\\s|$)"),c=[],d;for(d=0;d<b.length;d++)a.test(b[d].className)&&c.push(b[d]);return c}function x(){var a=document.getElementsByClassName("psearch");if(!(a.length<=0)){var b=document.getElementById("search-ac-init-data");if(b){for(var c=b.getAttribute("data-aliases").split(","),d=b.getAttribute("data-ime"),e=b.getAttribute("data-mkt"),b=b.getAttribute("data-src"),
f=0;f<a.length;f++){var g=a[f];if(g){var j=g.tagName.toLowerCase()==="input"?g:g.getElementsByTagName("input")[0];if(j&&j.id){var i=document.getElementById(j.id+"-data");if(i){var k=i.getAttribute("data-form"),g=j.id.replace(/-/g,"___"),F=i.getAttribute("data-dropdown"),q=i.getAttribute("data-popup"),i=i.getAttribute("data-implicit-alias");if(k!==void 0&&(!ACs[g]||q))j=new AutoComplete({src:b,mkt:e,ime:d,aliases:i?[i]:c,sb:j.id,form:k,dd:F,popupBox:q,callback:"ACs."+g+".updateAutoCompletion"}),ACs[g]=
j}}}}typeof uet=="function"&&(uet("be",n,{wb:1}),uex("ld",n,{wb:1}))}}}typeof uet=="function"&&uet("bb","iss-init-aw",{wb:1});l=window.ue&&typeof ue.tag=="function"&&typeof uet=="function"&&typeof uex=="function";n="iss-init-aw";C={disabled0:"iss-c0-aw",disabled2:"iss-cs-aw"};v=!1;var O=function(a,b){function c(b){if(b!==void 0)f=g=b,a.value=b;return a.value}function d(a){a!==void 0&&(i=a);return i}function e(a){var i=c();if(i!=f&&(a||i!=g))d(f=i),b.change(i)}var f,g,j,i,k,F=this;l&&!v&&(ue.tag(a===
document.activeElement?"iss-late-aw":"iss-on-time-aw"),v=!0);u(a,"keyup",function(a){switch(a.keyCode){case 13:b.hide();break;case 27:return b.dismiss();default:e(!0)}});u(document.body,"click",function(c){var h;h=(c=c.target||c.srcElement)&&c.id&&c.id.indexOf("iss_sh_delete")!==-1,c=h;document.activeElement!=a&&!c&&(b.dismiss(),j=!1)});u(a,"focus",function(){j=!0;var a=F.pos(),d=c();window.sx&&window.sx.searchsuggest&&(b.change(d),k||(b.record("27941"),k=!0));window.scrollTo(0,a.top)});r(a,"autocomplete",
"off");i=f=c();this.keyword=function(a){return c(a)};this.userInput=function(a){return d(a)};this.size=function(){return{width:a.offsetWidth,height:a.offsetHeight}};this.pos=function(){return z(a)};this.parent=function(){for(var b=a.parentNode;b&&b.className;){if(/\b(?:a-global-nav-search|suggest_parent)\b/.test(b.className))return b;b=b.parentNode}return a.parentNode};this.update=e;this.hasFocus=function(){return j};this.focus=function(){a.focus()};this.blur=function(){a.blur()}},P=function(a,b,
c,d){function e(){a.pos();a.size();c&&z(c);g.style.width=b.offsetWidth+"px"}function f(){a.pos();a.size();g=document.createElement("div");g.id="srch_sggst";g.style.display="none";u(g,"click",function(a){for(var a=a?a:event,b=a=a.srcElement?a.srcElement:a.target,c=-1,e=!1,c=4;b!==g&&b.className!=="suggest_row"&&c>=0;)b=b.parentNode,c-=1;b.className==="suggest_row"&&(c=b.id?parseInt(b.id.substr(6)):-1,e=a&&a.id&&a.id.indexOf("iss_sh_delete")!==-1,d(b,c,e))});e();a.parent().appendChild(g);u(window,"resize",
e);return g}var g;this.visible=function(){return(g||f()).style.display!="none"};this.hide=function(){(g||f()).style.display="none";this.html("")};this.show=function(){g||f();e();(g||f()).style.display=""};this.html=function(a){(g||f()).innerHTML=a};this.destroy=function(){g&&(a.parent().removeChild(g),g=void 0)}};window.AutoComplete=function(a){function b(a){h=L(a,Q);B(h,"sb");B(h,"form");if(h.sb&&h.form)B(h,"dd"),B(h,"popupBox"),s=new O(h.sb,{hide:e,dismiss:f,change:g,record:d}),w=new P(s,h.form,
h.popupBox,i),h.protocol=h.protocol||window.parent.document.location.protocol,c(),h.ime&&window.setInterval(function(){s.update()},20),h.aliases&&h.aliases.length==1&&(x=h.aliases[0])}function c(){y=[];if(window.sx&&window.sx.searchsuggest&&window.sx.searchsuggest.searchedText)for(var a=window.sx.searchsuggest.searchedText,b={},c=0;c<a.length;c++)if(!b[a[c].keywords]){var d=a[c];d.sh="1";var h=d,g=a[c].keywords,p=document.createElement("div");p.innerHTML=g;h.keyword=p.childNodes.length===0?"":p.childNodes[0].nodeValue;
y.push(d);b[a[c].keywords]=1}}function d(a){ue&&ue.id&&(a=[h.protocol+"//",location.host,"/mn/search/csl?","rrid="+ue.id,"&cpt=SearchAW","&ctw="+a].join(""),J.call(a,"WeblabTrigger"))}function e(){!h.ime&&q()}function f(){return w.visible()?(setTimeout(function(){return function(){q()}}(),300),m=-1,k(),!1):!0}function g(){v&&(clearTimeout(v),v=null);v=setTimeout(function(){return function(){t&&t.cleanup();if(s.hasFocus()){var a;if(!(a=x))a=h.dd?(a=h.dd.value&&h.dd.value.match(E))?a[1]:null:null;var b=
s.keyword(void 0),c;if(c=h.dd)if(!(c=!a)){c=h.aliases;var d;if(d=c){a:{d=0;for(var g=c.length;d<g;d++)if(c[d]==a){c=d;break a}c=-1}d=c>=0}c=!d}c||(!h.dd&&!a&&(a="aps"),!b||!b.length?(o=I([],[],y),o.length>0?j(""):q()):(c=!l?null:C[K],b=encodeURIComponent(b),a=h.protocol+"//"+h.src+"?method=completion&q="+b+"&search-alias="+a+"&client="+h.cid+"&mkt="+h.mkt+"&x="+h.callback,t=new N(K++),c&&uet("bb",c,{wb:1}),t.callSuggestionsService(a)))}v=null;m=-1}}(),100)}function j(a){var b=h.sugPrefix;if(A<=0)w.hide();
else{w.show();for(var c=document.getElementById("srch_sggst"),d="",g=0;g<A;g++){d+='<div id="'+(b+g)+'" class="suggest_row">';var e;e=o[g];var p=a,i=g,f=e.keyword,j=e.sh?n(f,p):f.toLowerCase().indexOf(p.toLowerCase()),k=void 0,k=j==-1,m=i+1==A?"suggest_link suggest_link_bottom":"suggest_link";if(e.sh)f=p,p=document.createElement("div"),p["textContent"in p?"textContent":"innerText"]=f,p=p.innerHTML,k=p.length,f=e.keywords,j=n(f,p),j>=0&&(f=f.substr(0,j)+D(f.substr(j,k))+f.substr(j+k)),e=" <div class='"+
m+"'><span style='color:#800080;'>"+f+"</span></div> <div class='suggest_delete'> <i id='iss_sh_delete"+i+"' class='a-icon a-icon-clearsearch'></i></div> ";else{if(!k)e.sc?f=D(f):(k=p.length,f=f.substr(0,j)+D(f.substr(j,k))+f.substr(j+k));e=f="<div class='"+m+"'>"+f+"</div>"}d+=e;d+="</div>"}c.innerHTML=d}}function i(a,b,c){m=b;m<0||(c?(b=o[m],a=h.protocol+"//"+location.host+b.deleteUrl,b=G(y,"keyword",b.keyword),b!=-1&&y.splice(b,1),window.setTimeout(function(){s.focus()},0),J.call(a,"DeleteKeyword")):
(window.setTimeout(function(){s.blur()},0),k(),w.hide(),h.form.submit()))}function k(){var a=s.keyword(void 0);if(m>=0)a=o[m],a=a.keyword;s.keyword(a);var b=m,c=document.getElementById("issprefix");if(b>=0){var a=s.userInput(),d=h.form,f=o&&o[b]&&o[b].sc=="1"?"ss_sc":o&&o[b]&&o[b].sh=="1"?"ss_sh":"ss_i",g=a.length,e=r(d,"action"),b=f+"_"+b+"_"+g;z.test(e)?e=e.replace(z,"ref=is_s_"+b):(e.charAt(e.length-1)!="/"&&(e+="/"),e+=b);r(d,"action",e);c?r(c,"value",a):(c=h.form,d=document.createElement("input"),
r(d,"name","sprefix"),r(d,"value",a),r(d,"type","hidden"),d.id="issprefix",c.appendChild(d))}else c&&h.form.removeChild(c)}function n(a,b){var c=a.toLowerCase().search(RegExp("(^|(?:\\s))"+H(b.toLowerCase()),"i"));return c<=0?c:c+1}function q(){t&&(t.cleanup(),t=null);A=0;w.hide();m=-1}function I(a,b,c){for(var d=c?c.slice(0,u):[],e=0,f=Math.min(u,a.length),g,e=0;e<f;e++)G(c,"keyword",a[e])==-1&&(g={keyword:a[e],sc:b&&b[e]&&b[e].sc=="1"},d.push(g));d=d.slice(0,u);A=d.length;return d}var h={},m=-1,
o=[],A=0,v=null,u=6,t=null,s,w,x,z=/(ref=[\w-]+)/,E=/search-alias\s*=\s*([\w-]+)/,y=[],J=new M,Q={dd:"searchDropdownBox",cid:"amazon-search-ui-mobile",action:"",sugPrefix:"issDiv"},K=0;a&&b(a);return{updateAutoCompletion:function(){if(t){var a=!l?null:C[t.counter];t.cleanup();t=null;if(s.hasFocus()){a&&(uet("be",a,{wb:1}),uex("ld",a,{wb:1}));var a=y,b=completion[1].length>0?2:u;if(a&&a.length!=0){for(var c=RegExp("(^|(?:\\s))"+H(completion[0].toLowerCase()),"i"),d=0,e=a.length,f=[],g;d<e&&f.length<
b;d++)g=a[d],g.keyword.toLowerCase().match(c)&&f.push(g);a=f}o=I(completion[1],completion.length>2?completion[2]:[],a);j(completion[0])}}},buildAuxSuggestions:c,hide:q,cleanUp:function(){w.destroy()}}};l&&uet("cf",n,{wb:1});window.ACs={};if(!document.getElementsByClassName)document.getElementsByClassName=E;document.readyState==="complete"?x():window.addEventListener?window.addEventListener("load",x):window.attachEvent&&window.attachEvent("load",x);(function(){function a(a){return!a?void 0:!/\ba-hidden\b/.test(a.className)}
function b(b,c){if(b){var f=a(b);c&&!f?b.className=b.className.replace(/\s?\ba-hidden\b/,""):!c&&f&&(b.className+=" a-hidden")}}function c(){function c(){var a=i.value!=="";l&&b(k,a&&(!h||m));h&&(b(q,m),b(n,!m))}function e(){o=null}function f(){o||(o=setTimeout(e,10))}function g(){o||(m=!1,c())}function j(){m=!0;c()}var i=document.getElementById("nav-search-keywords");if(i){var k=document.getElementById("nav-clear-search"),n=document.getElementById("nav-search-placeholder-icon"),q=document.getElementById("nav-searchbar-button"),
l=k&&!a(k),h=q&&!a(q),m=document.activeElement===i,o=null;l&&(i.addEventListener("change",c),i.addEventListener("keyup",c));h&&(i.addEventListener("focus",j),i.addEventListener("blur",g),q.addEventListener("mousedown",f),k&&k.addEventListener("mousedown",f));(l||h)&&c();if(k)k.onclick=function(a){a.preventDefault();i.value="";m=document.activeElement===i;c()};if(n)n.onclick=function(a){a.preventDefault();i.focus()}}}document.readyState==="complete"?c():window.addEventListener?window.addEventListener("load",
c):window.attachEvent&&window.attachEvent("load",c)})()})();(function(){(function(){function l(){var l=document.getElementById("search-icon-link");if(l)l.onclick=function(l){var n=this.href.lastIndexOf("#");if(n>0&&n<this.href.length-1&&(n=document.getElementById(this.href.substring(n+1))))n.focus(),l.preventDefault()}}document.readyState==="complete"?l():window.addEventListener("load",l)})()})();
(function(){(function(){function l(){var l=document.getElementsByClassName("a-subheader");l.length>0&&!window.pageYOffset&&l[0].scrollIntoView(!0)}document.readyState==="complete"?l():window.addEventListener("load",l)})()})();