//balloonbox.js

/*-------------------
 Balloon Box Class
--------------------*/

function BalloonBox() {
    this._balloonBox;
}

//Text
BalloonBox.prototype._headerText;

BalloonBox.prototype.setHeaderText = function (headerText) {
 	this._headerText = headerText;
}

BalloonBox.prototype.getHeaderText = function () {
 	return this._headerText;
}

BalloonBox.prototype._bodyText;

BalloonBox.prototype.setBodyText = function (bodyText) {
 	this._bodyText = bodyText;
}

BalloonBox.prototype.getBodyText = function () {
 	return this._bodyText;
}

//Position
BalloonBox.prototype._xPosition;

BalloonBox.prototype._yPosition;

BalloonBox.prototype.setPosition = function (xPosition, yPosition) {
 	this._xPosition = xPosition;
 	this._yPosition = yPosition;
}

BalloonBox.prototype.getXPosition = function () {
 	return this._xPosition;
}

BalloonBox.prototype.getYPosition = function () {
 	return this._yPosition;
}

//Width
BalloonBox.prototype._balloonWidth;

BalloonBox.prototype.setBalloonWidth = function (balloonWidth) {
 	this._balloonWidth = balloonWidth;
}

BalloonBox.prototype.getBalloonWidth = function () {
 	return this._balloonWidth;
}

//Orientation
BalloonBox.prototype._handleOrientation;

BalloonBox.prototype.setHandleOrientation = function (handleOrientation) {
 	this._handleOrientation = handleOrientation;
}

BalloonBox.prototype.getHandleOrientation = function () {
 	return this._handleOrientation;
}

//Type
BalloonBox.prototype._balloonType;

BalloonBox.prototype.setBalloonType = function (balloonType) {
 	this._balloonType = balloonType;
}

BalloonBox.prototype.getBalloonType = function () {
 	return this._balloonType;
}

//BalloonBox Functions
BalloonBox.prototype.isMessageDisplayed = function() {
	var balloonBox 				= $('balloonBox');
	var balloonBoxDisplay		= balloonBox.getStyle('display');
	return balloonBoxDisplay;
}

BalloonBox.prototype.displayBalloonBox = function() {	

	try {
	
		//Create references to balloon box divs
		var balloonBox 				= $('balloonBox');
		var balloonBoxHeader 		= $('balloonBoxHeader');
		var balloonBoxBody 			= $('balloonBoxBody');
		var balloonBoxHandle 		= $('balloonBoxHandle');
		var balloonShadow			= $('balloonShadow');
		var balloonBoxHandleShadow	= $('balloonBoxHandleShadow');
		var balloonBoxSidebar		= $('balloonBoxSidebar');
		
		//Create references for balloon handle image
		var balloonHandleImage			= $('balloonHandleImage');
		var balloonHandleShadowImage	= $('balloonHandleShadowImage');
	
		//Get data for the BalloonBox	
		var headerText 				= this.getHeaderText();
		var	bodyText				= this.getBodyText();
		var	xPosition				= this.getXPosition();
		var	yPosition				= this.getYPosition();
		var	balloonWidth			= this.getBalloonWidth();
		var	handleOrientation		= this.getHandleOrientation();
		var	balloonType				= this.getBalloonType();
	
		//Format string and set image
		var handleImageOrientation		= handleOrientation.capitalize();
		balloonHandleImage.src 			= 'images/balloonHandle' + handleImageOrientation + '.gif';
		balloonHandleShadowImage.src 	= 'images/balloonHandle' + handleImageOrientation + 'Shadow.gif'
					
		//Text must be set first to get accurate
		//width and height of the elements
		balloonBoxHeader.innerHTML = headerText;
		balloonBoxBody.innerHTML = bodyText;
		
		if (balloonWidth) {
			balloonBox.style.width = balloonWidth + 'px';
		} else {
			balloonWidth = balloonBox.getWidth();
		}
		
		//Requires prototype library
		//Set the height and width 
		handleWidth 	= balloonBoxHandle.getWidth();
		handleHeight	= balloonBoxHandle.getHeight();
		balloonHeight	= balloonBox.getHeight();
		balloonPadding	= (10 * 2);
		balloonBorder 	= (1 * 2) - 1;
		balloonExtra	= balloonPadding + balloonBorder;
			
		//Set the center of the balloon and handle
		balloonXCenter	= balloonWidth/2;
		balloonYCenter	= balloonHeight/2;	
		handleXCenter	= handleWidth/2;
		handleYCenter	= handleHeight/2;
		
		//Set position of balloon box
		var balloonXPosition = $H({north: xPosition - balloonXCenter, east: xPosition - (handleWidth + balloonWidth + balloonExtra),  south: xPosition - balloonXCenter, west: xPosition + (handleWidth - balloonBorder)});
		var balloonYPosition = $H({north: yPosition + (handleHeight - 4), east: yPosition - balloonYCenter, south: yPosition - (balloonHeight + handleHeight + balloonBorder), west: yPosition - balloonYCenter});
	
		//Set position of handle
		var handleXPosition = $H({north: xPosition - handleXCenter, east: xPosition - handleWidth,  south: xPosition - handleXCenter, west: xPosition});
		var handleYPosition = $H({north: yPosition, east: yPosition - handleYCenter, south: yPosition - handleHeight, west: yPosition - handleYCenter});
	
		//Place handle shadow first so that it shows up correctly
		balloonBoxHandleShadow.setStyle({left: handleXPosition[handleOrientation] + 5  + 'px'});
		balloonBoxHandleShadow.setStyle({top: handleYPosition[handleOrientation] + 5  + 'px'});
		balloonBoxHandleShadow.setStyle({opacity: 0.2});
	
		//Place balloon box shadow first so that it shows up correctly
		balloonShadow.setStyle({left: balloonXPosition[handleOrientation] + 5 + 'px'});
		balloonShadow.setStyle({top: balloonYPosition[handleOrientation] + 5 + 'px'});	
		balloonShadow.setStyle({width: balloonWidth + balloonExtra + 'px'});
		balloonShadow.setStyle({height: balloonHeight + 'px'});
		balloonShadow.setStyle({opacity: 0.2});
		
		//Place handle
		balloonBoxHandle.setStyle({left: handleXPosition[handleOrientation] + 'px'});
		balloonBoxHandle.setStyle({top: handleYPosition[handleOrientation] + 'px'});
		
		//Place balloon box
		balloonBox.setStyle({left: balloonXPosition[handleOrientation] + 'px'});
		balloonBox.setStyle({top: balloonYPosition[handleOrientation] + 'px'});
		
		//balloonBoxSidebar needs to be set this way 
		//because Internet Explorer does not set the 100% height attribute correctly
		balloonBoxSidebar.setStyle({height: balloonHeight});
		
		
		//Show the balloon box elements
		balloonShadow.style.display 			= 'block';
		balloonBoxHandleShadow.style.display	= 'block';
		balloonBox.style.display 				= 'block';
		balloonBoxHandle.style.display 			= 'block';
				
		//Show sidebar 
		if (balloonType != 'standard') {
		
			var balloonSidebarHTML 		= $H({information: '<br/><img src="images/Information.gif" id="balloonBoxSidebarImage" alt="Information">', urgent: '<br/><img src="images/Urgent.gif" id="balloonBoxSidebarImage" alt="Urgent">', warning: '<br/><img src="images/Warning.gif" id="balloonBoxSidebarImage" alt="Warning">'});
			var balloonSidebarBGColor 	= $H({information: '#A7BED0', urgent: '#FF8484', warning: '#FFFF7E'});
			
			//Make space for the sidebar
			balloonBoxHeader.setStyle({left: 40 + 'px'});
			balloonBoxBody.setStyle({left: 40 + 'px'});
			
			//Make sure the text doesn't bleed over the dialog box
			balloonBoxHeader.setStyle({paddingRight: 40});
			balloonBoxBody.setStyle({paddingRight: 40});
	
			//Set sidebar content and display
			balloonBoxSidebar.innerHTML = balloonSidebarHTML[balloonType];
			balloonBoxSidebar.setStyle({backgroundColor: balloonSidebarBGColor[balloonType]});
			balloonBoxSidebar.style.display 			= 'block';
	
		}
	
	} catch (e) {
	 //die silently for now
	}
	
}

BalloonBox.prototype.closeBalloonBox = function() {

	try {

	var balloonBox 				= $('balloonBox');
	var balloonBoxHandle 		= $('balloonBoxHandle');
	var balloonShadow			= $('balloonShadow');
	var balloonBoxHandleShadow	= $('balloonBoxHandleShadow');
	var balloonBoxSidebar		= $('balloonBoxSidebar');
	
	//Hide the balloon box elements
	balloonBox.style.display 				= 'none';
	balloonBoxHandle.style.display 			= 'none';
	balloonShadow.style.display 			= 'none';
	balloonBoxHandleShadow.style.display	= 'none';
	
	} catch (e) {
		//die silently for now
	}
}
