var fx_config = new Array();
fx_config['images'] = new Array();
fx_config['images']['constraint'] = new Array;
fx_config['images']['zoom'] = new Array;

/* config area */
fx_config['images']['constraint']['mini'] 		= 100;
fx_config['images']['constraint']['thumb'] 		= 175;
fx_config['images']['constraint']['fullsize'] 		= 300;
fx_config['images']['constraint']['zoom'] 		= 800;
fx_config['images']['constraint']['constrainBy'] 	= 'w';		// width (w) or height (h)

fx_config['images']['zoom']['step']			= 7;		// number pixels to jump with each expand/contract
fx_config['images']['zoom']['speed']			= 1;		// delay in milliseconds between jumps
fx_config['images']['zoom']['runout']			= 1000;		// maximum number of iterations to expand
fx_config['images']['zoom']['tween']			= 10;		// positive number tweens out
/* end config area */


var unique_counter = 0;

function mouseoverZoom(targ, constrainTo) {
	// attach zoom fx
	targ.zoom = document.createElement('div');
	targ.zoom.className = 'float imgZoom';
	targ.zoom.image = document.createElement('img');
	targ.zoom.image.id = (targ.id!='' && targ.id!=undefined) ? targ.id+'|zoom_img' : '_'+(unique_counter++);
	document.body.appendChild(targ.zoom);
	targ.zoom.appendChild(targ.zoom.image);
	targ.zoom.image.src = targ.src;
	if(targ.preloaded) {
		targ.zoom.image.src = targ.preloaded.src;
	} else {
		if((constrainTo==undefined) || (constrainTo < fx_config['images']['constraint']['fullsize']))	// use fullsize
			targ.zoom.image.src = targ.src.replace('.t.jpg', '.f.jpg').replace('.m.jpg','.f.jpg');
		else 	targ.zoom.image.src = targ.src.replace('.t.jpg', '.z.jpg').replace('.m.jpg','.z.jpg').replace('.f.jpg','.z.jpg');
	}
	targ.zoom.image.onmouseout = function(e) {	if(!e) e = this.event; mouseoutZoom(e.target);	}

	targ.zoom.display='block';
	targ.zoom.style.width=targ.offsetWidth+'px';
	targ.zoom.style.height=targ.offsetHeight+'px';
	targ.zoom.image.style.width=targ.offsetWidth+'px';
	targ.zoom.image.style.height=targ.offsetHeight+'px';
	targ.zoom.style.top = Top(targ)+'px';
	targ.zoom.style.left = Left(targ)+'px';
	targ.zoom.onclick=function(event) {	if(!event)	event=this.event;Popup('/boss/displayImage.php?w=600&src='+event.target.src,620,500);	};

	var w = 0;
	var h = 0;
	if(fx_config['images']['constraint']['constrainBy'] == 'w') {
		w = constrainTo ? constrainTo : fx_config['images']['constraint']['fullsize'];
		var ratio = targ.offsetWidth / w;
		h = targ.offsetHeight / ratio;
	} else {
		h = constrainTo ? constrainTo : fx_config['images']['constraint']['fullsize'];
		var ratio = targ.offsetHeight / h;
		w = targ.offsetWidth * ratio;
	}
	expandImage(targ.zoom.image, Math.round(w), Math.round(h), true);
} function mouseoutZoom(targ) {
	targ.parentNode.parentNode.removeChild(targ.parentNode);
}
function dissolve(targ, src, caption) {
	var container = targ.parentNode;
	var img = targ;
	if(!container.fade_holder) {
		var tmp = document.createElement('img');
		tmp.id = 'fader';
		tmp.style.position='absolute';
		container.fade_holder = tmp;
		container.fade_holder.style.top = Top(img)+'px';
		container.fade_holder.style.left = Left(img);
		container.appendChild(tmp);
		//container.fade_holder.onclick=function() {openWin($('img_holder').src.replace('.f.jpg','.jpg'), 680, 510);}
	}
	container.fade_holder.style.opacity=1;
	container.fade_holder.style.filter='alpha(opacity=100)';
	container.fade_holder.style.display='block';
	container.fade_holder.style.visibility='visible';
	container.fade_holder.src=img.src;
	container.fade_holder.width=img.offsetWidth;
	container.fade_holder.height=img.offsetHeight;
	container.fade_holder.style.top = Top(img)+'px';
	container.fade_holder.style.left = Left(img)+'px';
	targ.style.maxHeight=targ.offsetHeight;
	targ.style.width=targ.offsetWidth;
	targ.style.heght=targ.offsetHeight;
	targ.src = src;
	$('caption').innerHTML = caption;
	fade_out(container.fade_holder);
}

function preload(targ, src) {
	if(!src || (src==undefined))	src = targ.src.replace('.t.jpg', '.f.jpg').replace('.m.jpg','.f.jpg');
	targ.preloaded = new Image();
	targ.preloaded.src = src;
}
function expandImage(targ,w,h,center, otherStep, speed, running) {
	if(speed == undefined)	speed = fx_config['images']['zoom']['step'];
	if(running == undefined)running = 0;
	if(center == undefined)	center = false;

	if(fx_config['images']['zoom']['tween']) {
		if(fx_config['images']['constraint']['constrainBy'] == 'w')
			speed = (targ.offsetWidth<fx_config['images']['zoom']['tween'] && speed>2) ? speed/.4 : speed;
		else	speed = (targ.offsetHeight<fx_config['images']['zoom']['tween'] && speed>2) ? speed/.4 : speed;
	}
	if((fx_config['images']['constraint']['constrainBy'] == 'w') && (targ.offsetWidth+speed > w)
	    ||(fx_config['images']['constraint']['constrainBy'] == 'h') && (targ.offsetHeight+speed > h)
	    ||((running++) > fx_config['images']['zoom']['runout'])) {
		targ.style.offsetWidth = w;
		targ.style.offsetHeight = h;
	} else {
		if(fx_config['images']['constraint']['constrainBy'] == 'w') {
			if(!otherStep || otherStep == undefined) {
				var ratio = targ.offsetWidth / targ.offsetHeight;
				otherStep = speed/ratio;
			}
			if(center) {
				if(!targ.style.marginLeft)	targ.style.marginLeft = 0;
				else	targ.style.marginLeft = parseInt(targ.style.marginLeft) - (speed)+'px';
				if(!targ.style.marginTop)	targ.style.marginTop = 0;
				else	targ.style.marginTop = parseInt(targ.style.marginTop) - otherStep+'px';
			}
			targ.style.width  = targ.offsetWidth+speed+'px';
			targ.style.height  = targ.offsetHeight+otherStep+'px';
		} else {
			targ.style.height = targ.offsetHeight+speed+'px';
		}
		setTimeout('expandImage($(\''+targ.id+'\'), '+w+','+h+', '+center+','+otherStep+','+speed+','+running+');', fx_config['images']['zoom']['speed']);
	}
}
function fade_out(obj) {
	obj.style.opacity = parseFloat(obj.style.opacity)-.1;
	obj.style.filter='alpha(opacity='+(parseFloat(obj.style.opacity)*100)+')';
	if(obj.style.opacity <= 0) {
		obj.style.display='none';
		return;
	} else {
		setTimeout('fade_out($("'+obj.id+'"));', 50);
	}
}


