/*
 * date:	2002-10-11
 * info:	http://inspire.server101.com/js/tp/
 */

var tp = [];
var tpl = [];

function tpSet(i, c) {
if (document.createElement) {
	var e = document.getElementById(i);
	//create unordered list for tab headers
	var l = document.createElement('ul');
	//p: a Div for the tab titles
	var p = document.createElement('div');
	e.className = l.className = p.className = c;

	var a, j, t;
	//extra arguments contain 'tp1', 'tp2', 'tp3'
	for (j = 2; j < arguments.length; j++) {
		c = document.getElementById(t = arguments[j]);
		//remove each tab div from tpeg
		tp[t] = c.parentNode.removeChild(c);

		//add a list item for each tab header
		a = l.appendChild(document.createElement('li'));
		a.className = c.className;
        // create an a for each tab header containing javascript to show tab
		tpl[t] = a = a.appendChild(document.createElement('a'));
		a.setAttribute('href', 'javascript:tpShow(\''+i+'\', \''+t+'\');');
	
		if (t == 'tp1')
		{
		    a.setAttribute('title', 'Counties ranked by value of pledges');
		}
		else if (t == 'tp2')
		{
		    a.setAttribute('title', 'Most popular pledges by number made');
		}
		else
		{
		    a.setAttribute('title', 'Most popular pledges by value of pledge');
		}
		
		
		//a.setAttribute('title', c.getAttribute('title'));
		//Use the Div title for the link text e.g. 'Top Counties'
		//if ()
		a.appendChild(document.createTextNode(c.getAttribute('title')));
	}
	
	//Add tp1 div as child of the tab titles 
	p.appendChild(tp[arguments[2]]);
	tpl[arguments[2]].className = 'active';

	//remove previously added elements
	while (e.firstChild) e.removeChild(e.firstChild);
	e.appendChild(l);
	e.appendChild(p);
}}


function tpShow(e, p) {
	//e is javascript link text
	e = document.getElementById(e).lastChild;
	//If className = 'active div is visible' otherwise not
	tpl[e.replaceChild(tp[p], e.firstChild).getAttribute('id')].className = null;
//	alert(tpl[p]);
	tpl[p].className = 'active';
}

/////// IMAGE SWAP ///////
// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 
function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}
