// RIL1.0 :: Random image link
// ***********************************************
// DOM scripting by brothercake -- https://www.brothercake.com/
// Original concept by Andy Clarke -- https://www.stuffandnonsense.co.uk/
// Create element and attributes based on a method by beetle -- https://www.peterbailey.net/
//************************************************
//open initialisation function
function randomImageLink() { 
//************************************************



/*****************************************************************************
 Define image links
*****************************************************************************/

// This is the button for the bottom left section.

//identify an image link ('link-id')
var button = new imageLink('bl-button');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')

button.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=category_view&target=11000', '', 'https://www.canadianwoodworker.com/wood/wp-content/themes/woodworker/images/bottom_left_CMT.jpg', '211', '188', '');

button.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=DEWALT&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_left_DEWALT.jpg', '211', '188', '');



	//select a possibility at random
	button.selectLink();


// This is the button for the bottom right section.

//identify an image link ('link-id')
var button4 = new imageLink('br-button');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')

button4.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=excalibur&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_right_excalibur.jpg', '180', '442', '');

button4.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=magswitch&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_right_magswitch.jpg', '180', '442', '');



	//select a possibility at random
	button4.selectLink();


// This is the button for the top right section.

//identify an image link ('link-id')
var button3 = new imageLink('tr-button');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')

button3.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/top_right_benchdog.jpg', '206', '295', '');

button3.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/top_right_tormek.jpg', '206', '295', '');

button3.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=woodpecker&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/top_right_woodpecker.jpg', '206', '295', '');



	//select a possibility at random
	button3.selectLink();





// This is the button for the top banner section.

var button1 = new imageLink('tb-button');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')


// 1
button1.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/top_banner_benchdog.jpg', '645', '114', '');

// 2
button1.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/top_banner_trend.jpg', '645', '114', '');

// 3
button1.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=wixey&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/top_banner_wixey.jpg', '645', '114', '');




	//select a possibility at random
	button1.selectLink();



// This is the button for the pther centre section.

var button2 = new imageLink('cb-button');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')   

// 1 
button2.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/centre_panasonic.jpg', '434', '293', '');

// 2 
button2.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/centre_trend.jpg', '434', '293', '');

// 3
button2.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=woodpecker&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/centre_woodpecker.jpg', '434', '293', '');






	//select a possibility at random
	button2.selectLink();


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

var button5 = new imageLink('sidebar_banner1');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')   

// 1 
button5.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_left_Byrd.jpg', '211', '188', '');

// 2 
button5.addLink('https://www.canadianwoodworker.com/webstore/wecs.php?store=&action=searchadvanced&advancedsearch_include_description=1&advancedsearch_words=dewalt&Submit=Submit', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_left_DEWALT.jpg', '211', '188', '');






	//select a possibility at random
	button5.selectLink();


var button6 = new imageLink('sidebar_banner2');

//add possibilities ('href', 'title text', 'src', 'width', 'height', 'alt text')   

// 1 
button6.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_left_Byrd.jpg', '211', '188', '');

// 2 
button6.addLink('https://www.canadianwoodworker.com/webstore/wecs.php', '', 'https://www.canadianwoodworker.com/wood/wp-content/uploads/bottom_left_DEWALT.jpg', '211', '188', '');







	//select a possibility at random
	button6.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(); }
