// jQuery Povečalo Plugin
//
// Version 0.1
//
// Luka Uzel
// luka.uzel@gmail.com
//
// Terms of Use
//
// This software is licensed under a Creative Commons License and is copyrighted
// (C)2009 Luka Uzel.

(function($) {  
  
	$.povecalo = {  
		defaults: {
		  "grow": {"event":"mouseover", "duration":100, "callback":function(){}, "easing":"linear"},
		  "shrink": {"event":"mouseout", "duration":100, "callback":function(){}, "easing":"linear"},
		  "callback": function(){},
		  "scale": 30,
		  "zindex": 0,
		}  
	};
	
	var config =  {};
	var trigger;

	jQuery.fn.povecalo = function(config){
	$.povecalo.config = $.extend({}, $.povecalo.defaults, config);
	
	
	
	 	this.each(function(){
		
			var width = jQuery(this).width();
			var _width = Math.round(width * ( 1 + ($.povecalo.config.scale / 100) ));
			var x = Math.round((width * ($.povecalo.config.scale / 100))/4);
			
			var height = jQuery(this).height();
			var _height = Math.round(height * ( 1 + ($.povecalo.config.scale / 100) ));
			var y = Math.round((height * ($.povecalo.config.scale / 100))/4);
			
			var parent = jQuery(this).parent();
			var z = parent.css("z-index");
			
			jQuery(this).bind($.povecalo.config.grow.event,function(){
					
					if($.povecalo.config.zindex!=0) parent.css("z-index",$.povecalo.config.zindex);
					jQuery(this).animate(
						{"width": _width,"height": _height,"marginLeft": "-=" + x,"marginTop": "-=" + y},
						$.povecalo.config.grow.duration,
						$.povecalo.config.grow.callback
						);
				});
				
			jQuery(this).bind($.povecalo.config.shrink.event,function(){
				
					if($.povecalo.config.zindex!=0) parent.css("z-index",z);
					jQuery(this).animate(
						{"width": width,"height": height,"marginLeft":"0px","marginTop":"0px","z-index":z},
						$.povecalo.config.shrink.duration,
						$.povecalo.config.shrink.callback
						);
				});
		});

 
    return this;	
	};

	
})(jQuery); 
