<!--
/*********************
phunphorm.js
Chris M. Sissons
Used to animate form elements.
*********************/


Hashtable.prototype.hash = null;
Hashtable.prototype.keys = null;
Hashtable.prototype.location = null;

function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

Hashtable.prototype.get = function (key) {
	return this.hash[key];
}

Hashtable.prototype.put = function (key, value) {
	if (value == null)
		return null;

	if (this.hash[key] == null)
		this.keys[this.keys.length] = key;

	this.hash[key] = value;
}

var swellTimeouts = new Hashtable();
var swellHasFocus = new Hashtable();
var swellIsOver = new Hashtable();


var swellTo = 1.4;
var numSwellSteps = 5;

function swellOver(objId, origWidth, origHeight, origFontSize) {
  swellIsOver.put(objId, true);
  startSwellShrink(objId, 1, origWidth, origHeight, origFontSize);
}

function swellOut(objId, origWidth, origHeight, origFontSize) {
  swellIsOver.put(objId, false);
  
  //-- Only shrink if object doesn't have focus
  if (swellHasFocus.get(objId) != true)
    startSwellShrink(objId, -1, origWidth, origHeight, origFontSize);
}

function swellGotFocus(objId, origWidth, origHeight, origFontSize) {
  swellHasFocus.put(objId, true);
  startSwellShrink(objId, 1, origWidth, origHeight, origFontSize);
}

function swellLostFocus(objId, origWidth, origHeight, origFontSize) {
  swellHasFocus.put(objId, false);
  
  //-- Only shrink if object doesn't have cursor over it
  if (swellIsOver.get(objId) != true)
    startSwellShrink(objId, -1, origWidth, origHeight, origFontSize);
}

function startSwellShrink(objId, direction, origWidth, origHeight, origFontSize) {
  //-- Cancel any animation in progress
  if (swellTimeouts.get(objId) != null)
    clearTimeout(swellTimeouts.get(objId));
  
  if (direction == 1) {
    //-- Set focus colour
    var obj = document.getElementById(objId);
  }
  
  //-- Begin animation
  doSwellShrink(objId, direction, origWidth, origHeight, origFontSize);
}

function doSwellShrink(objId, direction, origWidth, origHeight, origFontSize) {
  //-- Assign object and dimensions
  var obj = document.getElementById(objId);
  var curWidth = parseFloat(obj.style.width);
  var curHeight = parseFloat(obj.style.height);
  var curFontSize = parseFloat(obj.style.fontSize);
  
  //-- Calculate width change steps
  var maxWidth = origWidth * swellTo;
  var widthDiff = maxWidth - origWidth;
  var widthStep = widthDiff / numSwellSteps;
  
  //-- Calculate height change steps
  var maxHeight = origHeight * swellTo;
  var heightDiff = maxHeight - origHeight;
  var heightStep = heightDiff / numSwellSteps;
  
  //-- Calculate font size change steps
  var maxFontSize = origFontSize * swellTo;
  var fontSizeDiff = maxFontSize - origFontSize;
  var fontSizeStep = fontSizeDiff / numSwellSteps;
  
  //-- Make size change
  curWidth = curWidth + (widthStep * direction);
  curHeight = curHeight + (heightStep * direction);
  curFontSize = curFontSize + (fontSizeStep * direction);
  
  if (curWidth < origWidth) {
    //-- Fully shrunk
    obj.style.width = origWidth;
    obj.style.height = origHeight;
    obj.style.fontSize = origFontSize + "pt";
    obj.style.borderColor = '#ffffff';
    swellTimeouts.put(objId, null);
  }
  else if (curWidth > (origWidth * swellTo)) {
    //-- Fully swelled
    swellTimeouts.put(objId, null);
    obj.style.borderColor = '#ff0000';
  }
  else {
    //-- Keep animating
    obj.style.width = curWidth;
    obj.style.height = curHeight;
    obj.style.fontSize = curFontSize + "pt";
    swellTimeouts.put(objId, setTimeout("doSwellShrink('" + objId + "', " + direction + ", " + origWidth + ", " + origHeight + ", " + origFontSize + ")", 40));  //-- Record timeout id
  }
}

//-->
