
//This way is no good, use the method just below this -Huy
/* 
addLoadEvent(prepareGallery);
addLoadEvent(showMenu);
addLoadEvent(showText);
//addLoadEvent(showPic);
*/



/* this function stinks: use the one above -Huy */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function showText(){
   var links = getElementsByClassName(document, "a", 'open_win');
   for(var l in links){
      links[l].onclick = function(){ 
          var sec = this.getAttribute('id').split('_')[1];
          var content_block = document.getElementById('content_'+sec).innerHTML;
          var content_holder = document.getElementById('content_holder');
          content_holder.innerHTML = content_block;
          return false;
      }
   }
}

function showMenu(){
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("ul_nav");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
               node.onmouseover=function() {
                   this.className+=" over";
               }
               node.onmouseout=function() {
                   this.className=this.className.replace(" over", "");
               }
             }
         }
    }
}

function prepareGallery(){
  var gal = getElementsByClassName(document, "div","picarea");
  for (var g in gal){
      links = gal[g].getElementsByTagName("a");
      for(i=0; i < links.length; i++){
        links[i].onmouseover = function(){
            image = this.firstChild;
            opacityFadeIn();
        }
        links[i].onmouseout = function(){
            image = this.firstChild;
            opacityFadeOut();
        }
      }
  }
    function opacityFadeIn(){
        if (!image.currentOpacity) image.currentOpacity = 50;
        opacity(image, image.currentOpacity, 100, 12, 50, 1);
    }
    function opacityFadeOut(){
        if (!image.currentOpacity) return;
        opacity(image, image.currentOpacity, 50, 12, 50, 1);
    }
}

function opacity( image, opacStart, opacEnd, steps, intervals, powr){
    if (image.fading) window.clearInterval(image.fading);
    var thisStep = 0;
    image.fading = window.setInterval(
        function(){
            image.currentOpacity =  easeInOut( opacStart, opacEnd, steps, thisStep, powr);
            image.style.opacity = (image.currentOpacity / 100);
            image.style.MozOpacity = (image.currentOpacity / 100);
            image.style.KhtmlOpacity = (image.currentOpacity / 100);
            image.style.filter = "alpha(opacity=" + image.currentOpacity + ")";
            thisStep++;
            if (thisStep > steps) window.clearInterval(image.fading);
        }
    , intervals)
     
}
function easeInOut( opacStart, opacEnd, steps, thisStep, powr ){
     var NumDifference = opacEnd - opacStart;
     var increaseStepAmt = opacStart + (Math.pow((( 1 / steps ) * thisStep), powr ) * NumDifference );
     return Math.ceil(increaseStepAmt);
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}



