

var BubbleControl = Class.create({
	initialize: function(xItemId) {
		this.itemId = xItemId;
		this.imageId = null;
		
		if (document.images) {
			preloadImg = new Image();

			this.imageURL = new Array();
			this.imageURL[1] = "_img/ah-box-silver-1.gif";
			this.imageURL[2] = "_img/ah-box-green-2.gif";
			this.imageURL[3] = "_img/ah-box-yellow-3.gif";
			this.imageURL[4] = "_img/ah-box-aqua-4.gif";
			this.imageURL[5] = "_img/ah-box-blue-5.gif";

			for(var i=1; i<=5; i++) {
				preloadImg.src = this.imageURL[i];
			}
    	}
		
	},
	swap: function(xId) {
		var newId = this.itemId;               // redefined for the scope of objects
		var newImg = this.imageURL[xId];  // redefined for the scope of objects
		var count = this.imageURL.length;
		var contentId = xId;
		Effect.Fade(this.itemId, {
			afterFinish: function() {
				// hiding all the content
				for (var i=1; i<count; i++) {
					var id = i.toString();
					if ($(id).style.display == 'block') {
						$(id).style.display = 'none';
					}
				}
				// displaying the correct content
				$(contentId.toString()).style.display = 'block';
				// applying the correct bubble background
				$(newId).style.background = "transparent url("+newImg+") no-repeat 0 0";
				// fading in the content
				Effect.Appear(newId);
			}
		});
	}
});

var Bubble = new BubbleControl('bubble');
