

red.prototype.resize = {

	resizer_size : 8,
	
	onresize : null,
	
	padding : 2,
	
	image : 'pics/resizer.gif',
	
	color : 'transparent',
	
	init : function(elem,minb,maxb,minh,maxh){
		//make absolute
		if(!red.prototype.css.has_position(elem)){
			red.prototype.css.position(elem,'relative');
		}
		
		
		padding = red.prototype.resize.padding;
		//padding = padding*2;
		
		
		if(minb == null){
			minb = 50;	
		}
		if(maxb == null){
			maxb = 100;	
		}
		if(minh == null){
			minh = 50;	
		}
		if(maxh == null){
			maxh = 100;	
		}
				
		var rect = red.prototype.rect.get(elem);
		
		var posx = rect.width-red.prototype.resize.resizer_size;
		var posy = rect.height-red.prototype.resize.resizer_size;
								
		var div = red.prototype.dom.create('div',elem);
		div.resizeobj 	= elem;
		div.padding = padding;
		div.minb = minb;
		div.maxb = maxb;
		div.minh = minh;
		div.maxh = maxh;
								
		red.prototype.css.set(div,"background-color:"+red.prototype.resize.color+";background-image:url("+red.prototype.path+red.prototype.resize.image+");position:absolute;font-size:1pt;left:"+(posx-padding)+"px;top:"+(posy-padding)+"px;"+
					"width:"+red.prototype.resize.resizer_size+"px;height:"+red.prototype.resize.resizer_size+"px;");
		
		var r_size = red.prototype.resize.resizer_size+padding;
		red.prototype.drag.opacitychange = false;
		red.prototype.drag.cursor = 'nw-resize';
		red.prototype.drag.is_resizer = true;
		red.prototype.drag.init(div,null,(minb-r_size),(maxb-r_size),(minh-r_size),(maxh-r_size));
		
				
		div.ondragstart = function(){
			this.rect		= red.prototype.rect.get(this.resizeobj);
			this.startxy 	= red.prototype.css.getxy(this);
			
			if(this.resizeobj.onresizestart != null){
				this.resizeobj.onresizestart();
			}
									
		}
		
		div.ondrag = function(){
			
			var thisxy = red.prototype.css.getxy(this);
						
			x_diff = this.startxy[0]-thisxy[0]-this.padding;
			y_diff = this.startxy[1]-thisxy[1]-this.padding;
			
			var thisb = this.rect.width-x_diff-this.padding;
			var thish = this.rect.height-y_diff-this.padding;
						
			red.prototype.css.set1(this.resizeobj,'width',thisb+"px");
			red.prototype.css.set1(this.resizeobj,'height',thish+"px");
			
			if(this.resizeobj.onresize != null){
				this.resizeobj.onresize();
			}
							
		}
		
		div.ondragend = function(){
			if(this.resizeobj.onresizeend != null){
				this.resizeobj.onresizeend();
			}
							
		}
		
		
		return div;
	}


}