
function resizeLink() {
  obj = document.getElementById('viewlink');
  if (obj) {
    screenx = screen.width;
    screeny = screen.height;
    if (typeof( window.innerWidth ) == 'number') {
      windowx = window.innerWidth;
      windowy = window.innerHeight;
    } else if (document.documentElement &&
               ( document.documentElement.clientWidth ||
                 document.documentElement.clientHeight ) ) {
      windowx = document.documentElement.clientWidth;
      windowy = document.documentElement.clientHeight;
    } else if ( document.body &&
                (document.body.clientWidth || document.body.clientHeight ) ) {
      windowx = document.body.clientWidth;
      windowy = document.body.clientHeight;
    } else {
      windowx = 1024;
      windowy = 768;
    }

    obj.href = obj.href + '&screenx='+screenx + '&windowx=' + windowx +
      '&screeny='+screeny + '&windowy=' + windowy;
  }
}

//Get current document size
function getDocSize() {
  var w = 0, h = 0;
  if(typeof(window.innerWidth) == 'number'){
    //Non-IE
    w = window.innerWidth;
    h = window.innerHeight;
  }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
    //IE 6+ in 'standards mode'
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
    //IE 4 compatible
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
  return {'width':w,'height':h};
}

function getScrollXY() {
	var sX = 0, sY = 0;
	if(typeof(window.pageYOffset)=='number'){
		//Non-IE
		sY = window.pageYOffset;
		sX = window.pageXOffset;
	}else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		//IE 6+ in 'standards mode'
		sY = document.documentElement.scrollTop;
		sX = document.documentElement.scrollLeft;
	}else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
		//IE 6 in 'strict mode' & some other browsers
		sY = document.body.scrollTop;
		sX = document.body.scrollLeft;
	}
	return {'x':sX,'y':sY};
}

/**
 * registerEvent - registers event handlers for objects
 */
function registerEvent(elem, event, callback, capture) {
	capture = capture || true;
	if ( event == 'allchange' ) {
		var types = ['change','click','keyup'];
		for(var i=0;i < types.length;i++){
			registerEvent(elem, types[i], callback, capture);
		}
		return;
	}
	elem = (typeof elem == 'object') ? elem : $(elem);
		
	if ( elem.addEventListener ) {
		elem.addEventListener(event, callback, capture);
	} else {
		elem.attachEvent('on'+event, callback);
	}
}

/**
 * createElement - Shortcut for document.createElement()
 * @param tag	string		TagName of the element to create
 */
function createElement(tag){ return document.createElement(tag); }

/**
 * fixEvent - Returns an event object with common properties/methods normalized for easier cross browser usage.
 * @param e		object	optional;Event object to normalize
 * @return		object	Event object after normalization
 */
function fixEvent(e){
	var evnt = e || window.event;
	if(!evnt.target){ evnt.target = evnt.srcElement; }
	evnt.preventDefault = (evnt.preventDefault)? evnt.preventDefault : function(){ this.returnValue = false; };
	evnt.stopPropagation = (evnt.stopPropagation)? evnt.stopPropagation : function(){ this.cancelBubble = true; }
	return evnt;
}


/*********************************************************/

/*********************************************************/


/**
 * $ - Shortcut for document.getElementById
 * @param id	string	ID of the element you want to retrieve
 * @return		object	Element object that matches the id
 */
function $(id){ return document.getElementById(id); }
/**
 * $n - Shortcut for document.getElementsByName
 * @param name	string		Name of the element(s) you want to retrieve
 * @return		collection	List of elements matching the name
 */
function $n(name, parent){ return (parent || document).getElementsByName(name); }
/**
 * $t - Shortcut for document.getElementsByTagName
 * @param tag	string		TagName of the element(s) you want to retrieve
 * @return		collection	List of elements matching the tag
 */
function $t(tag,parent){ return (parent || document).getElementsByTagName(tag); }
/**
 * next - Returns the next non-whitespace sibling element
 * @param	el	object	Element node from which to start
 * @return		object	Next non-whitespace child element
 */
function next(el) {
	if(!el || !el.nextSibling) { return null; }
	el=el.nextSibling;
	return (el.nodeType==1) ? el : next(el);
}
/**
 * prev - Returns the previous non-whitespace sibling element
 * @param	el	object	Element node from which to start
 * @return		object	Previous non-whitespace child element
 */
function prev(el) {
	if(!el || !el.previousSibling) { return null; }
	el=el.previousSibling;
	return (el.nodeType==1) ? el : prev(el);
}
/**
 * first - Returns the first non-whitespace child element
 * @param	el	object	Parent element node
 * @return		object	First non-whitespace child element
 */
function first(el) {
	if(!el || !el.firstChild) { return null; }
	el=el.firstChild;
	return (el.nodeType==1) ? el : next(el);
}
/**
 * last - Returns the last non-whitespace child element
 * @param	el	object	Parent element node
 * @return		object	Last non-whitespace child element
 */
function last(el) {
	if(!el || !el.lastChild) { return null; }
	el=el.lastChild;
	return (el.nodeType==1) ? el : prev(el);
}
/**
 * createElement - Shortcut for document.createElement()
 * @param tag	string		TagName of the element to create
 */
function createElement(tag){ return document.createElement(tag); }
/**
 * Array.indexOf - adds indexOf() support to browsers that don't have it.
 */
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj,start){
		var len = this.length;
		start = Number(start) || 0;
		start = (start < 0) ? Math.ceil(start) : Math.floor(start);
		if(start < 0){ start+= len; }
		for(;start < len;start++){
			if(start in this && this[start]===obj){ return start; }
		}
		return -1;
	}
}

var isIE = null;
function checkIE(){
	if(isIE == null){
		isIE = (isIE || /msie/i.test(navigator.appVersion) || window.attachEvent);
	}
	return isIE;
}

function hover(tab){
/* Removing AMA jank shim due to IE JS errors
	var shim = $('shim');
	if(checkIE() && shim){
		var list = $t('ul',tab)[0];
		if(list){
			var lprnt = list.parentNode, lstyle=list.currentStyle;
			lprnt.insertBefore(shim, list);
			var props = ['top','left','width','height','padding'];
			for(var i=0;i < props.length;i++){
				shim.style[props[i]] = lstyle[props[i]];
			}
			shim.style.width = (parseInt(shim.style.width,10)+2)+'px';
			
			var items = $t('li',list), newheight=0;
			for(i=0;i < items.length;i++){
				newheight += 28;
			}
			newheight++;
			var superparent = (lprnt.parentNode && lprnt.parentNode.parentNode) ? lprnt.parentNode.parentNode : (lprnt.parentNode ? lprnt.parentNode : lprnt);
			if (superparent && superparent.id != 'nav') {
				newheight += (3*items.length) +1;
			}
			if(!/msie 7\.0/i.test(navigator.appVersion) && superparent && superparent.id == 'nav'){
				newheight += 20;
			}
			shim.style.height = newheight+'px';
			
			shim.style.display = '';
		}
	}
*/
	if(!/hover/i.test(tab.className)){
		tab.className += ' hover';
	}
}
function hoveroff(tab){
	var shim = $('shim');
/*	Removing AMA jank shim due to IE JS errors
 	if(checkIE() && shim){
		shim.style.display = 'none';
	}
*/
	tab.className = tab.className.replace(/\s?hover\s?/i,'');
}


/*****************************************************************/
// Header nav
function domLoader(){}
domLoader.isReady = false;
domLoader.timer = null;
domLoader.queue = [];
domLoader.register = function(fn){
	var self = this;
	if(this.isReady){ return fn(); }
	else if(!this.timer){
		registerEvent(window,'load', function(){ self.checkDom(); });
		this.timer = setInterval(function(){ self.checkDom(); },13);
	}
	this.queue.push(fn);
};
domLoader.checkDom = function(){
	if(this.isReady){ return true; }
	if(document && document.getElementById && document.getElementsByTagName && document.body){
		clearInterval(this.timer);
		for(var i=0;i < this.queue.length;i++){
			this.queue[i]();
		}
		this.timer = null;
		this.queue = [];
		this.isReady = true;
		return true;
	}
	return false;
}
/* Check for IE and create the shim iframe if neccessary */
domLoader.register(function(){
	isIE = checkIE();
	if(isIE){
		var head = $('header');
		if(!head){ return; }
		/*  Removing AMA jank shim due to IE JS errors
		var shim = createElement('iframe');
		var atbs = {'id':'shim','frameBorder':0,'scrolling':'no','src':''};
		for(var atb in atbs){
			shim[atb] = atbs[atb];
		}
		var css={'opacity':0,'filter':'alpha(opacity=0)','position':'absolute','top':0,'left':0,'zIndex':3,'display':'none'};
		for(var prop in css){
			shim.style[prop] = css[prop];
		}
		head.insertBefore(shim, head.firstChild);
		*/
	}
});

