/* Expando Image Script ©2008-2010 John Davenport Scheuer
   as first seen in http://www.dynamicdrive.com/forums/
   username: jscheuer1 - This Notice Must Remain for Legal Use
   Updated: 02/14/2010 7:33am
   */

if(document.images){
	(function(){
		var cos, a = /Apple/.test(navigator.vendor), times = a? 20 : 40, speed = a? 40 : 20, widthHeight = function(dim){
				return dim[0] * cos + dim[1] + 'px';
			}, targ, addAttach;
		function expConIm(im){
			im = im || window.event;
			var type;
			if(im.type){
					type = im.type;
			}
			if(!expConIm.r.test(im.className)){
				im = im.target || im.srcElement || null;
			}
			if(!im || !expConIm.r.test(im.className)){
				return;
			}
			var e = expConIm,
			resize = function(){
				if(!e.ims[i]) {return;}
				cos = (1 - Math.cos((e.ims[i].jump / times) * Math.PI)) / 2;
				im.style.width = widthHeight(e.ims[i].w);
				im.style.height = widthHeight(e.ims[i].h);
				if(e.ims[i].d && times > e.ims[i].jump){
					++e.ims[i].jump;
					e.ims[i].timer = setTimeout(resize, speed);
				}else if(!e.ims[i].d && e.ims[i].jump > 0){
					--e.ims[i].jump;
					e.ims[i].timer = setTimeout(resize, speed);
				}
			}, d = document.images, i = d.length - 1;
			for(i; i > -1; --i)
				if(d[i] === im) {break;}
			i = i + im.src;
			if(!e.ims[i] && im && type === 'mouseover'){
				e.ims[i] = {im: new Image(), jump: 0};
				e.ims[i].im.onload = function(){
					im.title = im.alt = '';
					e.ims[i].w = [e.ims[i].im.width - im.width, im.width];
					e.ims[i].h = [e.ims[i].im.height - im.height, im.height];
					e(im);
				};
				e.ims[i].im.src = im.src;
				return;
				}
			if(e.ims[i] && e.ims[i].timer) {clearTimeout(e.ims[i].timer);}
			if(e.ims[i]){
				e.ims[i].d = !e.ims[i].d;
				resize();
			}
		}
		
		targ = (function(){
			return typeof event !== 'undefined'? function(){return event.srcElement || null;} :
			function(e){return e.target || null;};
		})();

		function imClick(e){
			var t = targ(e);
			if(t && expConIm.r.test(t.className) && t.parentNode.href){
				expConIm.ims = {};
			}
		}

		expConIm.ims = {};

		expConIm.r = /\bexpando\b/;

		addAttach = (function(){return window.addEventListener? function(el, ev, f){
				el.addEventListener(ev, f, false);
			}:window.attachEvent? function(el, ev, f){
				el.attachEvent('on' + ev, f);
			}:function(){return;};
		})();
		addAttach(document, 'mouseover', expConIm);
		addAttach(document, 'mouseout', expConIm);
		addAttach(document, 'click', imClick);
	})();
}


