window.onload = choosePic;
var my_div = null;
var newDiv = null;
var thisAd = 0;
var adImages = new Array("ImagesInDatabase/2360_Photo3_800.jpg","ImagesInDatabase/2360_Photo4_900.jpg","ImagesInDatabase/2360_Photo5_300.jpg","ImagesInDatabase/2360_Photo1_800.jpg","ImagesInDatabase/2360_Photo6_300.jpg","ImagesInDatabase/2360_Photo7_2500.jpg","ImagesInDatabase/2360_Photo8_700.jpg","ImagesInDatabase/2360_Photo9_2500.jpg","ImagesInDatabase/2360_Photo10_1900.jpg","ImagesInDatabase/2360_Photo18_2800.jpg","ImagesInDatabase/2360_Photo11_2500.jpg","ImagesInDatabase/2360_Photo12_1900.jpg","ImagesInDatabase/2360_Photo13_1900.jpg","ImagesInDatabase/2360_Photo14_1900.jpg","ImagesInDatabase/2360_Photo15_1900.jpg","ImagesInDatabase/2360_Photo16_200.jpg","ImagesInDatabase/2360_Photo17_800.jpg","ImagesInDatabase/2360_Photo18_900.jpg","ImagesInDatabase/2360_Photo19_1900.jpg");
function choosePic() {
// generate a table
generate_table();
// insert an anchor after the new table
insertAfter();
thisAd = Math.floor((Math.random() * adImages.length));
rotate();
// call a marquee function
addElement();
}
function rotate() {
thisAd++;
if (thisAd == adImages.length) {
thisAd = 0;
}
if(document.getElementById("adBanner") === null) return false;
document.getElementById("adBanner").src = adImages[thisAd];
setTimeout("rotate()", 3 * 1000);
}
function addElement() {
// add a marquee style
// find a h1 elements
var x = document.getElementsByTagName("h1")[0];
var y = document.getElementsByTagName("td")[11];
y.setAttribute('id','org_h1');
// create a new div element
// and give it some content
newDiv = document.createElement("marquee");
newContent = document.createTextNode("For more information go to www.cottageparadise.ca");
newDiv.appendChild(newContent); //add the text node to the newly created div.
// add the newly created element and it's content into the DOM
my_div = document.getElementById("org_h1");
my_div.insertBefore(newDiv, x);
}
function blockAdblockUser() {
if(document.getElementById('myTestAd')) {
var h = document.getElementById('myTestAd').clientHeight;
// check if the adBlock is turn on
if(h == 0) {
// remove parts and hide the html and the js tables
RemoveHtmlTable()
// call a new table without any rotations
generate_static_table();
}
}
}
function generate_table() {
// get the reference for the body (table row in that case)
var body = document.getElementsByTagName("td")[15];
// creates a <table> element and a <tbody> element
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
// creates a table row
var row = document.createElement("tr");
// sets the bgcolor attribute to the row;
row.setAttribute("bgcolor", "#CCCCCC");
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
// sets the bgcolor attribute to the cell;
cell.setAttribute("bordercolor", "#000000");
var div = document.createElement("div");
// sets the id attribute to the myTestAd div;
div.setAttribute("id", "myTestAd");
// creates an anchor element
var a = document.createElement("a");
//sets the href attribute
a.setAttribute("href", "Photos.cfm?PhotosID=2360");
var img = document.createElement("img");
a.appendChild(img);
div.appendChild(a);
cell.appendChild(div);
row.appendChild(cell);
// add the row to the end of the table body
tblBody.appendChild(row);
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the attributes of tbl;
tbl.setAttribute("cellpadding", "10");
tbl.setAttribute("bgcolor", "#666666");
//sets the attributes of image
img.setAttribute("src", "ImagesInDatabase/2360_Photo3_800.jpg");
img.setAttribute("id", "adBanner");
img.setAttribute("width", 300);
img.setAttribute("height", 200);
img.setAttribute("align", "top");
img.setAttribute("border", 2);
img.setAttribute("alt", "Trent Hills' Piece of Paradise");
blockAdblockUser();
RemoveHtmlTable();
}
function generate_static_table() {
// get the reference for the body (table row in that case)
var body = document.getElementsByTagName("td")[15];
// creates a <table> element and a <tbody> element
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
// creates a table row
var row = document.createElement("tr");
// sets the bgcolor attribute to the row;
row.setAttribute("bgcolor", "#CCCCCC");
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
// sets the bgcolor attribute to the cell;
cell.setAttribute("bordercolor", "#000000");
// creates an anchor element
var a = document.createElement("a");
//sets the href attribute
a.setAttribute("href", "Photos.cfm?PhotosID=2360");
var img = document.createElement("img");
a.appendChild(img);
cell.appendChild(a);
row.appendChild(cell);
// add the row to the end of the table body
tblBody.appendChild(row);
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the attributes of tbl;
tbl.setAttribute("cellpadding", "10");
tbl.setAttribute("bgcolor", "#666666");
//sets the href attribute
img.setAttribute("src", "ImagesInDatabase/2360_Photo3_800.jpg");
img.setAttribute("width", 300);
img.setAttribute("height", 200);
img.setAttribute("align", "top");
img.setAttribute("border", 2);
img.setAttribute("alt", "Trent Hills' Piece of Paradise");
// stop the script
return false;
}
function RemoveHtmlTable() {
// get the reference for the body (parent table row in that case)
var parent = document.getElementsByTagName("td")[15];
var child_t = parent.getElementsByTagName("table")[0];
var throwawayNode = parent.removeChild(child_t);
}
function insertAfter() {
var parent = document.getElementsByTagName("td")[15];
var tbl = parent.getElementsByTagName("table")[0];
var anchors = document.getElementsByTagName("A");
for (var i = 0; i < anchors.length; i++) {
if (anchors[i].className == 'highlight') {
parent.insertBefore(anchors[i], tbl.nextSibling);
}
}
}