;(function($) {

	var defaults = {
		scale:   50,
		speed:  "fast",
		bigPictureSrcPattern: []
	};

	$.fn.dynamichover = function(settings) {
		// Initialize the effect
		$.extend(this, defaults, settings);
		
		var self = this;
		var img = this.find("img");
		var largeImg = undefined
		
		var init = {
			"height":img.attr("height"),
			"width":img.attr("width"),
			"left":img.offset().left,
			"top":img.offset().top,
			"scx":(img.attr("width")*self.scale)/100,
			"scy":(img.attr("height")*self.scale)/100,						"bigWidth":0,						"bigHeight":0
		}
		
		if (self.bigPictureSrcPattern != [] ) {
			var src = img.attr("src").replace(self.bigPictureSrcPattern[0], self.bigPictureSrcPattern[1]);						var tempImg = new Image();						tempImg.src = src;						$(tempImg).load(function() { init["bigWidth"] = tempImg.width; init["bigHeight"] = tempImg.height; });						
		} else { var src = img.attr("src") }
		function removeLargeImage(){
			self.find(".animatedBigPic").remove()
		}
		function mouseOver(elem){
			elem.animate( { 
				width:init["bigWidth"],
				height:init["bigHeight"],
				left:init["left"]-((init["bigWidth"]/2)-(init["width"]/2)), 
				top:init["top"]-((init["bigHeight"]/2)-(init["height"]/2))
				
				},{queue:false, duration: self.speed, easeing: "easeout"})
		}
		
		function mouseOut(elem){
			elem.css("z-index",90)
			elem.animate( { 
				width:init["width"], 
				height:init["height"], 
				left:init["left"], 
				top:init["top"]
				
				},{queue:false, duration: self.speed, easeing: "easein", complete:removeLargeImage})
		}
		
		
		img.mouseover(function(){
			
			img.after('<img class="animatedBigPic" src="'+src+'" width="'+init["width"]+'"	height="'+init["height"]+'" alt=""/>');
			largeImg = self.find(".animatedBigPic")
			largeImg.css({"position":"absolute", "z-index":100,	"left":init["left"], "top":init["top"]})
			largeImg.hover( function(){ mouseOver(largeImg)}, function(){ mouseOut(largeImg)})
		})
		
		return this;
	};
})(jQuery);
