//hoverZoom plugin
(function($){
    $.fn.hoverZoom = function(options){
        var defaults = {
            percent: 10
        };
        options = $.extend({}, defaults, options);
		
        return this.each(function(){
            $(this)
            .setHoverZoomData(options.percent)
            .hover(
                function(){
                    $(this).animate({
                        top: $(this).data('position').topTo,
                        left: $(this).data('position').leftTo,
                        width: $(this).data('position').widthTo,
                        height: $(this).data('position').heightTo
                    });
                },
                function(){
                    $(this).animate({
                        top: $(this).data('position').topFrom,
                        left: $(this).data('position').leftFrom,
                        width: $(this).data('position').widthFrom,
                        height: $(this).data('position').heightFrom
                    });
                });
        });
    };
	
    $.fn.setHoverZoomData = function(percent){
		
        var options = $.extend({
            percent: percent
        });
		
        return this.each(function(){
            $(this)
            .data('position', {
                topFrom : $(this).position().top,
                leftFrom : $(this).position().left,
                widthFrom : $(this).width(),
                heightFrom : $(this).height(),
				
                topTo : $(this).position().top - ($(this).width() / 100 * options.percent)/2,
                leftTo : $(this).position().left - ($(this).height() / 100 * options.percent)/2,
                widthTo : $(this).width() + ($(this).width() / 100 * options.percent),
                heightTo : $(this).height() + ($(this).height() / 100 * options.percent)
            })
        });
    };
	
})(jQuery);
