(function($) {
	$.fn.BrandZoom = function(options) {
		var properties = $.extend({}, $.fn.BrandZoom.defaults, options);

		function z_hover() {
			//Set all other li's to a lower z-index
			$('ul.people li').css({'z-index':'1'});

			//Bump up this z-index
			$(this).css({'z-index' : '98'});

			//Define some vars for use later
			var o_top = Math.floor($(this).attr('original_top')-(properties.crop_size/2));
			var o_left = Math.floor($(this).attr('original_left')-(properties.crop_size/2));

			$(this).removeClass('noShadow').addClass('hoverShadow').stop().animate({															  
					top:  o_top+properties.unit,
					left: o_left+properties.unit,
					width: Math.floor($(this).attr('original_width'))+properties.unit,
					height: Math.floor($(this).attr('original_height'))+properties.unit,
				}, properties.speed_hover).find('img.first').stop().animate({
					marginTop:'0px',
					marginLeft:'0px'	
			},properties.speed_hover);
	}

		function z_unhover() {
			$(this).css({'z-index' : '1'});
			$(this).removeClass('hoverShadow').addClass('noShadow').stop().animate({
					top: Math.floor($(this).attr('original_top')) + properties.unit,
					left: Math.floor($(this).attr('original_left')) + properties.unit,
					width: $(this).attr('original_width')-parseInt(properties.crop_size) + properties.unit,
					height: $(this).attr('original_height')-parseInt(properties.crop_size) + properties.unit
				}, properties.speed_unhover).find('img.first').stop().animate({
					marginTop:0-Math.floor(properties.crop_size/2)+'px',
					marginLeft:0-Math.floor(properties.crop_size/2)+'px'
			},properties.speed_unhover);

		}
		
		function z_click(e) {
			e.preventDefault();
			if($(this).find('img.last').length) {
				$(this).find('img.first').animate({'margin-top': '-172px'},(properties.speed_hover*3));
			}
		}
		
        return this.each(function(index) {
        	zoomer = $(this);
        	//zoomer.attr('original_width', $(this).find('img.first').width());
        	//zoomer.attr('original_height', $(this).find('img.first').height());
			zoomer.attr('original_width', 191);
			zoomer.attr('original_height', 171);
			zoomer.attr('original_top', Math.floor($(this).offset().top));
			zoomer.attr('original_left', Math.floor($(this).offset().left));
        	zoomer.css({'position' : 'absolute', 'top':Math.floor(zoomer.attr('original_top'))+'px', 'left':Math.floor(zoomer.attr('original_left'))+'px'});
			if(!$.browser.msie) {
        		zoomer.hover(z_hover, z_unhover);
			} else {
				$(zoomer).mouseenter(z_hover).mouseleave(z_unhover);
			}
			zoomer.click(z_click);
        });

    }; 
    
	$.fn.BrandZoom.defaults = {
		crop_size: 20,
		speed_hover: 100,
		speed_unhover: 100,
		unit: 'px',
	};
    
})(jQuery);
