// place any jQuery/helper plugins in here, instead of separate, slower script files.
// Resize plugin 
// 0.5
(function($){
    $.fn.resizeImage = function(options) {
            return this.each(function() {
                var o = options;	
				$(this).parent().css({overflow:"hidden"});
				$(this).css({position:'relative'})
				this.defaults={
					minWidth:0,
					minHeight:0
				}
				this.original={width:$(this).width(),height:$(this).height()}
			
				$.extend(this,{
					init:function(){
						$(this).css({width:$(this).width(),height:$(this).height()});
						
					},
					scaleX:function(value,auto){
						if(value) $(this).width(this.original.width*value);	
						if(auto)$(this).css({height:'auto'})				
						return $(this).width()/this.original.width;
					},
					scaleY:function(value,auto){
						if(value) $(this).height(this.original.height*value);
						if(auto)$(this).css({width:'auto'});
						return $(this).height()/this.original.height;
					},
					resize:function(e){
						var target=e.data.targetImage
						var windowRect={width:$(window).width(),height:$(window).height()}
						target.scaleX(windowRect.width/(target.original.width),true);
						if($(target).height()<windowRect.height){
							$(target).height(windowRect.height);
							target.scaleX(target.scaleY(),false);
						}
						$(target).css({left:(windowRect.width/2 - $(target).width()/2)});
					
					}
				})
				this.init();
				this.resize({data:{targetImage:this}}) 		
				$(window).bind("resize",{targetImage:this},this.resize)
				
            });
        }

})(jQuery);
