FinderPanels = function(){
    var currentPanel;
    var newPanelId;
    var STATIC_PANEL = 'lensTop';    // ID of static default panel, which we won't animate
    var HELP_PANEL = 'lensHelpContainer';    // ID of help panel, which sits on top of the others thus they won't hide
    var FILTER_PANEL = 'lens_filter';        // ID of filter tools panel
    var topPosition = null;          // Default "top" position we'll be animating to
    var isAnimating = false;         // Are we currently animating in a panel? 
    var isFiltered = false;          // Did we go to the filter page yet?
    //var toggledState = false;        // Have we manually flipped LensFilter's saveState flag?
    
    var isIE7 = jQuery.browser.msie && jQuery.browser.version < 8;
    var isIE8 = jQuery.browser.msie && jQuery.browser.version < 9;    
    
    return{
        /***
         * Handles switching visible panels in the tool, setting heights, etc.
         * @param {String} pId ID of panel we're showing.
         */
        panelSwitch : function(pId){
            // If we're already switching panels, you're going to have to wait...
            if(! isAnimating){
                var o = this;
                newPanelId = pId.substr(1);    // Remove leading #
                
                // Hide any quickview flyouts.
                LensFilter.hideFlyouts();
                
                // We pass showPanel as a function as we'll use it in an animation callback
                this.hidePanel(currentPanel, function(){
                    isAnimating = true;
                    o.showPanel(jQuery(pId));                                                      
                });
            }
        },
        /***
         * IE7 and IE 8 cannot properly run the animation of the filter screen into place: it has a tendency to drop most/all frames.
         * This is a basic animation function that will animate and ease that panel into place.
         * @param {jQueryObject} p Panel we'd like to animate.
         */
        animateIE : function(p){
            var top = parseInt(p.css('top'));
            var distance = 35;    // Optimal number of steps to move per itearation.
            var o = this;
            
            // Animate using our set distance...
            if(top - distance > 0){
                p.css('top',top - distance);
                setTimeout(function(){
                    o.animateIE(p);    
                },15);                        
            }   
            // ... until we're close when we start easing...
            else if(top - 5 > 0){
                p.css('top', top - 5);
                setTimeout(function(){
                    o.animateIE(p);    
                },15);                  
            }
            // ... and slowly finish easing into place.
            else if(top - 1 >= 0){
                p.css('top', top - 1);
                setTimeout(function(){
                    o.animateIE(p);    
                },15);                
            }
            else{
                // If we are coming from the static panel/inital screen, and have already been to 
                // the filter, we must re-run the appropriate filters to reload our filtered lens list
                if(LensFilter.isFiltered() && currentPanel.attr('id') == STATIC_PANEL){
                    LensFilter.filterLenses();    
                }

                isAnimating = false;
                newPanelId = '';
                currentPanel = p;                
            }     
        },
        /***
         * Animates in panel p
         * @param {jQueryObject} p Panel we'd like to animate.
         */
        showPanel : function(p){
            var id = p.attr('id');
            
            if(id == FILTER_PANEL){
                LensFilter.hideTeleconverters();
                /* Removed - close button on filter tools stops state save functionality                
                if(toggledState){
                    LensFilter.setSave(true);
                }                
                */            
            }

            if(id !== STATIC_PANEL && p !== currentPanel){
                // IE7 cannot properly animate in the filter panel without dropping frames. Thus, we call our own
                // animation function.
                if((isIE7 || isIE8) && id == FILTER_PANEL){
                    this.animateIE(p);    
                }
                else{
                    p.animate({
                        top : 0
                    },450,'easeInOutCirc',function(){
                        // If we are coming from the static panel/inital screen, and have already been to 
                        // the filter, we must re-run the appropriate filters to reload our filtered lens list
                        if(LensFilter.isFiltered() && currentPanel.attr('id') == STATIC_PANEL){
                            LensFilter.filterLenses();    
                        }
    
                        isAnimating = false;
                        newPanelId = '';
                        currentPanel = p;
                    });                    
                }
            } 
            else if(id === STATIC_PANEL && p !== currentPanel){
                currentPanel = p;

                isAnimating = false;
                
                // Show all lenses and remove our cookie if we're out of the tool.
                setTimeout(function(){
                    /* Removed - close button on filter tools stops state save functionality
                    if(LensFilter.isFiltered()){
                        toggledState = true;                            
                    }
                    LensFilter.setSave(false).clearState().showAll();
                    */
                    LensFilter.showAll();
                },250);
            }
            else{
                isAnimating = false;
            }   
        },
        /***
         * Animates out panel p
         * @param {jQueryObject} p Panel we'd like to animate.
         * @param {Function} callback Callback we'll execute once function completes.
         */
        hidePanel : function(p,callback){
            if(topPosition === null){
                topPosition = jQuery('#top_container').height();
                // Set the "top" to help jQuery's animation a bit...
                jQuery('#lens_filter, #lensHelpContainer').css('top',topPosition);
            }
            
            var pId = p.attr('id');
            if(pId !== STATIC_PANEL && newPanelId !== HELP_PANEL){
                var duration = isIE7 ? 750 : 350;                
                
                p.animate({
                    top : topPosition    
                },duration,'easeInOutQuint',function(){
                    callback();
                });
            } 
            else{
                callback();
            }      
        },
        /***
         * Returns the currently selected panel.
         */
        getCurrentPanel : function(){
            return currentPanel;
        },
        init : function(){
            // Set appropriate current panel
            currentPanel = jQuery('#lensTop');
        }         
    }    
}();

jQuery(document).ready(function() {
    FinderPanels.init();
        
    //Table ToolTips
    jQuery("#infoTable thead th").each(function(){
        var el = jQuery(this);
        var to;
        if(el.attr('data-tooltip')){
            el.bind('mouseenter',function(){
                el.addClass('hover')
                    .find('span')
                    .addClass('hover');
            })
            .bind('mouseleave',function(e){
                el.removeClass('hover')
                    .find('span')
                    .removeClass('hover');   

                to = setTimeout(function(){
                        jQuery('#' + el.attr('data-tooltip')).removeClass('shown').hide();    
                    },1000);                                 
            })
            .tooltip({ tip : '#' + el.attr('data-tooltip'), events : { def : 'click,dblclick', tooltip : 'mouseover' },
                onShow : function(){ clearTimeout(to); } })
            .bind('click dblclick',function(e){
                var tip = jQuery('#' + el.attr('data-tooltip'));
                
                if(tip.hasClass('shown')){
                    tip.removeClass('shown').hide();                        
                } 
                else{    
                    tip.addClass('shown');
                }
            })
        }    
    });

    jQuery("img.lensFindBtn").click(function(){
        FinderPanels.panelSwitch('#lens_filter');
    });
        
    jQuery("img.closeLensFinder").click(function() {
        FinderPanels.panelSwitch('#lensTop');           
    });
    
    jQuery("#lensCloseBtn img").click(function() {
        if(LensFilter.lastWindow && LensFilter.lastWindow == 'home') {
            FinderPanels.panelSwitch('#lensTop');
        }
        else{
            FinderPanels.panelSwitch('#lens_filter');
        }
    });
    
    //Help "quick views"
    var rTips = jQuery('.reccoTip')
                    .find('a')
                    .bind('click', function(e){
                        e.preventDefault();
                        var h = this.getAttribute('href');
                        
                        // Remove leading '#' from URL. The IEs like to make this a full path (argh), thus we 
                        // can't easily grab the hash value and have to rely on substrings.                                               
                        var paneId = h.substr(h.lastIndexOf('#') + 1);    
                        var newPane = jQuery('#' + paneId);   
                        var panes = jQuery('#lensHelpContainer div.panes > div');       

                        jQuery('#helpTabs').tabs().click(panes.index(newPane));
                        
                        LensFilter.lastWindow = 'filter';
                        
                        jQuery(this).parents('.reccoTip').hide();
                        setTimeout(function(){
                            FinderPanels.panelSwitch('#lensHelpContainer');                            
                        },100);
                    })
                    .end();

    // Find the width. Used to calculate whether or not we're displaying tips to the 
    // left or right.                
    var bd = jQuery('body');        
    if(! bd.attr('data-width')){
        bd.attr('data-width',bd.width());
        bd.attr('data-height'),bd.height();
    }                    
    
    jQuery('h3.toolTipBtn span,q').bind('click', function(e){
            e.preventDefault(e);
            var el = jQuery(this);
            var offset = el.offset();
                        
            var tip = rTips.fadeOut('fast')
                    .filter('.' + el.parent().attr('data-tooltip'))

            if(el.hasClass('shown')){
                rTips.fadeOut('fast')
                    .filter('.' + el.parent().attr('data-tooltip'))   
                    .fadeIn();
            }
            else{
                var newLeft = offset.left + 20; 
                var newTop = offset.top;

                tip.css({
                        visibility : 'hidden',
                        display : 'block'
                    });
                    
                if(offset.left > parseInt(bd.attr('data-width'),10) / 2){
                    newLeft = offset.left - tip.width() - 10;
                }
                
                if(offset.top + tip.height() > parseInt(bd.attr('data-height'),10) / 2){
                    newTop = offset.top - tip.height();
                }
                
                tip.css('visibility', 'visible')
                    .hide()
                    .css({
                        top : newTop,
                        left : newLeft
                    })
                    .fadeIn()
                    .addClass('shown');
            }
        });    
    
    jQuery('#intro_help_link')
        .bind('click', function(e){
            e.preventDefault(e);
            jQuery('#helpTabs').tabs().click(0);
            LensFilter.lastWindow = 'home';  
            setTimeout(function(){
                FinderPanels.panelSwitch('#lensHelpContainer');                    
            },100);
        });
        
    jQuery("#help_choosing")
        .click(function(e) {
            e.preventDefault();
            rTips.fadeOut('fast');
            jQuery('#helpTabs').tabs().click(0);
            LensFilter.lastWindow = 'filter';
            setTimeout(function(){
                FinderPanels.panelSwitch('#lensHelpContainer');                    
            },100);
        });
        
    jQuery('#help_decide')
        .bind('click', function(e){
            e.preventDefault();
            rTips.fadeOut('fast');
            jQuery('#helpTabs').tabs().click(3); // Format Options -> tab #4
            LensFilter.lastWindow = 'filter';  
            setTimeout(function(){
                FinderPanels.panelSwitch('#lensHelpContainer');                    
            },100);
        });  

    jQuery("img.close").click(function() { 
        jQuery(".reccoTip").fadeOut('hide'); 
    });

    // setup ul.tabs to work as tabs for each div directly under div.panes 
    jQuery("#helpTabs").tabs("div.panes > div"); 
    
});

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c*(t/=d)*t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c*(t/=d)*t*t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c*((t=t/d-1)*t*t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t + b;
        return c/2*((t-=2)*t*t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c*(t/=d)*t*t*t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
        return -c/2 * ((t-=2)*t*t*t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c*(t/=d)*t*t*t*t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c*((t=t/d-1)*t*t*t*t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
        return c/2*((t-=2)*t*t*t*t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t/d * (Math.PI/2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t==0) return b;
        if (t==d) return b+c;
        if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
        return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
        return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
        return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*(t/=d)*t*((s+1)*t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158; 
        if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t/=d) < (1/2.75)) {
            return c*(7.5625*t*t) + b;
        } else if (t < (2/2.75)) {
            return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
        } else if (t < (2.5/2.75)) {
            return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
        } else {
            return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
    }
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */

 /***
  * Patching in lightboxing via awesomebox
  */
 /**
 * @author Adam McIntyre
 * Builds the Media Bar / Carousel / Lightbox combo on the product 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 
*/
var aClient = {};
aClient.photos = [];
aClient.allAssets = {};
aClient.groups = {};
aClient.noDisplayaltTerms = {'Enlarge Image' : true};  // Array of alt terms to ignore

/* 
 *  aClient.addItem()
 *    Given an item, determines if it should be displayed in the lightbox and 
 *    adds it to appropriate array.
 *  @param lbItem Item to test.
 */
aClient.addItem = function(lbItem) {
    var aTypes = {'jpg':true, 'gif':true, 'png':true, 'bmp':true, 'flv':true, 'mp3':true, 'wav':true}; // types of images to place in Awesome Box

    if(lbItem.href.substr(lbItem.href.lastIndexOf('.')+1) in aTypes) {
        this.photos.push(lbItem);
        this.addToGroup(lbItem);
        YAHOO.awesomebox.setClickAction(lbItem,YAHOO.awesomebox);        
    }
};

/***
 * Adds an item to a given photo "group," as specified in its "rel" attribute.
 * If that group exists, the item is added. Otherwise, the group is created than added.
 * @param {Object} lbItem
 */
aClient.addToGroup = function(lbItem){
    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);
    grp[lbItem.href] = grp.items.length - 1;     // hold array index of this item in a map for quick lookup      
}

/***
 * Returns a group with the given name, or an empty array if it doesn't exist.
 * @param {String} groupName Name of group we're looking for.
 */
aClient.getGroup = function(groupName){
    if(this.groups[groupName]){
        return this.groups[groupName];
    }
    return [];
}

/***
 * Determines whether a given value is present in a group.
 * @param {String} groupName Name of group we would like to check.
 * @param {String} value Value we'd like to test for presence in group.
 */
aClient.isInGroup = function(groupName,value){
    if(value in this.getGroup(groupName)){
        return this.groups[groupName][value];    
    }
    return null;
}

/* 
 *  aClient.pageWidth() and aClient.pageHeight()
 *    Returns the width and height of the content in the document.
 */
aClient.pageWidth = function() {
    var xScroll;
    if(window.innerHeight && window.scrollMaxY) {   
        xScroll = document.body.scrollWidth;
    } else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        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){ // all but Explorer Mac
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
    }
    if(yScroll <= $D.getViewportHeight()) {
        pageHeight = $D.getViewportHeight();
    } else { 
        pageHeight = yScroll;
    }
    return pageHeight;
};

/* 
 *  aClient.xScroll(), aClient.yScroll()
 *    Returns the position of the X and Y scrollbars.
 */
aClient.xScroll = function() {
    var xScroll = window.scrollX || document.documentElement.scrollLeft;
    return xScroll;
};  
aClient.yScroll = function() {
    var yScroll = window.scrollY || document.documentElement.scrollTop;
    return yScroll;
};

/* 
    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 
*/

var aLoadImgSrc = '/static/js/awesome-box-v2/images/aBox-loading.gif'; // where is the loading image? (recommend absolute)
var isSafari = false;
if(YAHOO.env.ua.webkit > 0) {
    isSafari = YAHOO.env.ua.webkit < 525.19;
}

/*
 *  ***************************************
 *  EDIT BEYOND THIS POINT AT YOUR OWN RISK
 *  ***************************************
 */

// Moved the aClient declaration out to CarouselWidget.js -- A

/*
 *  Helper Variables
 */
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;

/*
 *  AnimMgr
 *    Sets the default frames per second higher so Safari will display animations
 *    at the correct speed. Degrades for slower browsers.
 */
YAHOO.util.AnimMgr.fps = 500;

YAHOO.widget.aEffect = function(el) { this.oEl = YAHOO.util.Dom.get(el); };

/*
 *  YAHOO.widget.aEffect.aShowLoad()
 *    Animation widget for transition period on Awesome Box initialize or between images.
 */
YAHOO.widget.aEffect.prototype.aShowLoad = function() {
    var showLoad = new $A('aLoadImg', {opacity: {to: 1}}, 0.2);
    showLoad.onStart.subscribe(function() {
        $D.setStyle('aLoadImg', 'display', 'block');
        $D.setXY('aLoadImg', [
            ($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');
            });
            hideMeta.animate();
        }
    });
    showLoad.animate();
};

/*
 *  YAHOO.widget.aEffect.aShowOverlay
 *    Fades in #aOverlay and #aBox.
 *    Initializes YAHOO.widget.aEffect.aShowLoad()
 */
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.aResizeBox()
 *    Initialized after new image is completed loading. Resizes and moves #aBox, times out
 *    and displays #aBoxMeta information
 */
YAHOO.widget.aEffect.prototype.aResizeBox = function(aPreload) {
    // Since we need to open Safari in a new window, we must make sure these
    // display properties are set.
    if(isSafari){
        $D.setStyle('aDiv','visibility','hidden');
        $D.setStyle('aDiv','display','none');
        $D.setStyle('aDiv', 'opacity', '0');           
    }
    
    var metaHeight = 40;    // Standard height for "meta" information at bottom of lightbox.
    
    if(document.getElementById('container_colors')){
        ColorVariantManager.setSelectedEl(this.oEl);
        if($D.hasClass(this.oEl, 'enlargeImg')) {
            $D.addClass('aBoxMeta', 'variant');
            metaHeight = 62;
            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 = nikonLabel.selectColor+': <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 moveBox = new $M('aBox', {
        width: {to: (imgScale[0]+20)},
        height: {to: (imgScale[1]+70)},
        points: {to: 
            [
                ($D.getViewportWidth()/2)-(imgScale[0]/2)+aClient.xScroll()-10,
                ($D.getViewportHeight()/2)-(imgScale[1]/2)+aClient.yScroll()-60
            ]
        }
    }, 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() {
        $D.setStyle('aBox', 'height', imgScale[1]+130+'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');
    
        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();
            $D.setStyle('aCloseButton','visibility','visible');
        });
        fadeImg.animate();
    });
    if($D.hasClass('aBoxMeta', 'aOpen')) {
        setTimeout(function() {
            $('aImg').setAttribute('src', aPreload.src); 
            setTimeout(function(){
                moveBox.animate();
            },10);
        }, 300);
    } else {
        $('aImg').setAttribute('src', aPreload.src);
        setTimeout(function(){ moveBox.animate(); }, 10);
    }
};

/*
 *  YAHOO.widget.aEffect.aResizeBoxEl()
 *    Initialized after new image is completed loading. Resizes a box for a non-image element.
 */
YAHOO.widget.aEffect.prototype.aResizeBoxEl = function(aPreload,anEl) {
    var moveBox = new $M('aBox', {
        width: {to: (aPreload.width+30)},
        height: {to: (aPreload.height+85)},
        points: {to: [
            ($D.getViewportWidth()/2)-(aPreload.width/2)+aClient.xScroll()-10,
            ($D.getViewportHeight()/2)-(aPreload.height/2)+aClient.yScroll()-10
            ]
        }
    }, 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','width', prWidth + 30 + 'px');
        $D.setStyle('aDiv','height', prHeight + 30 + 'px');
        $D.setStyle('aDiv','opacity','1');
        $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: 40}}, 0.2);

        showMeta.onComplete.subscribe(function(){
            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('closeButton', '/static/images/'+nikonLabel.locale+'/buttons/btn_flash_close_on.png');
                fo.addVariable('closeButtonHover', '/static/images/'+nikonLabel.locale+'/buttons/btn_flash_close_off.png');
                fo.addVariable('volLabel', '/static/images/'+nikonLabel.locale+'/icons/icon_flash_sound.png');
                fo.addVariable('close', 'YAHOO.awesomebox.close');
                fo.addVariable('showClose',true);
                fo.write('aDiv');
            },10);
        });
        showMeta.animate();    
    });
    moveBox.animate();
};

/*
 *  YAHOO.widget.aEffect.aClose
 *    Closes #aBox and #aOverlay. Invoked via pressing 'x', clicking the 'X' image or #aOverlay
 */
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.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.setStyle('aBox', 'display', 'none');
            $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('aDiv', 'width', '0');
            $D.setStyle('aDiv', 'height', '0'); 
            $D.setStyle('aOverlay', 'display', 'none');
            $D.setStyle('aOverlay', 'height', '0px');
            $D.setStyle('aLoadImg', 'display', 'none');
            $D.setStyle('aCloseButton','visibility','hidden');            
        });
        hideOverlay.onComplete.subscribe(function(){
            $('aDiv').innerHTML = '';                           
        });
        hideOverlay.animate();
    });
    hideMeta.animate();
    fadeBox.animate();
    $E.removeListener('aNextButton', 'click');
    $E.removeListener('aPrevButton', 'click');
    $E.removeListener(document, 'keypress');
};

/*
 * YAHOO.widget.aEffect.aAwesome
 *   This is awesome. Pay no attention to it.
 */
YAHOO.widget.aEffect.prototype.aAwesome = function() {
return true;
};

/*
 *  YAHOO.awesomebox()
 *    Non-animating functions, initialized on window load completion.
 */
YAHOO.awesomebox = function() {   
    return {
        /*
         *  init()
         *    Creates the markup, checks for direct image link, adds event listeners.
         */
        init : function() {
            if(!document.getElementsByTagName){ return; }
            
            /*
             *  Awesome Box Markup
             *  
                <div id="aOverlay" title="Click to Close"></div>
                <div id="aBox">
                    <div id="aImgHolder">
                        <img id="aImg" />
                        <div id="aDiv" />
                    </div>
                    <div id="aBoxMeta">
                        <a class="aButton" href="#next" id="aNextButton"></a>
                        <a class="aButton" href="#prev" id="aPrevButton"></a>
                        <a class="aButton" href="#close" id="aCloseButton"></a>
                        <h1 id="aInfoTitle"></h1>
                        <p id="aCount"></p>
                        <p id="aInfo"></p>
                    </div>
                </div>
                <img src="images/aBox-loading.gif" id="aLoadImg" />
             */
            
            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');
            if(typeof nikonLabel === 'undefined'){
                $(aBox).className = 'en_US';        
            }
            else{
                $(aBox).className = nikonLabel.cssClass;
            }
            aBody.appendChild(aBox);
            $D.setStyle('aBox', 'opacity', '0');
            $D.setXY('aBox', [($D.getViewportWidth()/2)-21, ($D.getViewportHeight()/2)-21])
            $D.setStyle('aBox', 'display', 'none');

            var aCloseButton = document.createElement('a');
            $(aCloseButton).setAttribute('id', 'aCloseButton');
            $(aCloseButton).setAttribute('href', 'javascript:void(0);');
            aBox.appendChild(aCloseButton);
            $D.addClass(aCloseButton, 'aButton');

            var aInfoTitle = document.createElement('h5');
            $(aInfoTitle).setAttribute('id', 'aInfoTitle');
            aBox.appendChild(aInfoTitle);
            
            var aImgHolder = document.createElement('div');
            $(aImgHolder).setAttribute('id', 'aImgHolder');
            aBox.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');            
            
            var aBoxMeta = document.createElement('div');
            $(aBoxMeta).setAttribute('id', 'aBoxMeta');
            aBox.appendChild(aBoxMeta);
            
            var aNextButton = document.createElement('a');
            $(aNextButton).setAttribute('id', 'aNextButton');
            aBoxMeta.appendChild(aNextButton);
            $(aNextButton).setAttribute('href', '#next');
            $D.addClass(aNextButton, 'aButton');

            var aPrevButton = document.createElement('a');
            $(aPrevButton).setAttribute('id', 'aPrevButton');
            aBoxMeta.appendChild(aPrevButton);
            $(aPrevButton).setAttribute('href', '#prev');
            $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 aInfo = document.createElement('p');
            $(aInfo).setAttribute('id', 'aInfo');
            aBoxMeta.appendChild(aInfo);
            
            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');

            $E.on(aOverlay, 'click', this.close);
            $E.on(aCloseButton, 'click', this.close);
        },
        
        /***
         * Sets the 'onclick' handler for an object
         * @param {Object} o Object whose handler we're setting
         */
        setClickAction : function(o,obj){
            var fileType = o.href.substr(o.href.lastIndexOf('.')+1).toLowerCase();
            
            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{    // img
                $E.addListener(o,'click',function(e){
                    YAHOO.util.Event.preventDefault(e);
                    obj.loadImg(e,this);
                });
            }
        },
        
        loadSafari : function(e, newSwf){
            $E.stopEvent(e);
            var sz;
            
            if(e.target.getAttribute('size'))
                sz = e.target.getAttribute('size'); // moz, safari, etc.
            else{   
                var m = e.target.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');
       
            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])+55));
        },
        loadSwf : function(e, newSwf){
            var sz;
            
            if(e.srcElement){
                if(e.srcElement.getAttribute('size')) 
                    sz = e.srcElement.getAttribute('size');
                else{
                    var m = e.srcElement.className.match(/\bsize_(\d\d\d\d?x\d\d\d\d?)\b/);
                    if(m) sz = m[1];
                    else sz = null;
                }  
            } 
            else{
                if(e.target.getAttribute('size')) 
                    sz = e.target.getAttribute('size'); // moz, safari, etc.
                else{
                    var m = e.target.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';

            $E.stopEvent(e);
            $E.removeListener(document, 'keypress');

            aPreload = new Image();
            aPreload.width = sz.split('x')[0];
            aPreload.height = sz.split('x')[1];

            if(newSwf) { var that = newSwf;
            } else { var that = this; }

            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 aInfoTitle = '';
            var aInfo = '';

            if(that.getAttribute('title') != null) {
                var aInfoTitle = that.getAttribute('title');
            }

            if($D.hasClass('aBoxMeta', 'aOpen')) {
                setTimeout(function() {
                    $('aInfoTitle').innerHTML = aInfoTitle;
                    $('aInfo').innerHTML = aInfo;
                }, 250);
            } else {
                $('aInfoTitle').innerHTML = aInfoTitle;
                $('aInfo').innerHTML = aInfo;
            }

            $E.addListener(document, 'keypress', function(e) {
                $E.stopEvent(e);
                switch($E.getCharCode(e)) {
                    case (120) : YAHOO.awesomebox.close();
                    break;
                    case (97) : YAHOO.awesomebox.awesome();
                    break;
                }
            });            
        },
        /*
         *  loadImg()
         *    Gets information for new image and invokes appropriate actions.
         */
        loadImg : function(e, newImg) {
            var fadeOverlayIn = new YAHOO.widget.aEffect();
            fadeOverlayIn.aShowOverlay();
                        
            if(newImg) { var that = newImg;
            } else { var that = this; }
            
            $E.stopEvent(e);
            $E.removeListener(document, 'keypress');

            aPreload = new Image();
            aPreload.onload = function() {
                setTimeout(function(){
                    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');
                    }
                    var aInfoTitle = '';
                    var aInfo = '';

                    if(that.getAttribute('title') != null) {
                        var aInfoTitle = that.getAttribute('title');
                    }
                    if(
                        that.getElementsByTagName('img')[0] &&
                        that.getElementsByTagName('img')[0].getAttribute('title') != null
                    ) {
                        var aInfoTitle = that.getElementsByTagName('img')[0].getAttribute('title');
                    }
                    if(
                        that.getElementsByTagName('img')[0] &&
                        that.getElementsByTagName('img')[0].getAttribute('alt') != null &&
                        !(that.getElementsByTagName('img')[0].getAttribute('alt') in aClient.noDisplayaltTerms)
                    ) {
                        var aInfo = that.getElementsByTagName('img')[0].getAttribute('alt');
                    } 

                    if($D.hasClass('aBoxMeta', 'aOpen')) {
                        setTimeout(function() {
                            $('aInfoTitle').innerHTML = aInfoTitle;
                            $('aInfo').innerHTML = aInfo;
                        }, 250);
                    } else {
                        $('aInfoTitle').innerHTML = aInfoTitle;
                        $('aInfo').innerHTML = aInfo;
                    }

                    if(that.getAttribute('rel')) {
                        YAHOO.awesomebox.loadNeighbors(that);
                    }
                    $E.addListener(document, 'keypress', function(e) {
                        $E.stopEvent(e);
                        switch($E.getCharCode(e)) {
                            case (120) : YAHOO.awesomebox.close();
                            break;
                            case (97) : YAHOO.awesomebox.awesome();
                            break;
                        }
                    });
                },10);
            };
            aPreload.src = that.getAttribute('href');                
        },        
        /***
         * Shows el's content in a plain, old overlay.
         * @param {HTMLElement|String} el Element whose content we'd like to overlay.
         */
        showOverlay : function(el){
            el = YAHOO.util.Dom.get(el);    // Ensure el is an HTMLElement

            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();    
            }

            //overlay.style.visibility = "hidden";
            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{
                // Determine if overlayed content has a width > 357px default. If so, increase overlay size.
                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)-20, ($D.getViewportHeight()/2)-20])                        
            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);
        },
        /***
         * Animation for showing the overlay.
         * @param {HTMLElement} overlay Overlay HTMLElement.
         */
        _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();   
        },  
        /***
         * "Resets" overlay, setting its content back to a "template"-able state and its
         * display to "none."
         */ 
        _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}";            
        },
        /***
         * Hides that plain, old overlay.
         */
        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(){
                // Reset all content.
                obj._resetOverlay();                
            });            

            anim.animate();
        },        
        /*
         *  scaleImage()
         * Returns proportional values for height and width of image, scaled if necessary.
         */
        scaleImage : function(aImage) {
            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+100 > ($D.getViewportHeight()-20)) {
                    sHeight = $D.getViewportHeight()-120;
                    sWidth = aImage.width * (sHeight / aImage.height);
                }
            } else if(aImage.height+100 > $D.getViewportHeight()) {
                sWidth = aImage.width * (($D.getViewportHeight()-120) / aImage.height);
                sHeight = $D.getViewportHeight()-120;
                if(sWidth > ($D.getViewportWidth()-20)) {
                    sWidth = aImage.width * (sHeight / aImage.height);
                    sHeight = aImage.height * (sWidth / aImage.width);
                }
            }
            var scaleAtts = new Array(Math.floor(sWidth), Math.floor(sHeight));
            return scaleAtts;
        },
        
        /*
         *  close()
         *    Calls YAHOO.widget.aEffect.aClose() and resets the #filename to #close.
         *    Not the most elegant solution.
         */
        close : function() {
            var aClose = new YAHOO.widget.aEffect();
            aClose.aClose();
        },
        
        awesome : function() {
            var aAwesome = new YAHOO.widget.aEffect();
            aAwesome.aAwesome();
        }
    }
}();

/*
 *  Start up the processes on window load.
 */
jQuery(window).bind('load',function(){
    YAHOO.awesomebox.init();     
    jQuery('a.lightbox').each(function(){
        YAHOO.awesomebox.setClickAction(this, YAHOO.awesomebox );    
    });
}) 

/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",_7);this.setAttribute("doExpressInstall",false);var _d=(_9)?_9:window.location;this.setAttribute("xiRedirectUrl",_d);this.setAttribute("redirectUrl","");if(_a){this.setAttribute("redirectUrl",_a);}};deconcept.SWFObject.prototype={setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};deconcept.PlayerVersion=function(_27){this.major=_27[0]!=null?parseInt(_27[0]):0;this.minor=_27[1]!=null?parseInt(_27[1]):0;this.rev=_27[2]!=null?parseInt(_27[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_29){var q=document.location.search||document.location.hash;if(q){var _2b=q.substring(1).split("&");for(var i=0;i<_2b.length;i++){if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return"";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};if(typeof window.onunload=="function"){var _30=window.onunload;window.onunload=function(){deconcept.SWFObjectUtil.cleanupSWFs();_30();};}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};if(typeof window.onbeforeunload=="function"){var oldBeforeUnload=window.onbeforeunload;window.onbeforeunload=function(){deconcept.SWFObjectUtil.prepUnload();oldBeforeUnload();};}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){Array.prototype.push=function(_31){this[this.length]=_31;return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;