var av = {
// array of embedded links to google videos
// new entries must be added at the BEGINNING of the array
jsText : ["",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""],
// reference to the div holding the current video
mediaContent : document.getElementById("mediaDiv"),
init : function() {
if (!document.getElementsByTagName) { return; }
this.util.configEvents();
// pinpoints the list of video links
this.listItem = document.getElementById('award_video_list');
// loads the most current video to the page
av.mediaContent.innerHTML = av.jsText[0];
//event delegation
this.util.addEvent(this.listItem, 'click', this.switchVideo, false);
},
switchVideo : function(evt) {
var videoLink = av.util.findTarget(evt, 'a', this);
// return if an anchor tag was not selected
if (!videoLink){return;}
// reference to a node list of video links
var linkList = av.listItem.getElementsByTagName('a');
var allLinks = linkList.length;
// assign a number value to each link in the video link list
for( var i=0; i< allLinks; i++){
linkList[i].number = i;
}
// determine the number value of the link clicked and find the corresponding number in the jsText array
for (var i=0; i< allLinks; i++){
// once a match is found, the content of the div holding the video is replaced with the object tag for the newly chosen video
if (videoLink === linkList[i]){
av.mediaContent.innerHTML = av.jsText[i];
}
}
},
util : {
configEvents : function() {
if (document.addEventListener) {
this.addEvent = function(el, type, func, capture) {
el.addEventListener(type, func, capture);
};
this.stopBubble = function(evt) { evt.stopPropagation(); };
this.stopDefault = function(evt) { evt.preventDefault(); };
this.findTarget = function(evt, targetNode, container) {
var currentNode = evt.target;
while (currentNode && currentNode !== container) {
if (currentNode.nodeName.toLowerCase() === targetNode) {
return currentNode; break;
}
else { currentNode = currentNode.parentNode; }
};
return false;
};
}
else if (document.attachEvent) {
this.addEvent = function(el, type, func) {
el["e" + type + func] = func;
el[type + func] = function() { el["e" + type + func] (window.event); };
el.attachEvent("on" + type, el[type + func]);
};
this.stopBubble = function(evt) { evt.cancelBubble = true; };
this.stopDefault = function(evt) { evt.returnValue = false; };
this.findTarget = function(evt, targetNode, container) {
var currentNode = evt.srcElement;
while (currentNode && currentNode !== container) {
if (currentNode.nodeName.toLowerCase() === targetNode) {
return currentNode; break;
}
else { currentNode = currentNode.parentNode; }
};
return false;
};
}
},
insertAfter : function(parent, nodeToInsert, referenceNode) {
parent.insertBefore(nodeToInsert, referenceNode.nextSibling);
}
}
}
av.init();