/*
 Script: kLib.js
  Core of the kLib Javascrpt Library.
 
  Author:
   - Caleb Kniffen, <http://kniffenwebdesign.com>
 
  Version:
   1.9
  
  Required Files:
   - prototype.js or prototype.kLib.js
*/
/*
Group: Shortcut Functions

Function: $I
 Changes a HTML Element's innerHTML.
 
 Arguments:
  elem - HTML ELEMENT, The element whos innerHTML is to be change.
  inner - string, The innerHTML's new value.
*/
$I = function(elem, inner){ $(elem).innerHTML=inner; }
/*
Function: $IA
 Appends new value to elements innerHTML.
 
 Arguments:
  elem - HTML ELEMENT, The element whos innerHTML is to be change.
  inner - string, The innerHTML's new value.
 
 See Also: 
  <$I>
*/
$IA = function(elem, inner){ $(elem).innerHTML+=inner; }
/*
 Function: $IC
  Clears specified element's innerHTML.
 
  Arguments:
    elem - HTML ELEMENT, The element whos innerHTML you want to clear.
*/
$IC = function(elem){  $(elem).innerHTML = "";}
/*
 Function: $S
  Returns specified element's style property
  
  Arguments:
    elem - HTML ELEMENT, The element whos style property you want returned.
	
  Returns:
   Style, Specified element's style property.
*/
$S = function(elem){ return $(elem).style; }
/*
 Function: $N
  Shortcut for regular getElementsByTagName().
 
  Arguments:
   elem - HTML ELEMENT, The starting element for getElementsByTagName().
   tag - string, The type of HTML tag to retrieve.
*/
$N = function(elem, tag){ return $(elem).getElementsByTagName(tag); }
/*
 Function: $EN
  Correctly performs getElementsByTagName().
  
  Fixes getElementsByTagName() bug where elements whose names have been changed by javascript are not included in the array returned.
*/
$EN = function(name){
 elements = document.getElementsByTagName('*')
 matching = new Array();
 for(x=0;x<elements.length;x++) if(name == elements[x].name) matching[matching.length] = elements[x];
 return matching;
}
/*
 Group: Boolean Functions
 
 Function: isParent
  Returns whether or not the second element is an ancestor of the the first element.
  
 Arguments:
  elem - HTML ELEMENT, The element that is the parent.
  target - HTML ELEMENT, The element that is matched to see if it is an ancestor of elem.
*/
isParent=function(elem,target){
 try{
  while(elem.offsetParent!=document.body){
   if(target==null){ return false;}
   if(elem.offsetParent==target){return true;}
   elem=elem.offsetParent;
  }
 }
 catch(e){}
 return false;
}
/*
 Function: isDefined
 
 Returns:
  boolean, Whether or not variable is defined.
*/
isDefined = function(variable){ return (variable!='undefined'); }
/*
 Function: isArray
 
 Returns:
  boolean, Whether or not variable is an Array.
*/
isArray = function(variable) { return isObject(variable) && variable.constructor == Array; }
/*
 Function: isObject
 
 Returns:
  boolean, Whether or not variable is an Object.
*/
isObject = function(variable) {return (variable && typeof(variable) == 'object') || isFunction(variable);}
/*
 Function: isFunction
 
 Returns:
  boolean, Whether or not variable is a function.
*/
isFunction = function(variable) {return typeof(variable) == 'function'; }
/*
 Group: Array Functions
 
 Function: add
  Adds object to an array
*/
Array.prototype.add = function(object){ this[this.length]=object; }
/*
 Group: Element Creation Functions
 
 Function: makeAppendChild
  Creates and returns an HTML Element.
  
  Arguments:
   type - string, The type of HTML element.
   parent - HTML ELEMENT, The element you want the new element to be appended to.
   style - object, A style object; Optional.
 
  Returns:
   HTML ELEMENT
*/
makeAppendElem=function(type,parent,style){
 elem = document.createElement(type);
 if(style) Element.setStyle(elem,style);
 $(parent).appendChild(elem)
 return elem;
}
/*
 Function: makeInput
 
  Arguments:
   parent - HTML ELEMENT, The element you want the new element to be appended to.
   type - radio|input|checkbox, The type of the new HTML ELEMENT INPUT.
   value - The value of the new HTML ELEMENT INPUT.
   style - object, A style object; Optional.
 
  Returns:
   HTML ELEMENT INPUT
*/
makeInput = function(parent, type, value, style){
 elem = makeAppendElem('input', parent, style);
 elem.type = type;
 elem.value = value;
 return elem;
}
/*
 Function: makeButton
  
  Arguments:
   text - string, What the button is to say.
   parent - HTML ELEMENT, The element you want the new element to be appended to.
   style - object, A style object; Optional.
   
  Returns:
   HTML ELEMENT BUTTON
*/
makeButton = function(text, parent, style){ 
 button = makeAppendElem('button', parent, style)
 $I(button, text);
 return button;
}
/*
 Function: makeImage
 
  Arguments:
   parent - HTML ELEMENT, The element you want the new element to be appended to.
   src - string, The image's file.
   alt - string, The image's alternate text.
   style - object, A style object; Optional.
   
  Returns:
   HTML ELEMENT IMAGE
*/
makeImage = function(parent, src, alt, style){
 image = makeAppendElem('img', parent, style)
 image.alt = alt;
 image.src=src;
 return image;
}
/*
 Group: Element Formating Functions
 
 Function: makeInlineBlock
  Turns an element into an inline block.
 
 Arguments:
  elem - HTML ELEMENT, The element to be turned into an inline block.
  offset - boolean, A special Netscape option.
  onlyInlineBlock - boolean, A special display option for other browsers. 
*/
makeInlineBlock = function(elem, offset, onlyInlineBlock){
 $S(elem).overflow = 'hidden';
 if(isIE){ 
  $S(elem).display = 'inline-block'; 
  if(onlyInlineBlock!=false) $S(elem).display = 'inline';
 }
 if(isNetscape){
  $S(elem).display = 'table-cell';
  $S(elem).display = '-moz-inline-box';
  if(offset!=false){
   $S(elem).position = 'relative';
   $S(elem).top = '-10px';
  }
 }
}
/*
 Function: formatSquare
  Formats an elements dimensions into a square.
 
  Arguments:
   elem - HTML ELEMENT, The element to be turned into an inline block.
   size - integer, The size of the box.
   makeInline - boolean, Whether or not to make the square inline.
   offset - boolean, A special Netscape option.
   onlyInlineBlock -  boolean, A special display option for other browsers. 
*/
formatSquare=function(elem, size, makeInline, offset, onlyInlineBlock){
 if(makeInline) makeInlineBlock(elem, offset, onlyInlineBlock);
 $S(elem).width = size + 'px';
 $S(elem).height = size + 'px';
 $S(elem).lineHeight = size + 'px';
 $S(elem).fontSize = '0px';
}
/*
 Group: Other Functions
 
  Function: CurrentPosition
 
  Returns:
   Current coordinates of the specified element.
*/
CurrentPosition=function(elem){
 this.x=elem.offsetLeft;
 this.y=elem.offsetTop;
 elem=elem.offsetParent;
 while(elem!=null){
  this.x+=elem.offsetLeft;
  this.y+=elem.offsetTop;
  elem=elem.offsetParent;
 }
 return this;
}
/*
 Function: OptionAdder
  Adds <option>s to a <select>
 Arguments:
  select - HTML ELEMENT SELECT, The <select> you want the <option>s added too.
  array - array, An array of the desired option values.
*/
optionAdder=function(select, array){
 for(x=0; x<array.length; x++){
  option = document.createElement('option');
  option.text = array[x]
  option.value = array[x]
  try{ select.add(option,null); }
  catch(ex){select.add(option); }
 }
}
/*
Group: Variables

 Var: isIE
  boolean, Whether or not the browser is based off of Internet Explorer.
*/
var isIE =(navigator.appName == "Microsoft Internet Explorer");
/*
 Var: isNetscape
  boolean, Whether or not the browser is based off of Netscape.
*/
var isNetscape = (navigator.appName =="Netscape");
