RotoImages = new Object ();
RotoImages.activeImage = null;
RotoImages.position = 0;
RotoImages.initStatus = new Object ();
RotoImages.ieAngles = [ 0, 3, 5, 6, 5, 3, 0, -3, -5, -6, -5, -3 ];
RotoImages.ieAngles2 = [ 0, 0.25, 0.75, 1.5, 2.25, 2.75, 3.0, 2.75, 2.25, 1.5, 0.75, 0.25 ];
RotoImages.radConvert = function (deg) {
	return Math.PI * 2 / 360 * deg;
}

RotoImages.init = function (elms) {
	var keys = (elms).split (',');
	
	for (var i = 0; i < keys.length; i++) {
		var key = keys [i];
		var img = document.getElementById (key);
		if (img.id != 'LogoLink') {
			img.shadow = document.createElement ('img');
			img.shadow.src = img.src.replace (/_out\./g, '_shadow.');
			img.shadow.border = 0;
			with (img.shadow.style) {
				zIndex = -1;
				display = 'block';
				position = 'absolute';
			}
			img.shadow.style.left = (img.offsetLeft + 1) + 'px';
			img.shadow.style.top = (img.offsetTop + 3) + 'px';
			
			img.parentNode.appendChild (img.shadow);
		}
		
		img.overImage = new Image ();
		img.outImage = new Image ();
		img.outImage.src = img.src;
		img.overImage.src = img.src.replace (/_out\./g, '_over.');
		img.onmouseover = function () {
			this.hovering = true;
			RotoImages.activeImage = this;
			RotoImages.position = 0;
			this.src = this.overImage.src;
		};
		img.onmouseout = function () {
			RotoImages.activeImage = null;
			this.hovering = false;
			RotoImages.mouseout (this);
			this.className = '';
			if (!this.shadow && this.filters) {
				this.filters.enabled = false;
			}
			this.src = this.outImage.src;
			this.blur ();
			if (this.shadow && this.shadow.className != '') {
				this.onmouseup ();
			}
		};
		img.onmousedown = function () {
			if (!window.ActiveXObject && this.shadow) {
				this.shadow.className = 'roto-shadow-down';
				this.shadow.style.left = this.offsetLeft + 'px';
				this.shadow.style.top = (this.offsetTop + 8) + 'px';
			}
		};
		img.onmouseup = function () {
			if (this.shadow) {
				this.shadow.style.left = (this.offsetLeft + 1) + 'px';
				this.shadow.style.top = (this.offsetTop - 3) + 'px';
				this.shadow.className = '';
				RotoImages.update ();
			}
		};
			
		img.hovering = false;
		if (img.filters) {
			img.filters.item (0).enabled = false;
		}
	}
	
	RotoImages.runLogoSwivel ();
}

if (navigator.appVersion.indexOf ("MSIE") == -1) {
	RotoImages.update = function () {
		var img = RotoImages.activeImage;
		
		if (img) {
			RotoImages.position++;
			
			if (RotoImages.position == 12) {
				RotoImages.position = 0;
			}
			
			img.className = "rotoImage-" + RotoImages.position;
			if (img.shadow && img.shadow.className != 'roto-shadow-down') {
				img.shadow.className = "rotoImage-" + RotoImages.position;
			}
		}
	};
	
	RotoImages.mouseout = function (img) {
		img.className =
		img.shadow.className = "";
	};
} else {
	RotoImages.update = function () {
		if (RotoImages.activeImage) {
			RotoImages.position++;
			
			if (RotoImages.position == 12) {
				RotoImages.position = 0;
			}
			
			var img = RotoImages.activeImage;
			var angles = (img.id == 'LogoLink' ? RotoImages.ieAngles2 : RotoImages.ieAngles);
			var angle = angles [RotoImages.position];
			var rad = RotoImages.radConvert (angle);
			var costheta = Math.cos (rad);
			var sintheta = Math.sin (rad);
			
			if (!RotoImages.initStatus [img.id]) {
				var sObj =
				RotoImages.initStatus [img.id] = new Object ();
				
				sObj.centerX = img.offsetLeft + Math.floor (img.offsetWidth / 2);
				sObj.centerY = img.offsetTop + Math.floor (img.offsetHeight / 2);
			} else {
				var sObj = RotoImages.initStatus [img.id];
			}
			
			img.filters.item (0).enabled = true;
			img.filters.item (0).M11 = costheta;
			img.filters.item (0).M12 = -sintheta;
			img.filters.item (0).M21 = sintheta;
			img.filters.item (0).M22 = costheta;
			img.style.left = sObj.centerX - Math.floor (img.offsetWidth / 2) + 'px';
			img.style.top = sObj.centerY - Math.floor (img.offsetHeight / 2) + 'px';
			
			if (img.id != 'LogoLink') {
				img.shadow.filters.item (0).enabled = true;
				img.shadow.filters.item (0).M11 = costheta;
				img.shadow.filters.item (0).M12 = -sintheta;
				img.shadow.filters.item (0).M21 = sintheta;
				img.shadow.filters.item (0).M22 = costheta;
				img.shadow.style.left = (sObj.centerX - Math.floor (img.offsetWidth / 2) + 1) + 'px'
				img.shadow.style.top = (sObj.centerY - Math.floor (img.offsetHeight / 2) + 3) + 'px';
			}
		}
	};
	
	RotoImages.mouseout = function (img) {
		var sObj = RotoImages.initStatus [img.id];
		
		img.filters.item (0).enabled = false;
		if (img.id != 'LogoLink') {
			img.shadow.filters.item (0).enabled = false;
		}
		img.style.left = sObj.centerX - Math.floor (img.offsetWidth / 2) + 'px';
		img.style.top = sObj.centerY - Math.floor (img.offsetHeight / 2) + 'px';
		if (img.shadow) {
			img.shadow.style.left = (sObj.centerX - Math.floor (img.offsetWidth / 2) + 1) + 'px'
			img.shadow.style.top = (sObj.centerY - Math.floor (img.offsetHeight / 2) + 3) + 'px';
		}
		img.className = '';
		if (img.shadow) img.shadow.className = "";
	};
}

RotoImages.runLogoSwivel = function () {
	var img = document.getElementById ("LogoLink");
	
	RotoImages.position = (++arguments.callee.count % 12);
	
	if (arguments.callee.count == 0) {
		RotoImages.activeImage = img;
		img.onmouseover ();
	}
	
	if (arguments.callee.count < 24 && RotoImages.activeImage === img) {
		window.setTimeout (arguments.callee, 50);
	} else {
		img.className = '';
		if (img.filters) img.filters.item (0).enabled = false;
		RotoImages.activeImage = null;
		RotoImages.position = 0;
		img.onmouseout ();
		arguments.callee.count = 0;
	}
};

RotoImages.runLogoSwivel.count = -1;

window.setInterval (RotoImages.update, 50);
