/*
@author: Remy Sharp / http://remysharp.com
@date: 2007-04-21
@usage:
$('img').zoom('200%', '200%');
$('img').zoom('300px', '200px');
$('img').zoom(300);

realwidth : realheight = 400 : x
540 : 300 = 400 : x
540 / 300 = 400 / x

*/
jQuery.fn.zoom = function(height, width, iunit) {


  if(!iunit){
	iunit = 'px';  
  }
  
  //alert(jQuery(this).height());
  
  if (!width && height) {
    width = height;
  } else if (width && !height) {
    realheight = jQuery(this).height();
	realwidth = jQuery(this).width();
	
	
	parsewidth = parseFloat(width);
	
	newheight = (parsewidth * realheight) / realwidth; 
	height = Math.round(newheight) + 'px';
	
	
  } else if (!width && !height) {
    width = height = '100%';
  }
  
  function toem(px) {
	if (iunit=='em'){
		px = parseFloat(px);
		return (px * 0.0626).toString() + 'em';
	}else{
		return px;
	}
  }
  
  function getLen(elm, side, target) {
    var l = 1;
    if (target.indexOf('%') === -1) {
      l = toem(target);
    } else {
      l = toem(elm[side] * (parseFloat(target)/100));
    }
    
    return l;
  }
  
  return this.each(function() {
    var hem = getLen(this, 'height', height);
    var wem = getLen(this, 'width', width);
    //alert(hem + ':' + wem);
	jQuery(this).width(wem);
	jQuery(this).height(hem);
    //jQuery(this).css({ height: hem, width: wem });
  });
};