/**
 * @author Adam McIntyre Builds the Media Bar / Carousel / Lightbox combo on the
 *         article detail page. Also contains the "client" awesomebox uses to
 *         process images.
 */
/*
 * The following information must not be removed: Awesome Box v2 Written by:
 * Paul Armstrong, Paul Armstrong Designs Site: http://paularmstrongdesigns.com
 * Idea and some functions from "LightBox" http://www.huddletogether.com Example &
 * Documentation: http://paularmstrongdesigns.com/awesome/box/ Last Updated:
 * Friday, February 2, 2007 at 12:31:10 This work is licensed under a Creative
 * Commons Attribution-ShareAlike 2.5 License
 * http://creativecommons.org/licenses/by-sa/2.5/ Required Yahoo! UI Files:
 * yahoo.js dom.js event.js [ or: yahoo-dom-event.js ] animation.js [ or:
 * animation-min.js ] Modified for NikonUSA.com by Adam McIntyre --
 * adam.mcintyre@molecular.com
 */

aLoadImgSrc = "/static/js/awesome-box-v2/images/aBox-loading.gif";
var aClient = {};
aClient.photos = [];
aClient.allAssets = {};
aClient.groups = {};
aClient.aTypes = {
    'jpg': true,
    'gif': true,
    'png': true,
    'bmp': true,
    'flv': true,
    'swf': true,
    'mp3': true,
    'wav': true
};
aClient.imgTypes = {
    'jpg': true,
    'gif': true,
    'bmp': true
};
aClient.mediaTypes = {
    'flv': true,
    'swf': true,
    'mp3': true,
    'wav': true
};
aClient.addItem = function (lbItem) {
    var fileType = lbItem.href.substr(lbItem.href.lastIndexOf('.') + 1).toLowerCase();
    if (fileType in aClient.aTypes) {
        var mixed = fileType in aClient.mediaTypes;
        this.photos.push(lbItem);
        this.addToGroup(lbItem, mixed);
        YAHOO.awesomebox.setClickAction(lbItem, YAHOO.awesomebox);
    }
};
aClient.addMCItem = function (lbItem) {
    var fileType = lbItem.href.substr(lbItem.href.lastIndexOf('.') + 1).toLowerCase();
    if (fileType in aClient.aTypes) {
        var mixed = fileType in aClient.mediaTypes;
        this.photos.push(lbItem);
        this.addToGroup(lbItem, mixed);
    }
};
aClient.noDownloadLink = {
    'jpg': true,
    'gif': true,
    'png': true,
    'bmp': true,
    'flv': true,
    'swf': true
};
aClient.addToGroup = function (lbItem, mixed) {
    if (! (lbItem.rel in this.groups)) {
        this.groups[lbItem.rel] = [];
        this.groups[lbItem.rel].items = [];
    }
    var grp = this.groups[lbItem.rel];
    grp.items.push(lbItem);
    if (mixed) {
        grp.mediaType = "mixed";
    }
    grp[lbItem.href] = grp.items.length - 1;
}
aClient.getGroup = function (groupName) {
    if (this.groups[groupName]) {
        return this.groups[groupName];
    }
    return [];
}
aClient.isInGroup = function (groupName, value) {
    if (value in this.getGroup(groupName)) {
        return this.groups[groupName][value];
    }
    return null;
}
aClient.pageWidth = function () {
    var xScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
    } else {
        xScroll = document.body.offsetWidth;
    }
    if (xScroll < $D.getViewportWidth()) {
        pageWidth = $D.getViewportWidth();
    } else {
        pageWidth = xScroll;
    }
    return pageWidth;
};
aClient.pageHeight = function () {
    var yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        yScroll = document.body.scrollHeight;
    } else {
        yScroll = document.body.offsetHeight;
    }
    if (yScroll <= $D.getViewportHeight()) {
        pageHeight = $D.getViewportHeight();
    } else {
        pageHeight = yScroll;
    }
    return pageHeight;
};
aClient.xScroll = function () {
    var xScroll = window.scrollX || document.documentElement.scrollLeft;
    return xScroll;
};
aClient.yScroll = function () {
    var yScroll = window.scrollY || document.documentElement.scrollTop;
    return yScroll;
};
MediaCenterUtils = function () {
    var intvl;
    return {
        _setupTreatment: function (imgEl) {
            YAHOO.util.Dom.removeClass(imgEl, 'auto_centered');
            YAHOO.util.Dom.removeClass(imgEl, 'auto_sized');
            YAHOO.util.Dom.setStyle(imgEl, 'width', '');
            YAHOO.util.Dom.setStyle(imgEl, 'height', '');
            YAHOO.util.Dom.setStyle(imgEl, 'top', '');
            YAHOO.util.Dom.setStyle(imgEl, 'left', '');
        },
        handleImageTreatment: function (img) {
            this.centerImage(img);
            this.positionEnlargeImage(img);
        },
        centerImage: function (img) {
            var imgEl = YAHOO.util.Dom.get(img);
            var imgP = imgEl.parentNode;
            if (!YAHOO.util.Dom.hasClass(imgEl, 'auto_centered') && imgEl.offsetWidth > 0 && imgEl.offsetHeight > 0) {
                imgEl.style.position = 'absolute';
                var lOffset = (imgEl.offsetWidth - imgP.offsetWidth) / 2;
                if (lOffset < 0) {
                    imgEl.style.left = (-1 * lOffset) + 'px';
                } else {
                    imgEl.style.left = '-' + lOffset + 'px';
                }
                var tOffset = (imgEl.offsetHeight - imgP.offsetHeight) / 2;
                if (tOffset < 0) {
                    imgEl.style.top = (-1 * tOffset) + 'px';
                } else {
                    imgEl.style.top = '-' + tOffset + 'px';
                }
                YAHOO.util.Dom.addClass(imgEl, 'auto_centered');
            }
            if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7 && (imgEl.offsetWidth == 0 || imgEl.offsetHeight == 0)) {
                setTimeout(function () {
                    MediaCenterUtils.handleImageTreatment(img);
                },
                250);
            }
        },
        resizeImage: function (img) {
            var imgEl = YAHOO.util.Dom.get(img);
            var imgP = imgEl.parentNode;
            var pWidth = imgP.offsetWidth;
            var pHeight = imgP.offsetHeight;
            var iWidth = imgEl.offsetWidth;
            var iHeight = imgEl.offsetHeight;
            if (iWidth > pWidth && iHeight > pHeight && !YAHOO.util.Dom.hasClass(imgEl, 'auto_sized')) {
                var newAspectRatio = Math.floor(Math.min(iWidth / pWidth, iHeight / pHeight));
                if (newAspectRatio > 1) {
                    imgEl.style.width = parseFloat(iWidth / newAspectRatio) + 'px'
                    imgEl.style.height = parseFloat(iHeight / newAspectRatio) + 'px';
                    YAHOO.util.Dom.addClass(imgEl, 'auto_sized');
                }
            }
        },
        positionEnlargeImage: function (img) {
            img = YAHOO.util.Dom.get(img);
            var parentWidth = img.offsetWidth;
            var enlargeBtn = document.getElementById('enlarge_' + img.id);
            var newRight = img.parentNode.offsetWidth - parentWidth;
            if ((newRight - 10) < 0) {
                YAHOO.util.Dom.setStyle(enlargeBtn, 'right', '10px');
            } else {
                var leftOffset = parseInt(YAHOO.util.Dom.getStyle(img, 'left'), 10);
                if (leftOffset > 0) {
                    newRight -= leftOffset;
                }
                YAHOO.util.Dom.setStyle(enlargeBtn, 'right', newRight + 'px');
            }
        },
        setSingleItemActions: function (el) {
            var el = YAHOO.util.Dom.get(el);
            var baseId = el.id.substr('link_'.length);
            var iSrc = '';
            if (document.getElementById(baseId + '_intermediateImage')) {
                iSrc = document.getElementById(baseId + '_intermediateImage').getAttribute('data-intimage');
            } else {
                iSrc = document.getElementById(baseId).src;
            }
            YAHOO.awesomebox.setClickAction(el, YAHOO.awesomebox);
            YAHOO.util.Event.addListener(el, 'click', function () {
                OmnitureHelper.setMCEnlargeClickEvents(this.getAttribute('data-mediatype'), this.href, this.title);
            });
            if (MCCarouselWidget.prototype.enlargeable(iSrc, el.href)) {
                var fileType = el.href.substr(el.href.lastIndexOf('.') + 1);
                if (fileType.toLowerCase() in aClient.imgTypes) {
                    var enlargeLink = document.getElementById('enlargeLink_' + baseId);
                    enlargeLink.removeAttribute('data-fulldescription');
                    enlargeLink.removeAttribute('title');
                    if (el.getAttribute('title')) {
                        enlargeLink.setAttribute('title', el.getAttribute('title'));
                    }
                    if (el.getAttribute('data-fulldescription')) {
                        enlargeLink.setAttribute('data-fulldescription', el.getAttribute('data-fulldescription'));
                    }
                    enlargeLink.setAttribute('href', el.href);
                    YAHOO.awesomebox.setClickAction(enlargeLink, YAHOO.awesomebox);
                    YAHOO.util.Dom.removeClass('enlarge_' + baseId, 'noD');
                }
                var rm = YAHOO.util.Selector.query('a.read_more', 'summary_' + baseId, true);
                if (rm) {
                    YAHOO.awesomebox.setClickAction(rm, YAHOO.awesomebox);
                }
            }
            this.maybeShowPlayButton(el, 'play_' + el.id);
        },
        maybeShowPlayButton: function (el, id) {
            var piLink = document.getElementById(id);
            if (el.href.indexOf('.flv') > -1) {
                setTimeout(function () {
                    piLink.removeAttribute('data-fulldescription');
                    piLink.removeAttribute('title');
                    piLink.removeAttribute('size');
                    if (el.getAttribute('title')) {
                        piLink.setAttribute('title', el.getAttribute('title'));
                    }
                    if (el.getAttribute('data-fulldescription')) {
                        piLink.setAttribute('data-fulldescription', el.getAttribute('data-fulldescription'));
                    }
                    if (el.getAttribute('size')) {
                        piLink.setAttribute('size', el.getAttribute('size'));
                    }
                    piLink.setAttribute('href', el.href);
                    YAHOO.awesomebox.setClickAction(piLink, YAHOO.awesomebox);
                    if (YAHOO.env.ua.ie == 0 || YAHOO.env.ua.ie > 6) {
                        YAHOO.util.Dom.setStyle(piLink, 'opacity', 0);
                        YAHOO.util.Dom.removeClass(piLink, 'noD');
                        new YAHOO.util.Anim(piLink, {
                            opacity: {
                                to: 0.99
                            }
                        },
                        0.25).animate();
                    } else {
                        YAHOO.util.Dom.removeClass(piLink, 'noD');
                    }
                },
                500);
            } else {
                YAHOO.util.Dom.addClass(piLink, 'noD');
            }
        }
    }
} ();

function MCCarouselWidget(cId, replaceImgId, size, numVisible, scrollInc) {
    this.tabId = cId;
    var curSize = size || YAHOO.util.Selector.query('ul.carousel-list li', cId).length;
    numVisible = numVisible || 6;
    scrollInc = scrollInc || numVisible;
    var configOpts = {
        "numVisible": numVisible,
        "animationSpeed": 0.35,
        "scrollInc": scrollInc,
        "navMargin": 0,
        "revealAmount": 0,
        "firstVisible": 1,
        "size": curSize,
        "prevElement": cId + "-prev",
        "nextElement": cId + "-next"
    };
    var carousel = new YAHOO.extension.Carousel(cId, configOpts);
    var navId = cId + "-navigation";
    this.replaceImgId = replaceImgId;
    this.getCarouselEl = function () {
        return carousel._carouselElemID;
    };
    this.getNav = function () {
        return document.getElementById(navId);
    };
    this.getCarousel = function () {
        return carousel;
    };
    this.scrollable = (curSize > numVisible && this.getNav()) ? true : false;
    var obj = this;
    var _wireChildActions = function () {
        var anchors = YAHOO.util.Selector.query('ul.carousel-list li a', cId);
        var linkEl = YAHOO.util.Dom.get('link_' + obj.replaceImgId);
        YAHOO.util.Dom.batch(anchors, function (o) {
            YAHOO.util.Event.addListener(o, 'click', function (e) {
                YAHOO.util.Event.preventDefault(e);
                var curEl = this;
                OmnitureHelper.setMCThumbClickEvents(mcTabs.get('activeTab').get('labelEl').innerHTML, curEl.getAttribute('data-mediatype'), curEl.href, curEl.title);
                obj.fadeSwap('preload_' + obj.replaceImgId, obj.replaceImgId);
                obj.setHighlighted(curEl);
                YAHOO.util.Dom.addClass('enlarge_' + obj.replaceImgId, 'noD');
                YAHOO.util.Dom.addClass('play_link_' + obj.replaceImgId, 'noD');
                setTimeout(function () {
                    var im = new Image();
                    var iSrc = document.getElementById(curEl.id + '_intermediateImage').getAttribute('data-intimage');
                    im.onload = function () {
                        if (obj.enlargeable(iSrc, curEl.href)) {
                            YAHOO.util.Event.removeListener(linkEl, 'click');
                            linkEl.setAttribute('href', curEl.href);
                            YAHOO.awesomebox.setClickAction(linkEl, YAHOO.awesomebox);
                        } else {
                            YAHOO.util.Event.removeListener(linkEl, 'click');
                            linkEl.setAttribute('href', 'javascript:void(0)');
                            YAHOO.util.Event.addListener(linkEl, 'click', function () {
                                return false;
                            });
                        }
                        linkEl.setAttribute('data-mediatype', curEl.getAttribute('data-mediatype'));
                        linkEl.removeAttribute('title');
                        linkEl.removeAttribute('data-fulldescription');
                        linkEl.title = curEl.getAttribute('title') ? curEl.getAttribute('title') : '&nbsp;';
                        linkEl.setAttribute('data-fulldescription', curEl.getAttribute('data-fulldescription'));
                        if (curEl.getAttribute('size')) {
                            linkEl.setAttribute('size', curEl.getAttribute('size'));
                        } else if (linkEl.getAttribute('size')) {
                            linkEl.removeAttribute('size');
                        }
                        obj.swapImages(obj, iSrc, function () {
                            MediaCenterUtils._setupTreatment(obj.replaceImgId);
                            MediaCenterUtils.handleImageTreatment(obj.replaceImgId);
                            obj.fadeSwap(obj.replaceImgId, 'preload_' + obj.replaceImgId);
                            document.getElementById('title_' + obj.replaceImgId).innerHTML = curEl.getAttribute('title') ? curEl.getAttribute('title') : '&nbsp;';
                            document.getElementById('summary_' + obj.replaceImgId).innerHTML = curEl.getAttribute('alt') ? curEl.getAttribute('alt') : '&nbsp;';
                            if (obj.enlargeable(iSrc, curEl.href) && (curEl.getAttribute('alt') && curEl.getAttribute('alt').indexOf('...') == curEl.getAttribute('alt').length - 3) && !(curEl.getAttribute('alt') == null || curEl.getAttribute('data-fulldescription') == null) && !(linkEl.alt == linkEl.getAttribute('data-fulldescription'))) {
                                var baseId = linkEl.id.substr('link_'.length);
                                var moreEl = document.getElementById('more_' + baseId);
                                var tmpLink = moreEl.cloneNode(true);
                                tmpLink.id = '';
                                if (curEl.getAttribute('size')) {
                                    tmpLink.setAttribute('size', curEl.getAttribute('size'));
                                }
                                tmpLink.setAttribute('href', curEl.href);
                                tmpLink.title = curEl.getAttribute('title') ? curEl.getAttribute('title') : '&nbsp;';
                                tmpLink.setAttribute('data-fulldescription', curEl.getAttribute('data-fulldescription'));
                                YAHOO.util.Dom.removeClass(tmpLink, 'noD');
                                document.getElementById('summary_' + obj.replaceImgId).appendChild(tmpLink);
                                var rm = YAHOO.util.Selector.query('a.read_more', 'summary_' + baseId, true);
                                rm.innerHTML = rm.innerHTML.replace(/^(\s)+(.*)(\s)+$/, '$2');
                                YAHOO.awesomebox.setClickAction(rm, YAHOO.awesomebox);
                            }
                            obj._addExtraInfo(curEl, true);
                            var fileType = curEl.href.substr(curEl.href.lastIndexOf('.') + 1);
                            var enlargeEl = document.getElementById('enlarge_' + obj.replaceImgId);
                            if (fileType.toLowerCase() in aClient.imgTypes && obj.enlargeable(iSrc, curEl.href)) {
                                var enlargeLink = YAHOO.util.Selector.query('a', enlargeEl, true);
                                enlargeLink.removeAttribute('data-fulldescription');
                                enlargeLink.removeAttribute('title');
                                if (curEl.getAttribute('title')) {
                                    enlargeLink.setAttribute('title', curEl.getAttribute('title'));
                                }
                                if (curEl.getAttribute('data-fulldescription')) {
                                    enlargeLink.setAttribute('data-fulldescription', curEl.getAttribute('data-fulldescription'));
                                }
                                enlargeLink.setAttribute('href', curEl.href);
                                YAHOO.awesomebox.setClickAction(enlargeLink, YAHOO.awesomebox);
                                setTimeout(function () {
                                    YAHOO.util.Dom.removeClass(enlargeEl, 'noD');
                                },
                                100);
                            } else {
                                YAHOO.util.Dom.addClass(enlargeEl, 'noD');
                            }
                            MediaCenterUtils.maybeShowPlayButton(curEl, 'play_link_' + obj.replaceImgId);
                        });
                    };
                    im.src = iSrc;
                },
                300);
            });
            YAHOO.util.Event.addListener(o, 'mouseover', function (e) {
                var curEl = this;
                if (document.getElementById(curEl.id + '_fileIcon')) {
                    var imgEl = YAHOO.util.Dom.getFirstChild(curEl);
                    var fileEl = document.getElementById(curEl.id + '_fileIcon');
                    var oldSrc = imgEl.src;
                    imgEl.src = fileEl.getAttribute('data-icon');
                    fileEl.setAttribute('data-icon', oldSrc);
                }
            });
            YAHOO.util.Event.addListener(o, 'mouseout', function (e) {
                var curEl = this;
                if (document.getElementById(curEl.id + '_fileIcon')) {
                    var imgEl = YAHOO.util.Dom.getFirstChild(curEl);
                    var fileEl = document.getElementById(curEl.id + '_fileIcon');
                    var oldSrc = imgEl.src;
                    imgEl.src = fileEl.getAttribute('data-icon');
                    fileEl.setAttribute('data-icon', oldSrc);
                }
            });
            aClient.addMCItem(o);
        });
        var lHref = linkEl.href;
        var baseId = linkEl.id.substr('link_'.length);
        var mcSrc = document.getElementById(baseId).src;
        if (obj.enlargeable(lHref, mcSrc)) {
            YAHOO.awesomebox.setClickAction(linkEl, YAHOO.awesomebox);
            var rm = YAHOO.util.Selector.query('a.read_more', 'summary_' + baseId, true);
            if (rm) {
                YAHOO.awesomebox.setClickAction(rm, YAHOO.awesomebox);
            }
        }
        var fileType = anchors[0].href.substr(anchors[0].href.lastIndexOf('.') + 1);
        var enlargeEl = document.getElementById('enlarge_' + obj.replaceImgId);
        if (fileType.toLowerCase() in aClient.imgTypes && obj.enlargeable(mcSrc, anchors[0].href)) {
            var enlargeLink = YAHOO.util.Selector.query('a', enlargeEl, true);
            enlargeLink.removeAttribute('data-fulldescription');
            enlargeLink.removeAttribute('title');
            if (anchors[0].getAttribute('title')) {
                enlargeLink.setAttribute('title', anchors[0].getAttribute('title'));
            }
            if (anchors[0].getAttribute('data-fulldescription')) {
                enlargeLink.setAttribute('data-fulldescription', anchors[0].getAttribute('data-fulldescription'));
            }
            enlargeLink.setAttribute('href', anchors[0].href);
            YAHOO.awesomebox.setClickAction(enlargeLink, YAHOO.awesomebox);
            YAHOO.util.Dom.removeClass(enlargeEl, 'noD');
        } else {
            YAHOO.util.Dom.addClass(enlargeEl, 'noD');
        }
        MediaCenterUtils.maybeShowPlayButton(anchors[0], "play_link_" + obj.replaceImgId);
        YAHOO.util.Event.addListener(obj.replaceImgId, 'load', function () {
            MediaCenterUtils._setupTreatment(obj.replaceImgId);
            MediaCenterUtils.handleImageTreatment(obj.replaceImgId);
        });
        YAHOO.util.Event.addListener('link_' + obj.replaceImgId, 'click', function () {
            OmnitureHelper.setMCEnlargeClickEvents(this.getAttribute('data-mediatype'), this.href, this.title);
        });
        obj._addExtraInfo(anchors[0], true);
    };
    var init = function () {
        _wireChildActions();
        if (obj.getNav()) {
            obj._configureNav();
        }
    };
    init();
}
MCCarouselWidget.prototype.enlargeable = function (smSrc, bigSrc) {
    return ! (smSrc == bigSrc || bigSrc.indexOf(smSrc) > -1 || smSrc.indexOf(bigSrc) > -1)
}
MCCarouselWidget.prototype.fadeSwap = function (inId, outId) {
    if (YAHOO.util.Dom.hasClass(inId, 'preload')) {
        YAHOO.util.Dom.addClass(inId, 'preload_on');
    }
    var anim = new YAHOO.util.Anim(outId, {
        opacity: {
            to: 0
        }
    },
    0.25, YAHOO.util.Easing.easeIn);
    anim.onStart.subscribe(function () {
        new YAHOO.util.Anim(inId, {
            opacity: {
                to: .99
            }
        },
        0.10, YAHOO.util.Easing.easeIn).animate();
    });
    anim.onComplete.subscribe(function () {
        YAHOO.util.Dom.removeClass(outId, 'preload_on');
    });
    anim.animate();
}
MCCarouselWidget.prototype._addExtraInfo = function (link, showLink) {
    var fileType = link.getAttribute('data-filetype');
    if (fileType && !(fileType.toLowerCase() in aClient.noDownloadLink)) {
        if (showLink) {
            this._displayDownloadLink(fileType, link.href);
        }
        this._displayFileInformation(fileType, link.getAttribute('data-filesize'));
    } else {
        YAHOO.util.Dom.addClass('download_' + this.replaceImgId, 'noD');
    }
}
MCCarouselWidget.prototype._mouseOverExtraInfo = function (link) {
    var fileType = link.getAttribute('data-filetype');
    if (fileType && !(fileType.toLowerCase() in aClient.noDownloadLink)) {
        this._displayFileInformation(fileType, link.getAttribute('data-filesize'));
    }
}
MCCarouselWidget.prototype._displayDownloadLink = function (fType, sUrl) {
    var el = document.getElementById('download_' + this.replaceImgId);
    el.href = sUrl;
    YAHOO.util.Dom.removeClass(el, 'noD');
};
MCCarouselWidget.prototype._displayFileInformation = function (fType, fSize) {
    var fileSize = fSize || '';
    var fileInfo = ' (' + fType + ', ' + fileSize + ')';
    if (document.getElementById('title_' + this.replaceImgId).innerHTML.indexOf(fileInfo) < 0) {
        document.getElementById('title_' + this.replaceImgId).innerHTML += fileInfo;
    }
};
MCCarouselWidget.prototype.swapImages = function (obj, newSrc, callback) {
    var i = YAHOO.util.Dom.get(obj.replaceImgId);
    if (i.src.indexOf(newSrc) > -1) {
        callback();
    } else {
        i.onload = function () {
            callback();
        }
        i.src = newSrc;
    }
};
MCCarouselWidget.prototype.setHighlighted = function (obj) {
    if (typeof MediaCenter[this.tabId].highlighted == "undefined") {
        MediaCenter[this.tabId].highlighted = YAHOO.util.Selector.query('ul.carousel-list', this.tabId, true);
    }
    if (typeof MediaCenter[this.tabId].current == "undefined") {
        MediaCenter[this.tabId].current = YAHOO.util.Selector.query('ul.carousel-list li', this.tabId, true);
    }
    YAHOO.util.Dom.removeClass(MediaCenter[this.tabId].highlighted, 'selected');
    YAHOO.util.Dom.removeClass(MediaCenter[this.tabId].current, 'selected');
    YAHOO.util.Dom.addClass(obj.parentNode, 'selected');
    YAHOO.util.Dom.addClass(this.getCarousel().carouselList, 'selected');
    MediaCenter[this.tabId].highlighted = obj.parentNode;
    MediaCenter[this.tabId].current = this.getCarousel().carouselList;
    if (this.getNav()) {
        var id = obj.parentNode.id;
        var num = id.substr(id.indexOf('item-') + 5);
        this._setCurrentNumber(num);
    }
}
MCCarouselWidget.prototype._configureNav = function () {
    if (this.scrollable) {
        this._setCurrentNumber(1);
    } else {
        var cn = this.getNav().childNodes;
        for (var i = 0; i < cn.length; i++) {
            if (cn[i].className && cn[i].className.indexOf('rnd') < 0) {
                cn[i].style.display = 'none';
            }
        }
    }
}
MCCarouselWidget.prototype._setCurrentNumber = function (curNumber) {
    YAHOO.util.Dom.get(this.getCarouselEl() + "-curNum").innerHTML = curNumber;
    YAHOO.util.Dom.get(this.getCarouselEl() + "-maxNum").innerHTML = this.getCarousel().cfg.getProperty('size');
};
MCCarouselWidget.prototype._getNavInfo = function () {
    var rt = {};
    rt.xy = YAHOO.util.Dom.getXY(this.getNav());
    rt.h = this.getNav().offsetHeight;
    return rt;
};
MCCarouselWidget.prototype._setShowNavEvent = function () {
    YAHOO.util.Event.addListener(this.getNav(), 'mousemove', this.handleShowNavigation, this);
};
MCCarouselWidget.prototype.handleShowNavigation = function (e, o) {
    YAHOO.util.Event.removeListener(o.getNav(), 'mousemove');
    o._fadeInNav();
    o._setHideNavEvent();
};
MCCarouselWidget.prototype._fadeInNav = function (e, o) {
    var anim = new YAHOO.util.Anim(this.getNav(), {
        opacity: {
            to: 1
        }
    },
    0.25, YAHOO.util.Easing.easeOut);
    anim.animate();
};
MCCarouselWidget.prototype._showNavigation = function () {
    var coordInfo = this._getNavInfo();
    var top = coordInfo.xy[1] + coordInfo.h;
    var anim = new YAHOO.util.Motion(this.getNav(), {
        points: {
            to: [coordInfo.xy[0], top]
        }
    },
    0.25, YAHOO.util.Easing.easeOut);
    anim.animate();
};
MCCarouselWidget.prototype._setHideNavEvent = function () {
    YAHOO.util.Event.addListener(this.getNav(), 'mouseout', this.handleHideNavigation, this);
};
MCCarouselWidget.prototype.handleHideNavigation = function (e, o) {
    if (e.explicitOriginalTarget.tagName && e.explicitOriginalTarget.tagName.toLowerCase() == "html") {
        YAHOO.util.Event.removeListener(o.getCarouselEl() + "-container", 'mouseout');
        o._fadeOutNav();
        o._setShowNavEvent();
    }
};
MCCarouselWidget.prototype._fadeOutNav = function (e, o) {
    var anim = new YAHOO.util.Anim(this.getNav(), {
        opacity: {
            to: 0.35
        }
    },
    0.25, YAHOO.util.Easing.easeOut);
    anim.animate();
};
MCCarouselWidget.prototype._hideNavigation = function () {
    var coordInfo = this._getNavInfo();
    var top = coordInfo.xy[1] - coordInfo.h;
    var anim = new YAHOO.util.Motion(this.getNav(), {
        points: {
            to: [coordInfo.xy[0], top]
        }
    },
    0.25, YAHOO.util.Easing.easeOut);
    anim.animate();
};
var isSafari = false;
if (YAHOO.env.ua.webkit > 0) {
    isSafari = YAHOO.env.ua.webkit < 525.19;
}
var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
var $A = YAHOO.util.Anim;
var $M = YAHOO.util.Motion;
var $S = YAHOO.util.Scroll;
var $Ease = YAHOO.util.Easing;
var $ = $D.get;
YAHOO.util.AnimMgr.fps = 500;
YAHOO.widget.aEffect = function (el) {
    this.oEl = YAHOO.util.Dom.get(el);
};
YAHOO.widget.aEffect.prototype.aShowLoad = function () {
    var showLoad = new $A('aLoadImg', {
        opacity: {
            to: 1
        }
    },
    0.2);
    showLoad.onStart.subscribe(function () {
        var loadImg = document.getElementById('aLoadImg');
        $D.setStyle(loadImg, 'display', 'block');
        $D.setXY(loadImg, [($D.getViewportWidth() / 2) - 16 + aClient.xScroll(), ($D.getViewportHeight() / 2) - 16 + aClient.yScroll()]);
        if ($D.hasClass('aBoxMeta', 'aOpen')) {
            var hideMeta = new $A('aBoxMeta', {
                opacity: {
                    to: 0
                },
                height: {
                    to: 0
                }
            },
            0.2);
            $D.setStyle('aCloseButton', 'visibility', 'hidden');
            hideMeta.onStart.subscribe(function () {
                $D.setStyle('aImg', 'opacity', '0');
                $D.setStyle('aImg', 'visibility', 'hidden');
                $D.setStyle('aInfoTitle', 'visibility', 'hidden');
                $D.setStyle('lightbox_share', 'visibility', 'hidden');
            });
            hideMeta.animate();
        } else {
            var aBox = document.getElementById('aBox');
            $D.setStyle('aCloseButton', 'visibility', 'hidden');
            $D.setStyle(aBox, 'width', loadImg.offsetWidth + 'px');
            $D.setStyle(aBox, 'height', loadImg.offsetHeight + 'px');
            $D.setXY(aBox, [($D.getViewportWidth() / 2) - 16 + aClient.xScroll(), ($D.getViewportHeight() / 2) - 16 + aClient.yScroll()]);
        }
    });
    showLoad.animate();
};
YAHOO.widget.aEffect.prototype.aShowOverlay = function () {
    selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
        $D.setStyle(selects[i], 'visibility', 'hidden');
    }
    var fadeOverlay = new $A('aOverlay', {
        opacity: {
            to: 0.55
        }
    },
    0.3);
    fadeOverlay.onStart.subscribe(function () {
        $D.setStyle('aOverlay', 'display', 'block');
        $D.setStyle('aOverlay', 'height', aClient.pageHeight() + 'px');
    });
    var showBox = new $A('aBox', {
        opacity: {
            to: 1
        }
    },
    0.3);
    showBox.onStart.subscribe(function () {
        $D.setStyle('aBox', 'display', 'block');
        var showLoad = new YAHOO.widget.aEffect();
        showLoad.aShowLoad();
    });
    showBox.animate();
    fadeOverlay.animate();
};
YAHOO.widget.aEffect.prototype.aResizeBox = function (aPreload) {
    if (window.imageLoad) clearInterval(window.imageLoad);
    $D.addClass('aBox', 'image');
    if (isSafari) {
        $D.setStyle('aDiv', 'visibility', 'hidden');
        $D.setStyle('aDiv', 'display', 'none');
        $D.setStyle('aDiv', 'opacity', '0');
    }
    if (document.getElementById('container_colors')) {
        ColorVariantManager.setSelectedEl(this.oEl);
        if ($D.hasClass(this.oEl, 'enlargeImg')) {
            $D.addClass('aBoxMeta', 'variant');
            if (!document.getElementById('container_lbVariants')) {
                var colors = $D.getElementsByClassName('color', 'div', 'container_colors');
                var lb_variantBlock = document.createElement('div');
                lb_variantBlock.id = 'container_lbVariants';
                lb_variantBlock.className = 'container_colors';
                var selectedColor = '';
                for (var i = 0; i < colors.length; i++) {
                    var el = colors[i];
                    var swatchImg = $D.getNextSibling($D.getFirstChild(el)).cloneNode(false);
                    swatchImg.id = 'lightbox_' + swatchImg.id;
                    var tmp = el.cloneNode(false);
                    tmp.id = el.id.replace('swatch_container', 'swatch_lb');
                    tmp.removeAttribute('onmouseover');
                    tmp.removeAttribute('onmouseout');
                    tmp.onclick = function () {
                        ColorVariantManager.lightboxClick(this.id.substr(this.id.lastIndexOf('_') + 1));
                    };
                    if ($D.hasClass(el, 'selected')) {
                        tmp.className = 'color selected';
                        selectedColor = swatchImg.alt;
                        ColorVariantManager.setOriginalColor(el.id.substr(el.id.lastIndexOf('_') + 1));
                    } else {
                        tmp.className = 'color';
                    }
                    var sp = document.createElement('span');
                    sp.className = 'sm_border';
                    tmp.appendChild(sp);
                    tmp.appendChild(swatchImg);
                    lb_variantBlock.appendChild(tmp);
                }
                var colorInfo = document.createElement('span');
                colorInfo.className = 'color_info';
                colorInfo.innerHTML = 'Select color: <strong id="label_colorName">' + selectedColor + '</strong>';
                lb_variantBlock.appendChild(colorInfo);
                document.getElementById('variant_label').innerHTML = selectedColor + '&nbsp;';
                document.getElementById('variant_label').style.display = 'inline';
                document.getElementById('aBoxMeta').insertBefore(lb_variantBlock, document.getElementById('aBoxMeta').firstChild);
            }
        }
    }
    var imgScale = YAHOO.awesomebox.scaleImage(aPreload);
    var metaHeight = 80;
    var tmpSpan = document.createElement('span');
    tmpSpan.style.visibility = 'hidden';
    document.body.appendChild(tmpSpan);
    tmpSpan.innerHTML = $('aInfo').innerHTML;
    if (imgScale[0] == 0 || isNaN(imgScale[0])) {
        tmpSpan.style.width = '100px';
    } else {
        tmpSpan.style.width = imgScale[0] + 'px';
    }
    tmpSpan.style.display = 'block';
    tmpSpan.style.position = 'absolute';
    tmpSpan.style.left = '-5000px';
    var tmpHeight = parseInt(tmpSpan.offsetHeight, 10);
    document.body.removeChild(tmpSpan);
    if (tmpHeight <= 80) {
        metaHeight = 95;
    } else {
        metaHeight = (tmpHeight - 80) + 105;
    }
    var topPoint = ($D.getViewportHeight() / 2) - (imgScale[1] / 2) + aClient.yScroll();
    topPoint = topPoint - metaHeight < 0 ? 0 : topPoint - metaHeight;
    var leftPoint = ($D.getViewportWidth() / 2) - (imgScale[0] / 2) + aClient.xScroll() - 10;
    var moveBox = new $M('aBox', {
        width: {
            to: (imgScale[0] + 20)
        },
        height: {
            to: imgScale[1]
        },
        points: {
            to: [leftPoint, topPoint]
        }
    },
    0.3);
    moveBox.onStart.subscribe(function () {
        $D.setStyle('aBox', 'display', 'block');
        var hideLoad = new $A('aLoadImg', {
            opacity: {
                to: 0
            }
        },
        0.3);
        var sizeImage = new $A('aImg', {
            width: {
                to: imgScale[0]
            },
            height: {
                to: imgScale[1]
            }
        },
        0.3);
        hideLoad.onComplete.subscribe(function () {
            $D.setStyle('aLoadImg', 'display', 'none');
        });
        hideLoad.animate();
        sizeImage.animate();
    });
    moveBox.onComplete.subscribe(function () {
        var imgReg = YAHOO.util.Dom.getRegion('aImgHolder');
        var hdHeight = imgReg.top - parseFloat(document.getElementById('aBox').style.top);
        var imgOffset = (imgReg.bottom - imgReg.top) - imgScale[1];
        $D.setStyle('aBox', 'height', imgScale[1] + imgOffset + hdHeight + metaHeight + 'px');
        $D.setStyle('aContainer', 'height', imgScale[1] + imgOffset + hdHeight + 'px');
        $D.setStyle('aBoxMeta', 'width', imgScale[0] + 'px');
        $D.addClass('aBoxMeta', 'aOpen');
        $('aImg').setAttribute('width', imgScale[0]);
        $('aImg').setAttribute('height', imgScale[1]);
        $D.setStyle('aImg', 'visibility', 'visible');
        $D.setStyle('aInfoTitle', 'visibility', 'visible');
        var fadeImg = new $A('aImg', {
            opacity: {
                from: 0,
                to: 1
            }
        },
        0.3);
        fadeImg.onComplete.subscribe(function () {
            var showMeta = new $A('aBoxMeta', {
                opacity: {
                    from: 0,
                    to: 1
                },
                height: {
                    to: metaHeight
                }
            },
            0.2);
            showMeta.onComplete.subscribe(function () {
                YAHOO.util.Dom.setStyle('aCount', 'filter', '');
            });
            showMeta.animate();
            YAHOO.util.Dom.setStyle('lightbox_share', 'visibility', 'visible');
            $D.setStyle('aCloseButton', 'visibility', 'visible');
        });
        fadeImg.animate();
    });
    var lbImage = $('aImg');
    if (lbImage.src == aPreload.src) {
        moveBox.animate();
    } else {
        setTimeout(function () {
            lbImage.onload = function () {
                moveBox.animate();
            }
            lbImage.src = aPreload.src;
        },
        300);
    }
};
YAHOO.widget.aEffect.prototype.aResizeBoxEl = function (aPreload, anEl) {
    $D.addClass('aBox', 'swf');
    var metaHeight = 80;
    var tmpSpan = document.createElement('span');
    tmpSpan.style.visibility = 'hidden';
    document.body.appendChild(tmpSpan);
    tmpSpan.innerHTML = $('aInfo').innerHTML;
    if (aPreload.width == 0 || isNaN(aPreload.width)) {
        tmpSpan.style.width = '100px';
    } else {
        tmpSpan.style.width = aPreload.width + 'px';
    }
    tmpSpan.style.display = 'block';
    tmpSpan.style.position = 'absolute';
    tmpSpan.style.left = '-5000px';
    var tmpHeight = parseInt(tmpSpan.offsetHeight, 10);
    document.body.removeChild(tmpSpan);
    if (tmpHeight < 30) {
        metaHeight = 80;
    } else if (tmpHeight >= 30 && tmpHeight <= 90) {
        metaHeight = (80 - tmpHeight + 10) + 80;
    } else if (tmpHeight > 0) {
        metaHeight = tmpHeight + 60;
    }
    var imgScale = YAHOO.awesomebox.scaleImage(aPreload);
    var topPoint = ($D.getViewportHeight() / 2) - (imgScale[1] / 2) + aClient.yScroll() - metaHeight;
    topPoint = topPoint < 0 ? 0 : topPoint;
    var moveBox = new $M('aBox', {
        width: {
            to: (aPreload.width + 30)
        },
        height: {
            to: (aPreload.height + 90 + metaHeight)
        },
        points: {
            to: [($D.getViewportWidth() / 2) - (aPreload.width / 2) + aClient.xScroll() - 10, topPoint]
        }
    },
    0.3);
    moveBox.onStart.subscribe(function () {
        $D.setStyle('aBox', 'display', 'block');
        var hideLoad = new $A('aLoadImg', {
            opacity: {
                to: 0
            }
        },
        0.3);
        var sizeBox = new $A('aDiv', {
            width: {
                to: aPreload.width
            },
            height: {
                to: aPreload.height
            }
        },
        0.3);
        hideLoad.onComplete.subscribe(function () {
            $D.setStyle('aLoadImg', 'display', 'none');
        });
        hideLoad.animate();
        sizeBox.animate();
    });
    moveBox.onComplete.subscribe(function () {
        var prHeight = aPreload.height;
        var prWidth = aPreload.width;
        $D.setStyle('aDiv', 'opacity', '1');
        $D.setStyle('aInfoTitle', 'visibility', 'visible');
        $D.setStyle('lightbox_share', 'visibility', 'visible');
        $D.setStyle('aCloseButton', 'visibility', 'visible');
        $D.setStyle('aImg', 'width', '0');
        $D.setStyle('aImg', 'height', '0');
        $D.setStyle('aBoxMeta', 'width', prWidth + 30 + 'px');
        $D.addClass('aBoxMeta', 'aOpen');
        $D.setStyle('aDiv', 'visibility', 'visible');
        $D.setStyle('aDiv', 'display', 'block');
        var showMeta = new $A('aBoxMeta', {
            opacity: {
                from: 0,
                to: 1
            },
            height: {
                to: 80
            }
        },
        0.2);
        if (anEl.href.indexOf('.swf') > 0) {
            $D.setStyle('aDiv', 'width', prWidth + 'px');
            $D.setStyle('aDiv', 'height', prHeight + 'px');
            showMeta.onComplete.subscribe(function () {
                setTimeout(function () {
                    var fo = new FlashObject(anEl.href + '?' + Math.round(Math.random() * 100000), anEl.rel + '' + Math.round(Math.random()), prWidth, prHeight, '#FFF');
                    fo.addParam('allowScriptAccess', 'sameDomain');
                    fo.addParam('wMode', 'transparent');
                    fo.write('aDiv');
                    var imgReg = YAHOO.util.Dom.getRegion('aImgHolder');
                    var hdHeight = imgReg.top - parseFloat(document.getElementById('aBox').style.top);
                    var imgOffset = (imgReg.bottom - imgReg.top) - prHeight;
                    $D.setStyle('aContainer', 'height', hdHeight + imgOffset + prHeight + 'px');
                },
                10);
            });
        } else {
            showMeta.onComplete.subscribe(function () {
                $D.setStyle('aDiv', 'width', prWidth + 30 + 'px');
                $D.setStyle('aDiv', 'height', prHeight + 30 + 'px');
                setTimeout(function () {
                    var fo = new FlashObject('/static/flash/mediabar/nikonvideo.swf?' + Math.round(Math.random() * 100000), anEl.rel + '' + Math.round(Math.random()), prWidth + 30, prHeight + 45, '#FFF');
                    fo.addParam('allowScriptAccess', 'sameDomain');
                    fo.addVariable('path', anEl.href);
                    fo.addVariable('title', '');
                    fo.addVariable('close', 'YAHOO.awesomebox.close');
                    fo.addVariable('showClose', false);
                    fo.addParam('wMode', 'transparent');
                    fo.write('aDiv');
                    var imgReg = YAHOO.util.Dom.getRegion('aImgHolder');
                    var hdHeight = imgReg.top - parseFloat(document.getElementById('aBox').style.top);
                    var imgOffset = (imgReg.bottom - imgReg.top) - prHeight;
                    $D.setStyle('aContainer', 'height', hdHeight + imgOffset + prHeight + 'px');
                },
                10);
            });
        }
        showMeta.animate();
    });
    moveBox.animate();
};
YAHOO.widget.aEffect.prototype.aClose = function () {
    var that = $('aImg');
    $D.removeClass('aBoxMeta', 'variant');
    if (document.getElementById('container_lbVariants')) {
        document.getElementById('container_lbVariants').parentNode.removeChild(document.getElementById('container_lbVariants'));
        document.getElementById('variant_label').style.display = 'none';
        ColorVariantManager.resetEnlargeImg();
    }
    var hideMeta = new $A('aBoxMeta', {
        height: {
            to: 0
        },
        opacity: {
            to: 0
        }
    },
    0.2);
    var fadeBox = new $M('aBox', {
        opacity: {
            to: 0
        }
    },
    0.3);
    fadeBox.onStart.subscribe(function () {
        $('aDiv').innerHTML = '';
    });
    fadeBox.onComplete.subscribe(function () {
        var hideOverlay = new $A('aOverlay', {
            opacity: {
                to: 0
            }
        },
        0.3);
        hideOverlay.onStart.subscribe(function () {
            selects = document.getElementsByTagName("select");
            for (i = 0; i != selects.length; i++) {
                $D.setStyle(selects[i], 'visibility', 'visible');
            }
            $D.removeClass('aBoxMeta', 'aOpen');
            $D.removeClass('aBox', 'swf');
            $D.removeClass('aBox', 'image');
            $D.setStyle('aBox', 'display', 'none');
            $D.setStyle('aInfoTitle', 'visibility', 'hidden');
            $D.setStyle('lightbox_share', 'visibility', 'hidden');
            $D.setStyle('aImg', 'opacity', '0');
            $D.setStyle('aImg', 'visibility', 'hidden');
            $D.setStyle('aDiv', 'visibility', 'hidden');
            $D.setStyle('aDiv', 'display', 'none');
            $D.setStyle('aDiv', 'opacity', '0');
            $D.setStyle('aOverlay', 'display', 'none');
            $D.setStyle('aOverlay', 'height', '0px');
            $D.setStyle('aLoadImg', 'display', 'none');
        });
        hideOverlay.onComplete.subscribe(function () {
            var w = $D.getStyle('aDiv', 'width');
            var h = $D.getStyle('aDiv', 'height');
            $D.setStyle('aImg', 'width', w);
            $D.setStyle('aImg', 'height', h);
            $D.setStyle('aDiv', 'width', '0');
            $D.setStyle('aDiv', 'height', '0');
        });
        hideOverlay.animate();
    });
    hideMeta.animate();
    fadeBox.animate();
    $E.removeListener('aNextButton', 'click');
    $E.removeListener('aPrevButton', 'click');
};
YAHOO.widget.aEffect.prototype.aAwesome = function () {
    return true;
};
YAHOO.awesomebox = function () {
    return {
        init: function () {
            if (!document.getElementsByTagName) {
                return;
            }
            var aBody = document.getElementsByTagName("body").item(0);
            var aOverlay = document.createElement('div');
            $(aOverlay).setAttribute('id', 'aOverlay');
            $(aOverlay).setAttribute('title', 'Click to Close');
            aBody.appendChild(aOverlay);
            $D.setStyle('aOverlay', 'opacity', '0');
            var aBox = document.createElement('div');
            $(aBox).setAttribute('id', 'aBox');
            aBody.appendChild(aBox);
            $D.addClass('aBox', 'l-e');
            $D.setStyle('aBox', 'opacity', '0');
            $D.setXY('aBox', [($D.getViewportWidth() / 2) - 21, ($D.getViewportHeight() / 2) - 21])
            $D.setStyle('aBox', 'display', 'none');
            var aContainer = document.createElement('div');
            $(aContainer).setAttribute('id', 'aContainer');
            var aCloseButton = document.createElement('a');
            $(aCloseButton).setAttribute('id', 'aCloseButton');
            $(aCloseButton).setAttribute('href', 'javascript:void(0)');
            aContainer.appendChild(aCloseButton);
            $D.addClass(aCloseButton, 'aButton');
            var aInfoTitle = document.createElement('h5');
            $(aInfoTitle).setAttribute('id', 'aInfoTitle');
            aContainer.appendChild(aInfoTitle);
            var lightboxShare = document.createElement('div');
            lightboxShare.setAttribute('id', 'lightbox_share');
            lightboxShare.innerHTML = '<a id="lightbox_printLink" href="javascript:YAHOO.awesomebox.printImage();" class="std"></a>';
            lightboxShare.innerHTML += '<a id="lightbox_addThisLink" href="http://www.addthis.com/bookmark.php" onmouseout="addthis_close();" onclick="return addthis_sendto();"><!--<img height="16" width="125" border="0" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Share"/>--></a>';
            aContainer.appendChild(lightboxShare);
            var aImgHolder = document.createElement('div');
            $(aImgHolder).setAttribute('id', 'aImgHolder');
            aContainer.appendChild(aImgHolder);
            var aImg = document.createElement('img');
            $(aImg).setAttribute('id', 'aImg');
            aImgHolder.appendChild(aImg);
            $D.setStyle('aImg', 'opacity', '0');
            $D.setStyle('aImg', 'visibility', 'hidden');
            var aDiv = document.createElement('div');
            $(aDiv).setAttribute('id', 'aDiv');
            aImgHolder.appendChild(aDiv);
            $D.setStyle('aDiv', 'opacity', '0');
            $D.setStyle('aDiv', 'visibility', 'hidden');
            aBox.appendChild(aContainer);
            var aBoxMeta = document.createElement('div');
            $(aBoxMeta).setAttribute('id', 'aBoxMeta');
            aBox.appendChild(aBoxMeta);
            var aInfo = document.createElement('div');
            $(aInfo).setAttribute('id', 'aInfo');
            aBoxMeta.appendChild(aInfo);
            var aNextButton = document.createElement('a');
            $(aNextButton).setAttribute('id', 'aNextButton');
            aBoxMeta.appendChild(aNextButton);
            $(aNextButton).setAttribute('href', 'javascript:void(0)');
            $D.addClass(aNextButton, 'aButton');
            var aPrevButton = document.createElement('a');
            $(aPrevButton).setAttribute('id', 'aPrevButton');
            aBoxMeta.appendChild(aPrevButton);
            $(aPrevButton).setAttribute('href', 'javascript:void(0)');
            $D.addClass(aPrevButton, 'aButton');
            var aCountContainer = document.createElement('div');
            $(aCountContainer).setAttribute('id', 'aCountContainer');
            var variantLabel = document.createElement('label');
            $(variantLabel).setAttribute('id', 'variant_label');
            aCountContainer.appendChild(variantLabel);
            var aCount = document.createElement('label');
            $(aCount).setAttribute('id', 'aCount');
            aCountContainer.appendChild(aCount);
            aBoxMeta.appendChild(aCountContainer);
            $D.setStyle(aCount, 'opacity', '0');
            var preloadLoading = new Image();
            preloadLoading.src = aLoadImgSrc;
            var aLoadImg = document.createElement('img');
            $(aLoadImg).setAttribute('id', 'aLoadImg');
            aBody.appendChild(aLoadImg);
            $(aLoadImg).setAttribute('src', preloadLoading.src);
            $D.setStyle('aLoadImg', 'opacity', '0');
            var atLink = document.getElementById('lightbox_addThisLink');
            YAHOO.util.Event.addListener(atLink, 'mouseover', function () {
                OmnitureHelper.setAddThisEvents();
                var tStr = "";
                if (document.getElementById('lightbox_itemTitle')) {
                    tStr = document.getElementById('lightbox_itemTitle').innerHTML;
                }
                return addthis_open(this, '', window.location.href, tStr);
            });
            if (window.location.href.indexOf('showAsset') != -1) {
                var asset = window.location.href.match(/showAsset=([^&]*)&?/)[1];
                if (document.body.id != '' || document.body.id != null) {
                    var body = $D.generateId(document.body);
                } else {
                    var body = document.body.id;
                }
                var allItems = YAHOO.util.Selector.query('ul.carousel-list li a');
                for (var i = 0; i < allItems.length; i++) {
                    if (allItems[i].href.indexOf(asset) > -1) {
                        var matchedItem = allItems[i];
                        var tmpId = matchedItem.id.substr(matchedItem.id.lastIndexOf('_') + 1);
                        tmpId = parseInt(tmpId.substr(0, tmpId.lastIndexOf('-')));
                        mcTabs.set('activeIndex', (tmpId - 1));
                        this.itemID = 'selectedImg_' + tmpId;
                        if (asset.indexOf('swf') > 0 || asset.indexOf('mp3') > 0 || asset.indexOf('flv') > 0) {
                            if (!isSafari) this.initLoadSwf(matchedItem);
                            else this.initLoadSafari(matchedItem);
                        } else {
                            this.initLoadImg(matchedItem);
                        }
                    }
                }
            }
            $E.on(aOverlay, 'click', this.close);
            $E.on(aCloseButton, 'click', this.close);
        },
        setClickAction: function (o, obj) {
            $E.removeListener(o, 'click');
            var fileType = o.href.substr(o.href.lastIndexOf('.') + 1).toLowerCase();
            if (fileType in aClient.aTypes) {
                if (fileType == 'swf' || fileType == 'mp3' || fileType == 'flv') {
                    if (!isSafari) $E.addListener(o, 'click', function (e) {
                        YAHOO.util.Event.preventDefault(e);
                        obj.loadSwf(e, this);
                    });
                    else $E.addListener(o, 'click', function (e) {
                        YAHOO.util.Event.preventDefault(e);
                        obj.loadSafari(e, this);
                    });
                } else {
                    $E.addListener(o, 'click', function (e) {
                        YAHOO.util.Event.preventDefault(e);
                        obj.loadImg(e, this);
                    });
                }
            }
        },
        setUrl: function (asset, tab, title) {
            var hashParams = "#" + 'showAsset=' + asset + "&tab=" + tab;
            var hashPosition = window.location.href.indexOf('#');
            if (hashPosition < 0) {
                window.location.href = window.location.href + hashParams;
            } else {
                window.location.href = window.location.href.substr(0, hashPosition) + hashParams;
            }
            var atLink = document.getElementById('lightbox_addThisLink');
            if (atLink) {
                atLink.href = atLink.href.replace('{sUrl}', window.location.href).replace('{sTitle}', title);
            }
        },
        loadSafari: function (e, newSwf) {
            $E.stopEvent(e);
            var sz;
            if (e.target.parentNode.getAttribute('size')) sz = e.target.parentNode.getAttribute('size');
            else {
                var m = e.target.parentNode.className.match(/\bsize_(\d\d\d\d?x\d\d\d\d?)\b/);
                if (m) sz = m[1];
                else sz = null;
            }
            if (sz == null || sz == 'undefined') sz = '480x360';
            var dim = sz.split('x');
            var aItemTitle = '';
            var aItemDesc = '';
            var tmpStr = '';
            if (newSwf.getAttribute('title')) {
                tmpStr = newSwf.getAttribute('title');
                aItemTitle = (tmpStr == 'null' || tmpStr == null) ? '' : tmpStr;
            }
            if (newSwf.getAttribute('data-fulldescription')) {
                tmpStr = newSwf.getAttribute('data-fulldescription');
                aItemDesc = (tmpStr == 'null' || tmpStr == null) ? '' : tmpStr;
            }
            var tmpHeight = 0;
            var hasInfo = (aItemTitle + aItemDesc).length > 0;
            if (hasInfo) {
                var htmlStr = '<h4 id="lightbox_itemTitle">' + aItemTitle + '</h4><label>' + aItemDesc + '</label>'
                var tmpEl = document.createElement('span');
                tmpEl.style.position = 'absolute';
                tmpEl.style.left = '-5000px';
                tmpEl.style.width = parseInt(dim[0]) + 20 + 'px';
                document.body.appendChild(tmpEl);
                tmpEl.innerHTML = htmlStr;
                tmpHeight = tmpEl.offsetHeight + 20;
                document.body.removeChild(tmpEl);
            }
            if (newSwf.href.indexOf('.swf') > 0) {
                tmpHeight += 20;
                var pWin = window.open('/static/html/swf_frame.html?file=' + newSwf.href + '&sz=' + sz + '&title=' + newSwf.getAttribute('title'), 'nMedia', 'resizable=1,width=' + (parseInt(dim[0]) + 20) + ',height=' + (parseInt(dim[1]) + tmpHeight));
                if (hasInfo) {
                    testOpenInterval = setInterval(function () {
                        if (pWin.document && pWin.document.getElementById('aDescription')) {
                            clearInterval(testOpenInterval);
                            var pDoc = pWin.document;
                            pDoc.getElementById('aDescription').innerHTML = htmlStr;
                            pDoc.getElementById('aDescription').className = '';
                        }
                    },
                    150);
                }
            } else {
                tmpHeight += 55;
                var pWin = window.open('/static/flash/mediabar/video_frame.html?file=' + newSwf.href + '&sz=' + sz, 'nMedia', 'resizable=1,width=' + parseInt(parseInt(dim[0]) + 50) + ',height=' + parseInt(parseInt(dim[1]) + tmpHeight));
                if (hasInfo) {
                    testOpenInterval = setInterval(function () {
                        if (pWin.document && pWin.document.getElementById('aDescription')) {
                            clearInterval(testOpenInterval);
                            var pDoc = pWin.document;
                            pDoc.getElementById('aDescription').innerHTML = htmlStr;
                            pDoc.getElementById('aDescription').className = '';
                        }
                    },
                    150);
                }
            }
        },
        initLoadSafari: function (el) {
            if (el.getAttribute('size')) sz = el.getAttribute('size');
            else {
                var m = el.className.match(/\bsize_(\d\d\d\d?x\d\d\d\d?)\b/);
                if (m) sz = m[1];
                else sz = null;
            }
            if (sz == null || sz == 'undefined') sz = '480x360';
            var dim = sz.split('x');
            var aItemTitle = '';
            var aItemDesc = '';
            var tmpStr = '';
            if (newSwf.getAttribute('title')) {
                tmpStr = newSwf.getAttribute('title');
                aItemTitle = (tmpStr == 'null' || tmpStr == null) ? '' : tmpStr;
            }
            if (newSwf.getAttribute('data-fulldescription')) {
                tmpStr = newSwf.getAttribute('data-fulldescription');
                aItemDesc = (tmpStr == 'null' || tmpStr == null) ? '' : tmpStr;
            }
            var tmpHeight = 0;
            var hasInfo = (aItemTitle + aItemDesc).length > 0;
            if (hasInfo) {
                var htmlStr = '<h4 id="lightbox_itemTitle">' + aItemTitle + '</h4><label>' + aItemDesc + '</label>'
                var tmpEl = document.createElement('span');
                tmpEl.style.position = 'absolute';
                tmpEl.style.left = '-5000px';
                tmpEl.style.width = parseInt(dim[0]) + 20 + 'px';
                document.body.appendChild(tmpEl);
                tmpEl.innerHTML = htmlStr;
                tmpHeight = tmpEl.offsetHeight;
                document.body.removeChild(tmpEl);
            }
            if (newSwf.href.indexOf('.swf') > 0) {
                tmpHeight += 20;
                var pWin = window.open('/static/html/swf_frame.html?file=' + newSwf.href + '&sz=' + sz + '&title=' + newSwf.getAttribute('title'), 'nMedia', 'resizable=1,width=' + (parseInt(dim[0]) + 20) + ',height=' + (parseInt(dim[1]) + tmpHeight));
                if (hasInfo) {
                    testOpenInterval = setInterval(function () {
                        if (pWin.document && pWin.document.getElementById('aDescription')) {
                            clearInterval(testOpenInterval);
                            var pDoc = pWin.document;
                            pDoc.getElementById('aDescription').innerHTML = htmlStr;
                            pDoc.getElementById('aDescription').className = '';
                        }
                    },
                    150);
                }
            } else {
                tmpHeight += 55;
                var pWin = window.open('/static/flash/mediabar/video_frame.html?file=' + newSwf.href + '&sz=' + sz, 'nMedia', 'resizable=1,width=' + parseInt(parseInt(dim[0]) + 50) + ',height=' + parseInt(parseInt(dim[1]) + tmpHeight));
                if (hasInfo) {
                    testOpenInterval = setInterval(function () {
                        if (pWin.document && pWin.document.getElementById('aDescription')) {
                            clearInterval(testOpenInterval);
                            var pDoc = pWin.document;
                            pDoc.getElementById('aDescription').innerHTML = htmlStr;
                            pDoc.getElementById('aDescription').className = '';
                        }
                    },
                    150);
                }
            }
        },
        loadSwf: function (e, newSwf) {
            var sz;
            var itemID = "";
            document.getElementById('lightbox_printLink').style.display = 'none';
            var fileType = newSwf.href.substr(newSwf.href.lastIndexOf('.') + 1);
            if (e.srcElement) {
                var srcEl = e.srcElement;
                if (srcEl.tagName.toLowerCase() == 'img') {
                    srcEl = srcEl.parentNode;
                }
                if (srcEl.getAttribute('size')) sz = srcEl.getAttribute('size');
            } else {
                if (e.target.parentNode.getAttribute('size')) sz = e.target.parentNode.getAttribute('size');
            }
            if (sz == null || sz == 'undefined') sz = '480x360';
            $E.stopEvent(e);
            aPreload = new Image();
            aPreload.width = sz.split('x')[0];
            aPreload.height = sz.split('x')[1];
            if (newSwf) {
                var that = newSwf;
                if (that.id.match(/^(link_|enlarge_|enlargeLink_|play_link_)(.*)/)) {
                    YAHOO.awesomebox.itemID = that.id.match(/^(link_|enlarge_|enlargeLink_|play_link_)(.*)/)[2];
                } else if (YAHOO.util.Dom.hasClass(that, 'read_more')) {
                    YAHOO.awesomebox.itemID = that.parentNode.id.match(/^(summary_)(.*)/)[2];
                }
                itemID = YAHOO.awesomebox.itemID;
                this.itemID = itemID;
            } else {
                var that = this;
                itemID = YAHOO.awesomebox.itemID;
            }
            var aInfoTitle = '';
            var aInfo = '';
            var aItemTitle = '';
            var aItemDesc = '';
            var tmpStr = '';
            aInfoTitle = YAHOO.util.Selector.query('ul.yui-nav li.selected a em', 'mc_tabbed_content', true).innerHTML;
            if (newSwf.getAttribute('title')) {
                tmpStr = newSwf.getAttribute('title');
                aItemTitle = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
            }
            if (newSwf.getAttribute('data-fulldescription')) {
                tmpStr = newSwf.getAttribute('data-fulldescription');
                aItemDesc = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
            }
            var aInfo = '<h4 id="lightbox_itemTitle">' + aItemTitle + '</h4><label>' + aItemDesc + '</label>';
            if (! (fileType in aClient.noDownloadLink)) {
                aInfo += '<br/><a href="' + that.href + '" class="std">' + nikonLabel.download + '</a>';
            }
            if ($D.hasClass('aBoxMeta', 'aOpen')) {
                setTimeout(function () {
                    $('aInfoTitle').innerHTML = aInfoTitle;
                    $('aInfo').innerHTML = aInfo;
                },
                250);
            } else {
                $('aInfoTitle').innerHTML = aInfoTitle;
                $('aInfo').innerHTML = aInfo;
            }
            var resizeBox = new YAHOO.widget.aEffect(that);
            resizeBox.aResizeBoxEl(aPreload, that);
            var fadeOverlayIn = new YAHOO.widget.aEffect();
            fadeOverlayIn.aShowOverlay();
            $D.setStyle('aNextButton', 'visibility', 'hidden');
            $D.setStyle('aPrevButton', 'visibility', 'hidden');
            $D.setStyle('aCount', 'opacity', '0');
            var currentTab = YAHOO.awesomebox.itemID.substr(YAHOO.awesomebox.itemID.indexOf('_') + 1);
            YAHOO.awesomebox.setUrl(that.href.substr(that.href.lastIndexOf('/') + 1), currentTab, aInfoTitle);
        },
        initLoadSwf: function (el) {
            var sz;
            document.getElementById('lightbox_printLink').style.display = 'none';
            var fileType = el.href.substr(el.href.lastIndexOf('.') + 1);
            if (el.getAttribute('size')) sz = el.getAttribute('size');
            else {
                var m = el.className.match(/\bsize_(\d\d\d\d?x\d\d\d\d?)\b/);
                if (m) sz = m[1];
                else sz = null;
            }
            if (sz == null || sz == 'undefined') sz = '480x360';
            aPreload = new Image();
            aPreload.width = sz.split('x')[0];
            aPreload.height = sz.split('x')[1];
            var aInfoTitle = '';
            var aInfo = '';
            var aItemTitle = '';
            var aItemDesc = '';
            var tmpStr = '';
            aInfoTitle = YAHOO.util.Selector.query('ul.yui-nav li.selected a em', 'mc_tabbed_content', true).innerHTML;
            if (el.getAttribute('title')) {
                tmpStr = el.getAttribute('title');
                aItemTitle = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
            }
            if (el.getAttribute('data-fulldescription')) {
                tmpStr = el.getAttribute('data-fulldescription');
                aItemDesc = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
            }
            var aInfo = '<h4 id="lightbox_itemTitle">' + aItemTitle + '</h4><label>' + aItemDesc + '</label>';
            if (! (fileType in aClient.noDownloadLink)) {
                aInfo += '<br/><a href="' + el.href + '" class="std">' + nikonLabel.download + '</a>';
            }
            if ($D.hasClass('aBoxMeta', 'aOpen')) {
                setTimeout(function () {
                    $('aInfoTitle').innerHTML = aInfoTitle;
                    $('aInfo').innerHTML = aInfo;
                },
                250);
            } else {
                $('aInfoTitle').innerHTML = aInfoTitle;
                $('aInfo').innerHTML = aInfo;
            }
            var resizeBox = new YAHOO.widget.aEffect(el);
            resizeBox.aResizeBoxEl(aPreload, el);
            var fadeOverlayIn = new YAHOO.widget.aEffect();
            fadeOverlayIn.aShowOverlay();
            $D.setStyle('aNextButton', 'visibility', 'hidden');
            $D.setStyle('aPrevButton', 'visibility', 'hidden');
            $D.setStyle('aCount', 'opacity', '0');
        },
        loadImg: function (e, newImg) {
            var fadeOverlayIn = new YAHOO.widget.aEffect();
            fadeOverlayIn.aShowOverlay();
            document.getElementById('lightbox_printLink').style.display = 'block';
            var itemID = "";
            if (newImg) {
                var that = newImg;
                if (that.id.match(/^(link_|enlarge_|enlargeLink_)(.*)/)) {
                    YAHOO.awesomebox.itemID = that.id.match(/^(link_|enlarge_|enlargeLink_)(.*)/)[2];
                } else if (YAHOO.util.Dom.hasClass(that, 'read_more')) {
                    YAHOO.awesomebox.itemID = that.parentNode.id.match(/^(summary_)(.*)/)[2];
                }
                itemID = YAHOO.awesomebox.itemID;
                this.itemID = itemID;
            } else {
                var that = this;
                itemID = YAHOO.awesomebox.itemID;
            }
            $E.stopEvent(e);
            aPreload = new Image();
            aPreload.onload = function () {
                clearInterval(window.imageLoad);
                setTimeout(function () {
                    var aInfoTitle = '';
                    var aItemTitle = '';
                    var aItemDesc = '';
                    var tmpStr = '';
                    aInfoTitle = YAHOO.util.Selector.query('ul.yui-nav li.selected a em', 'mc_tabbed_content', true).innerHTML;
                    if (newImg.getAttribute('title')) {
                        tmpStr = newImg.getAttribute('title');
                        aItemTitle = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
                    }
                    if (newImg.getAttribute('data-fulldescription')) {
                        tmpStr = newImg.getAttribute('data-fulldescription');
                        aItemDesc = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
                    }
                    var aInfo = '<h4 id="lightbox_itemTitle">' + aItemTitle + '</h4><label>' + aItemDesc + '</label>';
                    if ($D.hasClass('aBoxMeta', 'aOpen')) {
                        setTimeout(function () {
                            $('aInfoTitle').innerHTML = aInfoTitle;
                            $('aInfo').innerHTML = aInfo;
                            var resizeBox = new YAHOO.widget.aEffect(that);
                            resizeBox.aResizeBox(aPreload);
                        },
                        250);
                    } else {
                        $('aInfoTitle').innerHTML = aInfoTitle;
                        $('aInfo').innerHTML = aInfo;
                        var resizeBox = new YAHOO.widget.aEffect(that);
                        resizeBox.aResizeBox(aPreload);
                    }
                    if (!that.getAttribute('rel')) {
                        $D.setStyle('aNextButton', 'visibility', 'hidden');
                        $D.setStyle('aPrevButton', 'visibility', 'hidden');
                        $D.setStyle('aCount', 'opacity', '0');
                    } else {
                        $D.setStyle('aCount', 'opacity', '1');
                        $E.removeListener('aNextButton', 'click');
                        $E.removeListener('aPrevButton', 'click');
                    }
                    if (that.getAttribute('rel')) {
                        YAHOO.awesomebox.loadNeighbors(that);
                    } else if (that.id.indexOf('enlargeLink') > -1) {
                        var linkId = 'link_' + that.id.substr('enlargeLink_'.length);
                        var linkEl = document.getElementById(linkId);
                        if (linkEl.getAttribute('rel')) {
                            $D.setStyle('aCount', 'opacity', '1');
                            $E.removeListener('aNextButton', 'click');
                            $E.removeListener('aPrevButton', 'click');
                            YAHOO.awesomebox.loadNeighbors(linkEl);
                        }
                    } else if (YAHOO.util.Dom.hasClass(that, 'read_more')) {
                        var linkId = 'link_' + that.parentNode.id.substr('summary_'.length);
                        var linkEl = document.getElementById(linkId);
                        if (linkEl.getAttribute('rel')) {
                            $D.setStyle('aCount', 'opacity', '1');
                            $E.removeListener('aNextButton', 'click');
                            $E.removeListener('aPrevButton', 'click');
                            YAHOO.awesomebox.loadNeighbors(linkEl);
                        }
                    }
                    var currentTab = YAHOO.awesomebox.itemID.substr(YAHOO.awesomebox.itemID.indexOf('_') + 1);
                    YAHOO.awesomebox.setUrl(that.href.substr(that.href.lastIndexOf('/') + 1), currentTab, aInfoTitle);
                },
                10);
            };
            aPreload.src = that.getAttribute('href');
            clearInterval(window.imageLoad);
            window.imageLoad = setInterval(function () {
                if (aPreload.src == document.getElementById('aImg').src) {
                    clearInterval(window.imageLoad);
                    return false;
                } else {
                    YAHOO.awesomebox.close();
                    aPreload.src = '';
                    alert(nikonLabel.missingItem);
                }
            },
            20000);
        },
        initLoadImg: function (el) {
            var fadeOverlayIn = new YAHOO.widget.aEffect();
            var newImg = el;
            fadeOverlayIn.aShowOverlay();
            document.getElementById('lightbox_printLink').style.display = 'block';
            aPreload = new Image();
            aPreload.onload = function () {
                clearInterval(window.imageLoad);
                var aInfoTitle = '';
                var aItemTitle = '';
                var aItemDesc = '';
                var tmpStr = '';
                if (newImg.getAttribute('rel')) {
                    tmpStr = newImg.getAttribute('rel');
                    aInfoTitle = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
                }
                if (newImg.getAttribute('title')) {
                    tmpStr = newImg.getAttribute('title');
                    aItemTitle = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
                }
                if (newImg.getAttribute('data-fulldescription')) {
                    tmpStr = newImg.getAttribute('data-fulldescription');
                    aItemDesc = (tmpStr == 'null' || tmpStr == null) ? '&nbsp;' : tmpStr;
                }
                var aInfo = '<h4 id="lightbox_itemTitle">' + aItemTitle + '</h4><label>' + aItemDesc + '</label>';
                $('aInfoTitle').innerHTML = aInfoTitle;
                $('aInfo').innerHTML = aInfo;
                var resizeBox = new YAHOO.widget.aEffect(el);
                resizeBox.aResizeBox(aPreload);
                if (!el.getAttribute('rel')) {
                    $D.setStyle('aNextButton', 'visibility', 'hidden');
                    $D.setStyle('aPrevButton', 'visibility', 'hidden');
                    $D.setStyle('aCount', 'opacity', '0');
                } else {
                    $D.setStyle('aCount', 'opacity', '1');
                    $E.removeListener('aNextButton', 'click');
                    $E.removeListener('aPrevButton', 'click');
                }
                if (el.getAttribute('rel')) {
                    YAHOO.awesomebox.loadNeighbors(el);
                }
            };
            aPreload.src = el.getAttribute('href');
            clearInterval(window.imageLoad);
            window.imageLoad = setInterval(function () {
                if (aPreload.src == document.getElementById('aImg').src) {
                    clearInterval(window.imageLoad);
                    return false;
                } else {
                    YAHOO.awesomebox.close();
                    aPreload.src = '';
                    alert(nikonLabel.missingItem);
                }
            },
            20000);
        },
        loadNeighbors: function (that) {
            var imgRefs = aClient.photos;
            var mGroup = aClient.getGroup(that.rel);
            if (mGroup.mediaType != 'mixed' && mGroup.items && mGroup.items.length > 0) {
                var photoSet = mGroup.items;
                var key = aClient.isInGroup(that.rel, that.href);
                setTimeout(function () {
                    $('aCount').innerHTML = 'Image ' + (key + 1) + ' of ' + photoSet.length;
                    $D.setStyle('aCount', 'visibility', 'visible');
                },
                300);
                if (key != photoSet.length - 1) {
                    var next = new Image();
                    next.src = photoSet[key + 1].getAttribute('href');
                    $D.setStyle('aNextButton', 'visibility', 'visible');
                } else {
                    $D.setStyle('aNextButton', 'visibility', 'hidden');
                }
                if (key != 0) {
                    var prev = new Image();
                    prev.src = photoSet[key - 1].getAttribute('href');
                    $D.setStyle('aPrevButton', 'visibility', 'visible');
                } else {
                    $D.setStyle('aPrevButton', 'visibility', 'hidden');
                }
                $E.addListener('aNextButton', 'click', this.loadImg, photoSet[key + 1], true);
                $E.addListener('aPrevButton', 'click', this.loadImg, photoSet[key - 1], true);
            } else {
                $D.setStyle('aCount', 'visibility', 'hidden');
                $D.setStyle('aNextButton', 'visibility', 'hidden');
                $D.setStyle('aPrevButton', 'visibility', 'hidden');
            }
        },
        showOverlay: function (el) {
            el = YAHOO.util.Dom.get(el);
            var w = el.getAttribute('data-width');
            var h = el.getAttribute('data-height');
            if (!document.getElementById('mb_overlay')) {
                var d = document.createElement('div');
                d.id = "mb_overlay";
                d.className = "liquidPop pop singleCol";
                d.innerHTML = '<div class="hd"><span class="l"> </span> ' + '<div class="m"><a id="mb_overlay_close" class="closeIcon" href="javascript:void(0)"> </a><h3 class="nkYellow">{popupTitle}</h3></div> ' + '<span class="r"> </span></div>' + '<div class="container_bd"><div class="l"><div class="r"><div class="bd">{popupContent}</div></div></div></div>' + '<div class="ft"><span class="l"> </span><div class="m"> </div><span class="r"> </span></div>';
                document.body.insertBefore(d, document.body.firstChild);
            }
            var overlay = document.getElementById('mb_overlay');
            if (YAHOO.util.Dom.getStyle(overlay, 'display') == "block") {
                this._resetOverlay();
            }
            YAHOO.util.Dom.setStyle(overlay, 'opacity', '0');
            YAHOO.util.Dom.setStyle(overlay, 'display', 'block');
            overlay.innerHTML = overlay.innerHTML.replace('{popupTitle}', el.title).replace('{popupContent}', document.getElementById(el.id + '_content').innerHTML);
            var bd = YAHOO.util.Selector.query('div.container_bd div.bd', overlay, true);
            if (w) {
                bd.style.width = w + "px";
                overlay.style.width = bd.offsetWidth + "px";
            } else {
                if (bd.firstChild.offsetWidth > 357) {
                    bd.style.width = bd.firstChild.offsetWidth + "px";
                    overlay.style.width = bd.offsetWidth + "px";
                }
            }
            if (h) {
                bd.style.height = h + "px";
            }
            YAHOO.util.Dom.setXY(overlay, [($D.getViewportWidth() / 2) - (overlay.offsetWidth / 2), ($D.getViewportHeight() / 2) - (overlay.offsetHeight / 2)]);
            overlay.style.display = "none";
            YAHOO.util.Event.addListener('mb_overlay_close', 'click', this.hideOverlay, this);
            this._animOverlay(overlay);
        },
        _animOverlay: function (overlay) {
            overlay.style.display = "block";
            var anim = new YAHOO.util.Anim(overlay, {
                opacity: {
                    to: 0.99
                }
            },
            0.25, YAHOO.util.Easing.easeIn);
            anim.animate();
        },
        _resetOverlay: function () {
            var overlay = document.getElementById('mb_overlay');
            YAHOO.util.Dom.setStyle('mb_overlay', 'display', 'none');
            YAHOO.util.Selector.query('div.hd h3', overlay, true).innerHTML = "{popupTitle}";
            YAHOO.util.Selector.query('div.container_bd div.bd', overlay, true).innerHTML = "{popupContent}";
        },
        hideOverlay: function (e, obj) {
            var anim = new YAHOO.util.Anim("mb_overlay", {
                opacity: {
                    to: 0
                }
            },
            0.25, YAHOO.util.Easing.easeIn);
            anim.onComplete.subscribe(function () {
                obj._resetOverlay();
            });
            anim.animate();
        },
        scaleImage: function (aImage) {
            var ttlReg = YAHOO.util.Dom.getRegion('aInfoTitle');
            var ttlOffset = ttlReg.bottom - ttlReg.top + parseInt(YAHOO.util.Dom.getStyle('aInfoTitle', 'marginTop'));
            var sHeight = aImage.height;
            var sWidth = aImage.width;
            if (aImage.width > $D.getViewportWidth()) {
                sWidth = $D.getViewportWidth() - 20;
                sHeight = aImage.height * (sWidth / aImage.width);
                if (sHeight + 140 + ttlOffset > ($D.getViewportHeight() - 20)) {
                    sHeight = $D.getViewportHeight() - 140 - ttlOffset;
                    sWidth = aImage.width * (sHeight / aImage.height);
                }
            } else if (aImage.height + 140 + ttlOffset > $D.getViewportHeight()) {
                sWidth = aImage.width * (($D.getViewportHeight() - 140 - ttlOffset) / aImage.height);
                sHeight = $D.getViewportHeight() - 140 - ttlOffset;
                if (sWidth > ($D.getViewportWidth() - 20)) {
                    sWidth = aImage.width * (sHeight / aImage.height);
                    sHeight = aImage.height * (sWidth / aImage.width);
                }
            }
            return [Math.floor(sWidth), Math.floor(sHeight)];
        },
        close: function () {
            var aClose = new YAHOO.widget.aEffect();
            aClose.aClose();
            if (window.imageLoad) clearInterval(window.imageLoad);
            if (window.location.href.match(/tab=([^&]*)&?/)) {
                var currentTab = window.location.href.match(/tab=([^&]*)&?/)[1];
                window.location.href = window.location.href.substr(0, window.location.href.indexOf('#')) + '#tab=' + currentTab;
            }
        },
        awesome: function () {
            var aAwesome = new YAHOO.widget.aEffect();
            aAwesome.aAwesome();
        },
        printImage: function () {
            var pWin = window.open('/static/html/le_print_frame.html');
            testOpenInterval = setInterval(function () {
                if (pWin.document && pWin.document.getElementById('printImage')) {
                    clearInterval(testOpenInterval);
                    var pDoc = pWin.document;
                    var pImg = pDoc.getElementById('printImage');
                    pImg.onload = function () {
                        pWin.print();
                    }
                    pImg.src = $('aImg').src;
                    pDoc.getElementById('aBox').innerHTML = '<div id="aInfo">' + $('aInfo').innerHTML + '</div>';
                }
            },
            150);
        }
    }
} ();
YAHOO.util.Event.onDOMReady(YAHOO.awesomebox.init, YAHOO.awesomebox, true);
(GlossaryWidget = function () {
    var sUrl = '';
    var conn = null;
    var glossary = null;
    var termsArray = [];
    var targetID = "";
    return {
        _genError: "We encountered an error. Please try again.",
        _buildGlossary: function (o) {
            var terms = o.responseXML.getElementsByTagName('GlossaryTerm');
            glossary = {};
            for (var i = 0; i < terms.length; i++) {
                var t = terms[i].getElementsByTagName('Title')[0];
                var s = terms[i].getElementsByTagName('Summary')[0];
                var u = terms[i].getElementsByTagName('URL')[0];
                var sUrl = '';
                if (u.text) {
                    sUrl = u.text;
                } else {
                    sUrl = u.textContent;
                }
                var articleName = sUrl.substr(sUrl.lastIndexOf('/') + 1);
                var tmpTitle = t.text ? t.text : t.textContent;
                if (window.location.href.indexOf(articleName) < 0 && !(window.blacklist && window.blacklist == tmpTitle)) {
                    if (t.text) {
                        glossary[t.text] = {
                            term: t.text,
                            summary: s.text,
                            url: sUrl
                        };
                    } else {
                        glossary[t.textContent] = {
                            term: t.textContent,
                            summary: s.textContent,
                            url: sUrl
                        };
                    }
                }
            }
            return this;
        },
        _getGlossaryXML: function () {
            var obj = this;
            conn = YAHOO.util.Connect.asyncRequest('GET', sUrl, {
                success: function (o) {
                    obj._buildGlossary(o)._parseContent();
                },
                failure: function (o) {
                    alert(obj._genError);
                },
                error: function (o) {
                    alert(obj._genError);
                }
            });
        },
        _preg_quote: function (str) {
            return (str + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
        },
        _parseContent: function () {
            var bcEls = YAHOO.util.Dom.getElementsByClassName('in-context-glossary');
            for (var bc = 0; bc < bcEls.length; bc++) {
                var bodyContent = bcEls[bc].innerHTML;
                for (var i in glossary) {
                    var regex = new RegExp('(<dfn [^>]*>)?(<img*?)?\\b(' + this._preg_quote(i) + ')\\b([^<]*?>)?(<\\/dfn>)?', 'ig');
                    bodyContent = bodyContent.replace(regex, function ($0) {
                        return arguments[1] || arguments[2] || arguments[4] || arguments[5] ? $0 : '<dfn onclick="GlossaryWidget.showOverlay(event,this)" data-term="' + i.replace(/\s/g, '_') + '">' + arguments[3] + '</dfn>';
                    });
                }
                bcEls[bc].innerHTML = bodyContent;
            }
        },
        showGlossary: function (e, o) {
            if (glossary == null) {
                o._getGlossaryXML();
            } else {
                o._parseContent();
            }
            o.enableGlossaryOff();
            YAHOO.util.Cookie.set('showInPageGlossary', 'true', {
                expires: new Date("January 12, 2025"),
                path: '/'
            });
            return o;
        },
        hideGlossary: function (e, o) {
            var bcEls = YAHOO.util.Dom.getElementsByClassName('in-context-glossary');
            for (var bc = 0; bc < bcEls.length; bc++) {
                var bodyContent = bcEls[bc].innerHTML;
                for (var i in glossary) {
                    var regex = new RegExp('<dfn [^>]*>(' + this._preg_quote(i) + ')(.*?)<.dfn>', 'ig');
                    bodyContent = bodyContent.replace(regex, function ($0, $1) {
                        return arguments[1];
                    });
                }
                bcEls[bc].innerHTML = bodyContent;
            }
            YAHOO.util.Cookie.remove('showInPageGlossary', {
                path: '/'
            });
            o.enableGlossaryOn();
        },
        showOverlay: function (e, el) {
            var xy = YAHOO.util.Dom.getXY(el);
            var currentTerm = el.getAttribute('data-term').replace(/_/g, ' ');
            var ov = document.getElementById('overlay_glossaryPop');
            if (ov == null) {
                ov = document.createElement('div');
                ov.id = 'overlay_glossaryPop';
                ov.className = 'pop_glossary';
                var tmpHtml = '<div class="hd"><div class="rnd le_bg"></div><h3 class="nkYellow">&nbsp;</h3><a class="close" href="javascript:GlossaryWidget.hideOverlay()">Close</a></div>';
                tmpHtml += '<div class="bd"><div class="definition">&nbsp;</div><a href="#" class="link_definition">&nbsp;</a></div>';
                tmpHtml += '<div class="ft le_bg">&nbsp;</div><div class="corner le_bg tl">&nbsp;</div>';
                ov.innerHTML = tmpHtml;
                document.body.appendChild(ov)
            }
            ov.getElementsByTagName('h3')[0].innerHTML = currentTerm;
            YAHOO.util.Selector.query('div.definition', ov, true).innerHTML = glossary[currentTerm].summary;
            var termLinkEl = YAHOO.util.Selector.query('a.link_definition', ov, true);
            var tmpUrl = glossary[currentTerm].url;
            if (tmpUrl.indexOf('index.page?appendix=' + currentTerm.substring(0, 1).toUpperCase()) < 0) {
                termLinkEl.innerHTML = nikonLabel.learnAbout + " " + currentTerm;
            } else {
                termLinkEl.innerHTML = nikonLabel.photoGlossary;
            }
            termLinkEl.href = tmpUrl;
            YAHOO.util.Event.addListener(termLinkEl, 'click', function () {
                OmnitureHelper.setIPGTermClickEvents(ttlEl.innerHTML);
            });
            var shiftLeft = (xy[0] + ov.offsetWidth) > YAHOO.util.Dom.getViewportWidth();
            var shiftTop = (xy[1] + ov.offsetHeight) > YAHOO.util.Dom.getViewportHeight();
            var cEl = YAHOO.util.Selector.query('div.corner', ov, true);
            if (shiftLeft && shiftTop) {
                cEl.className = "corner le_bg br";
                var newX = xy[0] - ov.offsetWidth - el.offsetWidth + cEl.offsetWidth;
                var newY = xy[1] - ov.offsetHeight - el.offsetHeight + (cEl.offsetWidth / 2);
                YAHOO.util.Dom.setXY(ov, [newX, newY]);
            } else if (!shiftLeft && shiftTop) {
                cEl.className = "corner le_bg bl";
                var newX = xy[0] + el.offsetWidth + cEl.offsetWidth;
                var newY = xy[1] - ov.offsetHeight - el.offsetHeight + (cEl.offsetWidth / 2);
                YAHOO.util.Dom.setXY(ov, [newX, newY]);
            } else if (shiftLeft && !shiftTop) {
                cEl.className = "corner le_bg tr";
                var newX = xy[0] - ov.offsetWidth - el.offsetWidth + cEl.offsetWidth;
                var newY = xy[1] + el.offsetHeight + (cEl.offsetWidth / 2);
                YAHOO.util.Dom.setXY(ov, [newX, newY]);
            } else {
                cEl.className = "corner le_bg tl";
                var newX = xy[0] + el.offsetWidth + cEl.offsetWidth;
                var newY = xy[1] + el.offsetHeight + (cEl.offsetWidth / 2);
                YAHOO.util.Dom.setXY(ov, [newX, newY]);
            }
            YAHOO.util.Event.stopEvent(e);
            YAHOO.util.Event.addListener(document.body, 'click', GlossaryWidget.maybeHideOverlay, el, this);
        },
        hideOverlay: function (e, el) {
            var ov = document.getElementById('overlay_glossaryPop');
            ov.style.left = "-5000px";
            YAHOO.util.Event.removeListener(document.body, 'click', GlossaryWidget.maybeHideOverlay, el, this);
        },
        maybeHideOverlay: function (e, el) {
            var ov = document.getElementById('overlay_glossaryPop');
            var targetNode = e.srcElement ? e.srcElement : e.explicitOriginalTarget;
            if (targetNode.nodeType == 3) targetNode = targetNode.parentNode;
            if (! (targetNode.tagName == 'dfn') && !YAHOO.util.Dom.isAncestor(el, e.explicitOriginalTarget) && !YAHOO.util.Dom.isAncestor(ov, e.explicitOriginalTarget)) {
                this.hideOverlay(e, el);
            }
        },
        enableGlossaryOff: function () {
            var obj = this;
            var pEl = YAHOO.util.Dom.get('glossary_widget');
            var aEl = YAHOO.util.Selector.query('a', pEl, true);
            var bEl = YAHOO.util.Dom.get('glossary_body');
            YAHOO.util.Event.removeListener(aEl, 'click');
            YAHOO.util.Event.removeListener(pEl, 'mouseover');
            YAHOO.util.Event.removeListener(pEl, 'mouseout');
            new YAHOO.util.Anim(bEl, {
                height: {
                    to: 0
                }
            },
            0.25, YAHOO.util.Easing.easeOut).animate();
            YAHOO.util.Dom.replaceClass(bEl, 'open', 'closed');
            YAHOO.util.Event.addListener(aEl, 'click', function (e) {
                GlossaryWidget.hideGlossary(e, obj);
                OmnitureHelper.setIPGStateEvent(false);
            },
            obj);
            aEl.innerHTML = "Turn off";
            YAHOO.util.Dom.addClass(pEl, 'on');
        },
        enableGlossaryOn: function () {
            var obj = this;
            var aEl = YAHOO.util.Selector.query('a', 'glossary_widget', true);
            YAHOO.util.Event.removeListener(aEl, 'click');
            YAHOO.util.Event.addListener(aEl, 'click', function (e) {
                GlossaryWidget.showGlossary(e, obj);
                OmnitureHelper.setIPGStateEvent(true);
            },
            obj);
            this.addWidgetMouseEvents();
            aEl.innerHTML = "Turn on";
            YAHOO.util.Dom.removeClass('glossary_widget', 'on');
        },
        addWidgetMouseEvents: function () {
            var pEl = YAHOO.util.Dom.get('glossary_widget');
            var bEl = YAHOO.util.Dom.get('glossary_body');
            YAHOO.util.Event.addListener(pEl, 'mouseover', function () {
                if (!YAHOO.util.Dom.hasClass(bEl), 'open') {
                    new YAHOO.util.Anim(bEl, {
                        height: {
                            to: YAHOO.util.Dom.getFirstChild(bEl).offsetHeight
                        }
                    },
                    0.25, YAHOO.util.Easing.easeIn).animate();
                    YAHOO.util.Dom.replaceClass(bEl, 'closed', 'open');
                }
            });
            YAHOO.util.Event.addListener(pEl, 'mouseout', function (e) {
                if (!YAHOO.util.Dom.isAncestor(pEl, e.relatedTarget)) {
                    new YAHOO.util.Anim(bEl, {
                        height: {
                            to: 0
                        }
                    },
                    0.25, YAHOO.util.Easing.easeOut).animate();
                    YAHOO.util.Dom.replaceClass(bEl, 'open', 'closed');
                }
            });
        },
        setTargetID: function (t) {
            targetID = t;
        },
        init: function () {
            var obj = this;
            YAHOO.util.Event.addListener(window, 'load', function () {
                if (document.getElementById('glossary_widget')) {
                    sUrl = GLOSSARY_TERM_URL;
                    if (YAHOO.util.Cookie.get('showInPageGlossary', Boolean)) {
                        GlossaryWidget.showGlossary(null, obj);
                    } else {
                        GlossaryWidget.enableGlossaryOn();
                    }
                }
            });
        }
    }
} ()).init();