
function init() {
	
	
	document.getElementById('footer').style.top=1500+'px';

	

	ourTestimonialManager = new TestimonialManager();
	ourTestimonialManager.init();
}
var ourTestimonialManager = null;

function BubbleSet() {
	this.id = null;
	this.textDivReference = null;
	this.bubbleReferences = Array();
	this.bubbleSize = null;
	this.increasing = false;
	this.needToRender = true;

	this.closedPosition = Array();
	this.openPosition = Array();
	this.xCenter;
	this.yCenter;
}

BubbleSet.prototype.init = function(textDiv,bubble1,bubble2) {
	
	this.bubbleReferences[0] = bubble1;
	this.bubbleReferences[1] = bubble2;
	
	this.textDivReference = textDiv;
		var x = this.textDivReference.offsetLeft;
		var y = this.textDivReference.offsetTop;
		var width = this.textDivReference.offsetWidth;
		var height = this.textDivReference.offsetHeight;
	
	this.closedPosition[0] = x;
	this.closedPosition[1] = y;
	this.openPosition[0] = textDiv.getAttribute("openx");
	this.openPosition[1] = textDiv.getAttribute("openy");
	this.maxSize = textDiv.getAttribute("openwidth");


	this.bubbleReferences[0].childNodes[0].style.width = 30;
	this.bubbleReferences[0].childNodes[0].style.height = 30;
	this.bubbleReferences[1].childNodes[0].style.width = 30;
	this.bubbleReferences[1].childNodes[0].style.height = 30;
	this.textDivReference.style.left = x;
	this.textDivReference.style.top = y;
	
	this.textDivReference.style.width = width;
	this.textDivReference.style.visibility = "visible";
	this.bubbleReferences[0].style.visibility = "visible";
	this.bubbleReferences[1].style.visibility = "visible";
	
	this.placeBubbles();
}


BubbleSet.prototype.placeBubbles = function() {
	var x = this.textDivReference.offsetLeft;
	var y = this.textDivReference.offsetTop;
	var width = this.textDivReference.offsetWidth;
	var height = this.textDivReference.offsetHeight;
	this.xCenter = Math.round(x + (width/2));
	this.yCenter = Math.round(y + (height/2));

	var currentBubbleRadius = Math.round(this.bubbleReferences[0].childNodes[0].offsetWidth/2);
	var bubbleLeft = this.xCenter - currentBubbleRadius;
	var bubbleTop =  this.yCenter - currentBubbleRadius;
	
	this.bubbleReferences[0].style.left = bubbleLeft +Math.round(currentBubbleRadius/40);
	this.bubbleReferences[1].style.left = bubbleLeft ;
	

	this.bubbleReferences[0].style.top = bubbleTop + Math.round(currentBubbleRadius/200);
	this.bubbleReferences[1].style.top = bubbleTop - Math.round(currentBubbleRadius/300);
	
}
BubbleSet.prototype.activate = function() {
	for (var i=0;i<ourTestimonialManager.bubbleReferences.length;i++) {
		ourTestimonialManager.bubbleReferences[i].deActivate();
	}
	this.startRendering()
	this.increasing = true;
	this.textDivReference.style.zIndex = 80;
	this.bubbleReferences[0].style.zIndex = 79;
	this.bubbleReferences[1].style.zIndex = 79;
}
BubbleSet.prototype.deActivate = function() {
	this.startRendering();
	this.increasing = false;
	this.textDivReference.style.zIndex = 50;
	this.bubbleReferences[0].style.zIndex = 49;
	this.bubbleReferences[1].style.zIndex = 49;
}


BubbleSet.prototype.stopRendering = function() {
	this.needToRender = false;
	
}
BubbleSet.prototype.startRendering = function() {
	this.needToRender = true;
	if (this.bubbleReferences[0].childNodes[0].offsetWidth <= 31) {
		var path = this.bubbleReferences[0].childNodes[0].src;
		if (path.indexOf("_small")==-1) {
			
			path = path.replace("_small.gif",".gif");
			this.bubbleReferences[0].childNodes[0].src = path;
		}
	}
}

BubbleSet.prototype.iterateBubbles = function() {
	if (this.needToRender) {
		var bubbleSize =  this.bubbleReferences[0].childNodes[0].offsetWidth;


		if (Math.abs(this.maxSize - bubbleSize ) > 60)  {
			this.textDivReference.style.visibility = "hidden";
		}
		else {
			this.textDivReference.style.visibility = "visible";
		}

		var oldBubbleSize = bubbleSize;
		if (this.increasing) {
			
			this.textDivReference.style.left = Math.round(this.textDivReference.offsetLeft + (this.openPosition[0]-this.textDivReference.offsetLeft)/3);

			this.textDivReference.style.top = Math.round(this.textDivReference.offsetTop + (this.openPosition[1]-this.textDivReference.offsetTop)/3);

			bubbleSize = Math.round(bubbleSize + (this.maxSize - bubbleSize)/3);
			if (bubbleSize > this.maxSize) bubbleSize = this.maxSize;


			var path = this.bubbleReferences[0].childNodes[0].src;			
			if ((bubbleSize > 45) && (path.indexOf("_small")!=-1)) {
				path = path.replace("_small.gif",".gif");
				this.bubbleReferences[0].childNodes[0].src = path;
			}
		}
		else if (!this.increasing) {
			
			this.textDivReference.style.left = Math.round(this.textDivReference.offsetLeft + (this.closedPosition[0]-this.textDivReference.offsetLeft)/8);

			this.textDivReference.style.top = Math.round(this.textDivReference.offsetTop + (this.closedPosition[1]-this.textDivReference.offsetTop)/8);

			bubbleSize = Math.round(bubbleSize + (30 - bubbleSize)/3);
			if (bubbleSize > this.maxSize) bubbleSize = this.maxSize;


			var path = this.bubbleReferences[0].childNodes[0].src;
			
			if ((bubbleSize < 45) && (path.indexOf("_small")==-1)) {
				path = path.replace(".gif","_small.gif");
				this.bubbleReferences[0].childNodes[0].src = path;
			}
			

		}

		
		for (var i=0;i<this.bubbleReferences.length;i++) {
			this.bubbleReferences[i].childNodes[0].style.width  = bubbleSize;
			this.bubbleReferences[i].childNodes[0].style.height = bubbleSize;
		}
		
		this.placeBubbles();
		if (
				((Math.abs(this.openPosition[0]-this.textDivReference.offsetLeft)<2) &&
				(Math.abs(this.openPosition[1]-this.textDivReference.offsetTop)<2)) || 
				((Math.abs(this.closedPosition[0]-this.textDivReference.offsetLeft)<2) && 
				(Math.abs(this.closedPosition[1]-this.textDivReference.offsetTop)<2))  
		)
		this.stopRendering();

	}
}

function TestimonialManager() {
	this.bubbleReferences = Array();
	
}
TestimonialManager.prototype.activate = function(index) {
	this.bubbleReferences[index].activate();
}
TestimonialManager.prototype.deActivate = function(index) {
	this.bubbleReferences[index].deActivate();

}
TestimonialManager.prototype.init = function () {
	divCollection = document.getElementsByTagName("DIV");

	for (var i=0;i<divCollection.length;i++) {
		if (divCollection[i].className	== "testimonial") {
		
			var textDiv = divCollection[i];
			
			var id = textDiv.id;
			
			var bubbleIndex = this.bubbleReferences.length;
			// save for future reference. 
			this.bubbleReferences[bubbleIndex] = new BubbleSet();
			var bubble1 = document.getElementById(id + "_bubble1");
			var bubble2 = document.getElementById(id + "_bubble2");
			
			this.bubbleReferences[bubbleIndex].init(textDiv,bubble1,bubble2,divCollection[i].getAttribute("maxsize"));

			eval("bubble2.onmouseover=function() {ourTestimonialManager.activate('"+ bubbleIndex +"'); };");
			eval("textDiv.onmouseover=function() {ourTestimonialManager.activate('"+ bubbleIndex +"'); };");
			eval("bubble2.onmouseout=function() {ourTestimonialManager.deActivate('"+ bubbleIndex +"'); };");
			
		}
	}
	go();
}

function go() {
	for (var i=0;i<ourTestimonialManager.bubbleReferences.length;i++) {
		ourTestimonialManager.bubbleReferences[i].iterateBubbles();
	}
	setTimeout("go();",40);
}
window.onload=init;
