/**
 * @author Alexander Farkas [trixta] // http://pfirsichmelba.de
 * 
 * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
 * 
 * 
 * For the latest version of this plugin and implementation visit:
 * http://pfirsichmelba.de/artikel-scripts/ie7-pagezoom-sucks.html#iezoomfluid
 * 
 */
jQuery.ieZoomDetect = function(){
	var offset = {};
	jQuery("#iezoom2doom").offset({}, offset);
	this.current = Math.round(offset.left)/100;
	if(typeof this.old == 'undefined' && typeof retest != 'undefined')
		this.old = this.current;
	else if(this.old != this.current){
			jQuery.event.trigger('zoomchange',[this.current,this.old]);
			this.old = this.current;
	}
	return this.current;
};
jQuery(function($){
	//Quick & Dirty
	$('body').append('<div id="iezoom2doom" style="width:0px;height:1px;position:absolute;left:100px;visibility:hidden;"></div>');
	var elm = $('#iezoom2doom').get(0);
	if(elm.style != undefined && elm.style.setExpression != undefined) 
		elm.style.setExpression( 'fontSize', 'jQuery.ieZoomDetect()');
});
jQuery.ieZoomCorrect = function(elm,zfac,settings){
	var jElm = jQuery(elm),processnum,nwidth = new Array(3);
	settings = jQuery.extend({
		zwidth: '',
		zmaxwidth: '',
		zminwidth: ''
  	}, settings);
	if(zfac > 0.95 && zfac < 1.05) //normal style
		jElm.css({width:'',maxWidth:'',minWidth:''});
	else{ //compute the new width
		jQuery.each([settings.zwidth,settings.zmaxwidth,settings.zminwidth],function(i){
			procnum = parseFloat(this);
			nwidth[i] = (!isNaN(procnum))? procnum/zfac+'%' : '';
		});
		jElm.css({width:nwidth[0],maxWidth:nwidth[1],minWidth:nwidth[2]});	
	}
};
jQuery.fn.ieZoomFluid = function(settings) {
	var cur = jQuery.ieZoomDetect();
	return this.each(function(){
		if(cur < 0.95 || cur > 1.05)
			jQuery.ieZoomCorrect(this,cur,settings);
	 	$(this).bind('zoomchange', function(event,zFac){
			jQuery.ieZoomCorrect(this,zFac,settings);
 		});
	});
};