﻿function addLoadEvent(func) {  var oldonload = window.onload; 
if (typeof window.onload != 'function') {   
window.onload = func; 
 }  
else {    
window.onload = function() {     
oldonload(); 
func();   
 } 
 } 
 }  

addLoadEvent(prepareGallery);
addLoadEvent(preparePlaceholder);
addLoadEvent(insert_copyright_date);
addLoadEvent(preloadimages);


function insert_copyright_date(){
var today=new Date();
var copy_year=today.getFullYear();
var x = document.createTextNode(copy_year);
document.getElementById('copyright_date').appendChild(x);
}


function preparePlaceholder() {
 if (!document.createElement) return false;
 if (!document.createTextNode) return false;
 if (!document.getElementById) return false;
 if (!document.getElementById("imagegallery")) return false;
var placeholder = document.createElement("img");
placeholder.setAttribute("id","placeholder");
placeholder.id="placeholder";
placeholder.setAttribute("src","NC_portfolio.fol/placeholder.jpg");
placeholder.setAttribute("alt","my image gallery");
var gallery = document.getElementById("imagegallery");
insertAfter(placeholder,gallery);
var caption = document.createElement("p");
caption.id="info";
caption.setAttribute("id","info");
var desctext = document.createTextNode("Choose an image");
caption.appendChild(desctext);
insertAfter(caption,placeholder);
}


function prepareGallery() { 
if (!document.getElementsByTagName) return false;  
if (!document.getElementById) return false; 
if (!document.getElementById("imagegallery")) return false;  
var gallery = document.getElementById("imagegallery"); 
var links = gallery.getElementsByTagName("a");
for ( var i=0; i < links.length; i++) {   
links[i].onclick = function() {	
return showPic(this);	
}
links[i].onkeypress = links[i].onclick;  
}
}

function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.href;
var placeholder = document.getElementById("placeholder");
  placeholder.src=source;
  if (!document.getElementById("info")) 
  return false;
if (whichpic.title) {
    var text = whichpic.title;
  } else {
    var text = "";
}
  var caption = document.getElementById("info");
  if (caption.firstChild.nodeType == 3) {
    caption.firstChild.nodeValue = text;
  }
  return false;
}


function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function preloadimages(){
if (!document.images) {
return;
}
myimages=new Array("NC_thumbnails.fol/thm1.jpg", "NC_thumbnails.fol/thm2.jpg", "NC_thumbnails.fol/thm3.jpg", "NC_thumbnails.fol/thm4.jpg", "NC_thumbnails.fol/thm5.jpg", "NC_thumbnails.fol/thm6.jpg", "NC_thumbnails.fol/thm7.jpg", "NC_thumbnails.fol/thm8.jpg", "NC_thumbnails.fol/thm9.jpg", "NC_thumbnails.fol/thm10.jpg", "NC_thumbnails.fol/thm11.jpg", "NC_thumbnails.fol/thm12.jpg", "NC_thumbnails.fol/thm13.jpg", "NC_thumbnails.fol/thm14.jpg", "NC_thumbnails.fol/thm15.jpg", "NC_thumbnails.fol/thm16.jpg", "NC_thumbnails.fol/thm17.jpg", "NC_thumbnails.fol/thm18.jpg", "NC_thumbnails.fol/thm19.jpg", "NC_thumbnails.fol/thm20.jpg", "NC_thumbnails.fol/thm21.jpg", "NC_thumbnails.fol/thm22.jpg", "NC_thumbnails.fol/thm23.jpg", "NC_thumbnails.fol/thm24.jpg", "NC_thumbnails.fol/thm25.jpg", "NC_thumbnails.fol/thm26.jpg", "NC_thumbnails.fol/thm27.jpg", "NC_thumbnails.fol/thm28.jpg", "NC_thumbnails.fol/thm29.jpg", "NC_thumbnails.fol/thm30.jpg", 
"NC_thumbnails.fol/thm31.jpg", "NC_portfolio.fol/pic1.jpg", "NC_portfolio.fol/pic2.jpg", "NC_portfolio.fol/pic3.jpg", "NC_portfolio.fol/pic4.jpg", "NC_portfolio.fol/pic5.jpg", "NC_portfolio.fol/pic6.jpg", "NC_portfolio.fol/pic7.jpg", "NC_portfolio.fol/pic8.jpg", "NC_portfolio.fol/pic9.jpg", "NC_portfolio.fol/pic10.jpg", "NC_portfolio.fol/pic11.jpg", "NC_portfolio.fol/pic12.jpg", "NC_portfolio.fol/pic13.jpg", "NC_portfolio.fol/pic14.jpg", "NC_portfolio.fol/pic15.jpg", "NC_portfolio.fol/pic16.jpg", "NC_portfolio.fol/pic17.jpg", "NC_portfolio.fol/pic18.jpg", "NC_portfolio.fol/pic19.jpg", "NC_portfolio.fol/pic20.jpg", "NC_portfolio.fol/pic21.jpg", "NC_portfolio.fol/pic22.jpg", "NC_portfolio.fol/pic23.jpg", "NC_portfolio.fol/pic24.jpg", "NC_portfolio.fol/pic25.jpg", "NC_portfolio.fol/pic26.jpg", "NC_portfolio.fol/pic27.jpg", "NC_portfolio.fol/pic28.jpg", "NC_portfolio.fol/pic29.jpg", "NC_portfolio.fol/pic30.jpg", "NC_portfolio.fol/pic31.jpg")
for (i=0;i<myimages.length;i++){
myimages[i]=new Image();
myimages[i].src=myimages[i];
}
}





