// PUT TOGETHER BY M HAYNES, JAN 2006

// Kick it all off!
function loadup(){

    // Find out IE version ########################################################        
    
    var browser = "";
    
    if (navigator.appName == "Microsoft Internet Explorer")
        {
            var detect = navigator.userAgent.toLowerCase();
            var thestring;
            var version = 0;

            if (checkIt('msie')) 
                {            
                    browser += detect.substr(place + thestring.length,3);
                }
        }

    function checkIt(string)
        {
            place = detect.indexOf(string) + 1;
            thestring = string;
            return place;
        }
    // ############################################################################
    


    if (browser >= 6 || browser == "") { // Only if IE is above 6, earlier versions suck.
    
        // Check if Browser is Compatible, do we support DOM?
        if (document.getElementById &&
        document.createTextNode && document.createElement){

            makeClickables('clickable', 'a'); // Put functions on .clickable <a> tags 
            hideDivs('hidden','div');   // Hide 'hidden' divs
            hideDivs('BackToTop', 'a'); // Hide back to top links.
            doCustomChanges();

            // Check for 'anim' URL parameter passed from interlinking trader / metals page
            if (anim != 'null') {changeit(anim);scroll(0,0);}
        }    
    
    } 
}


// Hide elements of the specified class !!
function hideDivs(thisClass, thisTag) {
    if (!document.getElementsByTagName) return false; {
      var hides = document.getElementsByTagName(thisTag);
      for (var h=0; h < hides.length; h++) {
          if (hides[h].className.match(thisClass)) {
                hides[h].style.display = "none";
                }
        }
    }
}

// Various stuff that needs changing and has nowehere else better to go!
function doCustomChanges() {
    document.getElementById('update').style.display = "block"; // Turn on the update div for rollover stuff
    document.getElementById('cover').style.display = "block"; // Turn on cover div.

    // Change the update div to have the content of the 1st 'hidden' div.
    var WhatToChange = document.getElementsByTagName('div');

    for (var wtc=0; wtc < WhatToChange.length; wtc++) {
         if (WhatToChange[wtc].className.match('hidden')) {
                document.getElementById('update').innerHTML = document.getElementById(WhatToChange[wtc].id).innerHTML;
                wtc = 10000; // Kill the loop         
        }
    }
}    


// Put specified functions onto tags with the selected class
function makeClickables(thisClass, thisTag) {
if (!document.getElementsByTagName) return false;

  var links = document.getElementsByTagName(thisTag);

  for (var i=0; i < links.length; i++) {
    if (links[i].className.match(thisClass)) {
    // Change href   
        links[i].href= "javascript:changeit('"+links[i].id+"-content')";

    // Onclick
        links[i].onclick = function() {
                changeit(this.id+"-content");
      }
  
    // Onkeypress
        links[i].onkeypress = function() {
                changeit(this.id+"-content");
      }
    }
  }
}

// Change whatever needs changing!
function changeit(what){
    document.getElementById('update').style.top = "-600px";
    document.getElementById('update').innerHTML = document.getElementById(what).innerHTML;
    opacity('update', 0, 100, 500);
}


function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 40); // Play about with this it make a difference!!
    var timer = 0; 
    
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
        
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 

    object.opacity = (opacity / 50); 
    object.MozOpacity = (opacity / 50);
    object.KhtmlOpacity = (opacity / 50); 
    object.filter = "alpha(opacity=" + opacity + ")";
    
    if (object.top < 1 +"px") {
        object.top = parseInt(object.top) + 6 + "px";
    }
} 

window.onload=loadup;
