function $(id) { return document.getElementById(id) }
var browser = {ff: navigator.userAgent.indexOf('Firefox') != -1, ie: document.attachEvent != null, safari: navigator.userAgent.indexOf('Safari') != -1};

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function fade(elem, from, to, time)
{
	var WAIT = 50, delta = ((to-from) * WAIT) / (1000*time);
	if (elem.fadeTO != null) clearTimeout(elem.fadeTO);
	_fade(elem, from, to, delta, WAIT);
	
	function _fade(elem, from, to, delta, wait) {
		var e = elem;//javascript fails to keep elem param seperate between closures ...? so manually create local variable
		if ((delta<0 && from < to) || (delta>0 && from > to)){
			setOpacity(e, to);//make sure opacity finishes on to value
			return;
		}

		setOpacity(e, from);
		e.fadeTO = setTimeout(function(){_fade(e, from+delta, to, delta, wait);}, wait);
	}
}

function setOpacity(elem, val) {
	if (browser.ie) elem.style.filter  = "alpha(opacity=" + parseInt(val) + ")";
	else elem.style.opacity = val / 100;
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}