function resizeImage(img, frame, dimObject)
{
	if(!dimObject)
	{
		alert('A hosszúságot és a szélességet meg kell adni!');
		return;
	}
	else
	{
		if(isNaN(dimObject.width) || dimObject.width < 1)
		{
			alert('A kép szélessége nem egy nullánál nagyobb egész számként van megadva!')
			return;
		}
		if(isNaN(dimObject.height) || dimObject.height < 1)
		{
			alert('A kép hosszúsága nem egy nullánál nagyobb egész számként van megadva!')
			return;
		}
	}
	
	this.img = new Image;		
	this.src = img.src;	
	this.src = this.src.replace('small_','big_');
	this.src = this.src.replace('th_','');
	this.img.id = img.id || '';
	this.frame = $(frame);
	this.width = dimObject.width; 
	this.height = dimObject.height;	
	this.error = false;	

	var that = this;
	this.img.onerror = function()
	{		
		that.error = true;		
		alert('Az ' + that.src + ' egy nemlétező elérési út!');		
	}

	this.img.onload = function()
	{				
		if(!this.error)
		{		   		  
		   var dims = that.getResizedDims();
		   this.width = dims[0];
		   this.height = dims[1];
		   that.frame.innerHTML = ''; 		   
		   that.frame.appendChild(this);
		   that.setPadding();
		   that.frame.style.display = 'block';		   
		}
	}
	this.img.src = this.src;	 
}

resizeImage.prototype.getResizedDims = function()
{	
	var new_width, new_height;
	var target_ratio = this.width/this.height;
	
	var img_ratio = this.img.width/this.img.height;

	if (target_ratio > img_ratio) 
	{
		new_height = this.height;
		new_width = img_ratio * this.height;
	}
	else 
	{
		new_height = this.width/img_ratio;
		new_width = this.width;
	}

	if(new_height > this.height)
	{
		new_height = this.height;
	}
	if (new_width > this.width) 
	{
		new_height = this.width;
	}	
	return [new_width,new_height];
}

resizeImage.prototype.setPadding = function()
{
   var vert_margin = '0 ';
   var hor_margin = ' 0';
   if(this.height-this.img.height > 1)
   {
	   vert_margin = parseInt((this.height-this.img.height)/2) + 'px';	   	   
   }
   if(this.width-this.img.width > 1)
   {
	   hor_margin = ' ' + parseInt((this.width-this.img.width)/2) + 'px';	   
   }
   this.frame.style.margin = vert_margin + hor_margin;   
}
