/**
 * Multi-photo Switch and Rollover
 */
jQuery(function($) {
    var switchImgTimer = null;
    $('.mImgs img').unbind().each(function() {
        var w = this.width, h = this.height, nw = this.naturalWidth, nh = this.naturalHeight;
        this.resize = function() {
            if (w >= h) {
                // Fat images
                if (w > nw) {
                    // No Zoom
                    $(this).css({
                        'width': nw + 'px',
                        'height': nh + 'px'
                    });
                }
            }
            else {
                // Tall images
                if (w > nh) {
                    // No Zoom
                    $(this).css({
                        'width': nw + 'px',
                        'height': nh + 'px'
                    });
                }
                else {
                    // Reset tall/fat size
                    if (h != 40) {
                        $(this).css({
                            'width': 'auto',
                            'height': '40px'
                        });
                    }
                }
            }
        };
        if (!nw || !nh) {
            // Get natural size in IE
            var oI = new Image(), that = this;
            oI.src = that.src + '?_=0';
            oI.onload = function() {
                nw = oI.width || w;
                nh = oI.height || h;
                that.resize();
                oI.onload = null;
                oI = null;
            };
        }
        else {
            this.resize();
        }
        
    });
    $('.mImgs td').unbind().hover(function() {
        var that = this;
        clearTimeout(switchImgTimer);
        switchImgTimer = setTimeout(function() {
            $('.mImgs td').removeClass('cur');
            $(that).addClass('cur');
            var src = $(that).find('img').attr('src');
            var nSrc = src.replace(/\/2f1/, '/2f0');
            $('#firstImg').attr('src', src).parent('a').attr('href', nSrc).parent('.bImg').next('a').attr('href', nSrc);
        }, 50);
    });
});

