function ImageRotation(id, dir, imgs, cwi, duration, delay) {

				var id = id;
				var dir = dir;
				var imgs = imgs;
				var cwi = cwi;
				var duration = duration;
				var delay = delay;
				var maxWidth = 0;
				var state = 0;
				var transCurrent = null;
				var transNext = null;


				this.startRotation = function() {
					preloadImage();
				}

				this.select = function(img) {
					if (transCurrent != null) {
						transCurrent.cancel();
					}
					if (transNext != null) {
						transNext.cancel();
					}
					var time = new Date();
					state = time.getTime() + 10;
					$('portfolio_ImageSelect_'+cwi).style.background = '#CCCCCC url(/images/portfolio/tab.gif) no-repeat bottom right';
					cwi = img;
					$('portfolio_ImageSelect_'+cwi).style.background = '#666666 url(/images/portfolio/tab.gif) no-repeat bottom right';
					$(id+'_ImgRotate_current').src = dir + imgs[cwi-1];
					if (nextImg = document.getElementById(id+'_ImgRotate_next')) {
						$(id+'_ImgRotate_next').remove();
					}
					if (oldImg = document.getElementById(id+'_ImgRotate_old')) {
						$(id+'_ImgRotate_old').remove();
					}
					contRotation.delay(10);
				}

				this.setMaxWidth = function(width) {
					maxWidth = width;
				}


				var contRotation = function() {
					var time = new Date();
					if (time.getTime() > state && state > 0) {
						state = 0;
						preloadImage();
					}
				}

				 var preloadImage = function() {
					if (imgs.length == cwi) {
						cwi = 0;
					}
					var objImage = document.createElement('img');
					objImage.style.display = 'none';
					objImage.setAttribute('id', id+'_ImgRotate_new');
					objImage.style.position = 'absolute';
					objImage.src = dir + imgs[cwi];

					document.getElementById(id).appendChild(objImage);
					rotateImages.delay(delay);
				}

				 var tidyUpImages = function() {
					if (divObj = document.getElementById(id+'_ImgRotate_next')) {
						$(id+'_ImgRotate_current').setAttribute('id', id+'_ImgRotate_old');
						$(id+'_ImgRotate_old').remove();
						divObj.setAttribute('id', id+'_ImgRotate_current');
					}
				}

				var rotateImages = function() {
					if (state == 0) {
						$(id + '_ImgRotate_new').setAttribute('id', id + '_ImgRotate_next');
						transCurrent = Effect.Appear(id+'_ImgRotate_next', {duration: duration});
						transNext = Effect.Fade(id+'_ImgRotate_current', {duration: duration});
						new Effect.Morph('portfolio_ImageSelect_'+getImageIndex($(id+'_ImgRotate_current').src), {style:'background:#CCCCCC url(/images/portfolio/tab.gif) no-repeat bottom right;', duration: duration});
						new Effect.Morph('portfolio_ImageSelect_'+getImageIndex($(id+'_ImgRotate_next').src), {style:'background:#666666 url(/images/portfolio/tab.gif) no-repeat bottom right;', duration: duration});
						cwi++;
						/*now preload the next*/
						tidyUpImages.delay(duration);
						preloadImage();
					}
				}

				var getImageIndex = function(src) {
					var url = src.split("/");
					var img = url[url.length - 1];
					return imgs.indexOf(img)+1;
				}



			}
