var thumbnailZoomIcon = {
    check: function(){
        if(!thumbnailZoomIcon.overObject){
            // false, just hide everything and be-done.
            $('.thumbnailZoom').hide();
            thumbnailZoomIcon._prevOverObject = false;
            return;
        }
        else{
            thumbnailZoomIcon.overObject.find('.thumbnailZoom').show();
            thumbnailZoomIcon._prevOverObject = thumbnailZoomIcon.overObject;
            return;
        }
    },
    overObject: false,
    _prevOverObject: false
};

$(function(){
    $('.categoryImage').each(function(){
        el = $(this).parent().parent(); // Get the category image's parent container (either a div or a td).
        elImg = $(this); // The thumbnail.
        elIcon = el.find('.thumbnailZoom'); // The zoom icon.

        var top = elImg.offset().top + elImg.height() - elIcon.height();
        var left = elImg.offset().left + elImg.width() - elIcon.width();
        
        elIcon
        .css('top', top)
        .css('left', left)
        .mouseover(function(){
            thumbnailZoomIcon.overObject = $(this).parent().parent();
            thumbnailZoomIcon.check();
        })
        .mouseout(function(){
            thumbnailZoomIcon.overObject = false;
            thumbnailZoomIcon.check();
        })
    })
    .mouseover(function(){
        thumbnailZoomIcon.overObject = $(this).parent().parent();
        thumbnailZoomIcon.check();
    })
    .mouseout(function(){
        thumbnailZoomIcon.overObject = false;
        thumbnailZoomIcon.check();
    });
    
    $('.productImageThumbSelector').find('img').each(function(){
        //el = $(this).parent().parent(); // Get the category image's parent container (either a div or a td).
        elImg = $(this); // The thumbnail.
        elIcon = $('.thumbnailZoom'); // The zoom icon.

        //var top = elImg.offset().top + elImg.height() - elIcon.height();
        //var left = elImg.offset().left + elImg.width() - elIcon.width();
        if (elImg.attr('site') == 'rush' ) {
        	var top = elImg.height()-30;
        	var left = elImg.width()-10;
        } else {
        	var top = elImg.height();
        	var left = elImg.width();
        }

        elIcon
        .css('top', top)
        .css('left', left)
        .mouseover(function(){
            thumbnailZoomIcon.overObject = $(this).parent().parent();
            thumbnailZoomIcon.check();
        })
        .mouseout(function(){
            thumbnailZoomIcon.overObject = false;
            thumbnailZoomIcon.check();
        })
    })
    .mouseover(function(){
        thumbnailZoomIcon.overObject = $(this).parent().parent();
        thumbnailZoomIcon.check();
    })
    .mouseout(function(){
        thumbnailZoomIcon.overObject = false;
        thumbnailZoomIcon.check();
    });
});
