function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

function FS_jumpMenuWinSize(targ,selObj,restore){ //v1.0
 if (selObj.options[selObj.selectedIndex].value == '' || selObj.options[selObj.selectedIndex].value == null) return false;
 var params = selObj.options[selObj.selectedIndex].value.split(",");
 var wd = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes';
 wd = 'toolbar=yes,location=yes,directories=ys,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes'; // no options
 if (params[1]) wd += ',width='+params[1];
 if (params[2]) wd += ',height='+params[2];
 window.open(params[0], targ, wd);
 if (restore) selObj.selectedIndex=0; 
} 

function MM_jumpMenu(targ,selObj,restore){ //v3.0 
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
 if (restore) selObj.selectedIndex=0; 
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// Flips the display of an object
function flipDisplay(layerID)
{ 
  var visStr, obj;
  if ((obj = MM_findObj(layerID)) != null)
  {
    if (obj.style)
    {
      obj = obj.style;
      obj.display = (obj.display == 'none') ? 'block' : 'none';
	  return obj.display;
	}
  }
}

function showElement(elm) {
	elm = E(elm);
	if (elm.style) elm.style.display = '';
}

function hideElement(elm) {
	elm = E(elm);
	if (elm.style) elm.style.display = 'none';
}


// Flips the display of an object and swaps an image at the same time
function flipExpand(LayerID,ImageID,ImgVisSrc, ImgHidSrc)
{
	if (flipDisplay(LayerID) == 'none') {
		switchImage(ImageID,ImgHidSrc);
	} else {
		switchImage(ImageID,ImgVisSrc);
	}
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function dbt_bookmark(targetURL,service) {
	//URL of this document
	if(!service) service='delicious';
	var loc=(targetURL && targetURL.length>0?targetURL:location.href);
	//Strip out any anchors
	var apos=loc.indexOf('#');
	loc=encodeURIComponent((apos>0?loc.substring(0,apos):loc));
	
	//Get Title and encode
	var title = encodeURIComponent(document.title); 
	
	var url='';
	
	//Redirect to service
	if(service=='digg') url='http://www.digg.com/submit?phase=2&url=' + loc + '&title=' + title;
	else if(service=='newsvine') url='http://www.newsvine.com/_tools/seed&save?u=' + loc + '&h=' + title;
	else if(service=='furl') url='http://www.furl.net/storeIt.jsp?p=1&u='+ loc +'&t=' + title;
	else if(service=='blinklist') url='http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=' + loc + '&Title=' + title;
	else if(service=='facebook') url='http://www.facebook.com/share.php?u=' + loc+ '&t=' + title;
	else if(service=='myspace') url='http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + title + '&u=' + loc + '&l=3';
	else if(service=='google') {
		var d=window.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+loc+"&title="+title,"bkmk_popup","left="+((window.screenX||window.screenLeft)+10)+",top="+((window.screenY||window.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");
		window.setTimeout(function(){d.focus()},300);
	} else 	url='http://del.icio.us/post?v=2&url=' + loc + '&amp;title=' + title;

	if (service!='google') location.href = url;
	return false;
}

function higlightExternalLinks() {
	// add class 'external' to all external links
	var localhost = false;
	if (window.location) {
		localhost = window.location.hostname;
	}
	if (!localhost) return false;	// if we cant get the local host exit
	if (document.getElementsByTagName && document.getElementById) {
		var content = document.getElementById('maincontent');
		if (content) {
			var links = content.getElementsByTagName('a'); // only links inside 'maincontent'
			for (i=0; i<links.length; i++) {
				if (links[i].hostname != localhost && links[i].hostname != '' && links[i].hostname != 'www.addthis.com' && !(downElement(links[i]) && downElement(links[i]).nodeName == "IMG")) {
					addClass(links[i],'external');
				}
			}
		}
	}
}

addLoadEvent(higlightExternalLinks);

/******************
		DOM Helpers
*******************/

function nextElement(elm,n) {
	n=n||0;
	elm = E(elm)
	if (!elm) return null;
	do { 
		elm = elm.nextSibling; 
		if (elm && elm.nodeType == 1) n--;
	}	while (elm && n>=0);
	return elm;
}

function previousElement(elm,n) {
	n=n||0;
	elm = E(elm)
	if (!elm) return null;
	do {
		elm = elm.previousSibling; 
		if (elm && elm.nodeType == 1) n--;
	}	while (elm && n>=0);
	return elm;
}

function downElement(elm,n) {
	n=n||0;
	elm = E(elm)
	if (!elm) return null;
	do {
		elm = elm.firstChild; 
		if (elm && elm.nodeType == 1) n--;
	}	while (elm && n>=0);
	return elm;
}

function upElement(elm,n) {
	n=n||0;
	elm = E(elm)
	if (!elm) return null;
	do {
		elm = elm.parentNode; 
		if (elm && elm.nodeType == 1) n--;
	}	while (elm && n>=0);
	return elm;
}

function E(elm) {
	return elm =  (typeof elm == 'string') ? ((document.getElementById) ? document.getElementById(elm) : null) : elm;
}

/******************
		CSS Helpers
*******************/

function hasClass(elm,v) {
	elm = E(elm)
	return elm.className.match(new RegExp('(\\s|^)'+v+'(\\s|$)'));
}

function addClass(elm,v) {
	elm = E(elm)
	if (!hasClass(elm,v)) elm.className += (elm.className) ? " "+v : v;
}
 
function removeClass(elm,v) {
	elm = E(elm)
	if (hasClass(elm,v))	elm.className=elm.className.replace(new RegExp('(\\s|^)'+v+'(\\s|$)'),' ');
}

function getElementsByClassName(className,container,tag) {
	var m=[];
	c=container||document; 	// default container to document
	tag=tag||'*';		// default tag to *
	if (c.getElementsByTagName) {
		var elms = c.getElementsByTagName(tag);	// find tags in container
		for (i=0; i<elms.length; i++) {
			if (hasClass(elms[i],className)) m.push(elms[i]); // collect for class
		}
	}
	return m;
}

/******************

	window load and unload helpers
		
*******************/

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

function addUnloadEvent(func) {
	// Allow multiple unloaders
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
			window.onunload = function() {
				oldonunload();
				func();
			}
	}
}
