﻿/* Extracted from Prototype JS Library, http://prototype.conio.net/
 Written by Sam Stephenson, http://conio.net/ */
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = (document.getElementById) ? document.getElementById(element) : eval("document.all."+element) ;
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

/* Functions to handle cross-browser events.
 Written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com. */
/* get the target of an event object */
function getTarget(e) {
	return (e.target) ? e.target : e.srcElement;
}

/* Function to grab all elements with a specific class name.
 Original written by Jonathan Snook, http://www.snook.ca/jonathan
 Add-ons by Robert Nyman, http://www.robertnyman.com 	
 Re-written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com */
function getElementsByClass(className, elm, tag){
	if(elm == null) elm = document;
	if(tag == null) tag = '*';
	var elems = elm.getElementsByTagName(tag);
	var returnElems = new Array();
	className = className.replace(/\-/g, "\\-");
	var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
	for(var i=0; i<elems.length; i++){
		if(pattern.test(elems[i].className)) returnElems.push(elems[i]);
	}
	return returnElems
}

/* Function to return the class attribute. IE and all other standards compliant browsers have different names for the class attribute object. */
function classAttr(){
	if (browser == IE ){
		class_att = 'className';
	}
	else {
		class_att = 'class';
	}
	
	return class_att;
	
}
/* Functions to add/remove event listeners to objects
	Written by John Resig, http://ejohn.org */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

/* Function to get img extension */
function getImgExt(obj){
	var src = obj.getAttribute('src');
	var imgExtPosition = src.lastIndexOf('.') + 1;	//Get the extension. Add 1 to get only the extension, not .extension
	
	var extension;
	
	if(src.match('clearpixel.gif')){	//If IE and the image is a PNG, return 'png', because the PNG transparency function causes the img src to be clearpixel.gif.
		extension = 'png';
	}
	
	else {
		var extension = src.slice(imgExtPosition);
	}
	return extension;
}

/* Function to get img src text */
function getImgSrc(obj){
	var src = obj.getAttribute('src');	
	return src;
}

/* Function to get img alt text */
function getImgAlt(obj){
	var alt_text = obj.getAttribute('alt');	
	return alt_text;
}

/* Function to get img height text */
function getImgHeight(obj){
	var img_h = obj.getAttribute('height');	
	return img_h;
}

/* Function to get img width text */
function getImgWidth(obj){
	var img_w = obj.getAttribute('width');	
	return img_w;
}

/* get the X location of an object */
function getX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x)	curleft += obj.x;
	return curleft;
}

/* get the Y location of an object */
function getY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)	curtop += obj.y;
	return curtop;
}

/* get the height of an element */
function getHeight(id){
    var elemHeight = $(id).offsetHeight;  
    
    return elemHeight;
}

/* get the width of an element */
function getWidth(id){
    var elemWidth = $(id).offsetHeight;  
    
    return elemWidth;
}