// RIL1.0 :: Random image link
// ***********************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// Original concept by Andy Clarke -- http://www.stuffandnonsense.co.uk/
// Create element and attributes based on a method by beetle -- http://www.peterbailey.net/
//************************************************
//open initialisation function
function randomImageLink() { 
//************************************************



/*****************************************************************************
 Define image links
*****************************************************************************/


//identify an image link ('link-id')
var button = new imageLink('imagerotate');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')
button.addLink('https://secure2.convio.net/choice/site/Donation2?idb=1830089031&df_id=1741&1741.donation=form1', 'Make a donation', 'http://www.prochoiceamerica.org/assets/wrapper-graphics/button01b.gif', '266', '100', 'Make a donation');
button.addLink('https://secure2.convio.net/choice/site/Donation2?df_id=1575&amp;1575.donation=form1', 'Monthly giving', 'http://www.prochoiceamerica.org/assets/wrapper-graphics/button02b.gif', '266', '100', 'Monthly giving');
button.addLink('https://secure2.convio.net/choice/site/Donation2?idb=1980345771&df_id=1726&1726.donation=form1', 'Renew your membership', 'http://www.prochoiceamerica.org/assets/wrapper-graphics/button04b.gif', '266', '100', 'Renew your membership');
//button.addLink('https://secure.ga0.org/02/statebans_web', 'Stop state abortion bans', 'http://www.prochoiceamerica.org/assets/graphics/statebans_hp.gif', '266', '100', 'Stop state abortion bans');

//select a possibility at random
button.selectLink();

//identify an image link ('link-id')
var button2 = new imageLink('imagerotate2');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')
button2.addLink('https://secure2.convio.net/choice/site/Donation2?idb=1830089031&df_id=1741&1741.donation=form1', 'Make a donation', 'http://www.prochoiceamerica.org/assets/wrapper-graphics/button01bsmall.gif', '174', '100', 'Make a donation');
button2.addLink('https://secure2.convio.net/choice/site/Donation2?df_id=1575&amp;1575.donation=form1', 'Monthly giving', 'http://www.prochoiceamerica.org/assets/wrapper-graphics/button02bsmall.gif', '174', '100', 'Monthly giving');
button2.addLink('https://secure2.convio.net/choice/site/Donation2?idb=1980345771&df_id=1726&1726.donation=form1', 'Renew your membership', 'http://www.prochoiceamerica.org/assets/wrapper-graphics/button04bsmall.gif', '174', '100', 'Renew your membership');

//select a possibility at random
button2.selectLink();


/*****************************************************************************
*****************************************************************************/



//close initialisation function
};




//image link constructor
function imageLink(linkid)
{
	//set link object
	this.link = document.getElementById(linkid);
	
	//create an empty array of possible links
	this.possibles = [];
};


//add a possibility 
imageLink.prototype.addLink = function()
{
	//store arguments in possible links array
	this.possibles[this.possibles.length] = arguments;
};


//select a possibility at random 
imageLink.prototype.selectLink = function()
{
	//if the link exists
	if(this.link != null)
	{
		//get a random item from the array
		this.rnd = this.possibles[Math.floor(Math.random() * this.possibles.length)];
		
		//set new link attributes 
		this.link.href = this.rnd[0];
		this.link.title = this.rnd[1];
		
		//get image object inside it
		this.img = this.link.getElementsByTagName('img')[0];
		
		//if it exists
		if(this.img != null)
		{
			//set new image attributes
			this.img.src = this.rnd[2]; 
			this.img.width = this.rnd[3]; 
			this.img.height = this.rnd[4]; 
			this.img.alt = this.rnd[5]; 
		}
	}
};


//call initialisation function if supported
if(typeof document.getElementById != 'undefined') { randomImageLink(); }
