//Js for the project pages
//Pre loads all the pages

var bNew = true
// The images are loaded from JS to enable the scaling of the images
// Because you have to pass the width and height to the image to get the right image, which you only know in JS,
// Not in ASP.NET

// Dynamically (from asp.net) written array of image ids for this project

var lastLink = 0 //Store the id of the previous selected link.

//Read the XML file for image preload
//var myimages = new Array();
//for (i=0; i < imgIds.length;i++){
//myimages[i] = new Image
//myimages[i].src = regexString(getImgLink(imgIds[i]), "<%=sTokenType%>", "")
//myimages[i + imgIds.length] = new Image
//myimages[i + imgIds.length].src = regexString(getImgLink(imgIds[i]), "<%=sTokenType%>", "topblue")
//}

createProjectLinks();


function getImgLink(id, iNumber){
// create one of the background-image links
return "<a href='#' id='ImgLink" + id + "' onclick='setBackground(" + id + ");return false'>" + iNumber + "</a>"

}

function setAciveLink (id){

setClass ("ImgLink" + id,  "Active")
setClass ("ImgLink" + lastLink,  "")

lastLink = id
 
}

function setClass (linkId, sClassName){
    var oLink =  document.getElementById (linkId)
    if (undefined != oLink){
        oLink.className = sClassName
    }
}

function getImgLink(id){
var sImgTemplate = _sImgTemplate

sImgTemplate = regexString(sImgTemplate, _TokenId, id)
sImgTemplate = regexString(sImgTemplate, _TokenWidth, 1110)
sImgTemplate = regexString(sImgTemplate, _TokenHeight, 610)
return(sImgTemplate);
}

function regexString (sIn, sRegex, sVal){
    var rxId = new RegExp(sRegex)
    return sIn.replace(sRegex , sVal)
}

function createProjectLinks(){
//Create array of text to look for
ProjectTypeId = new Array();
ProjectTypeId[0] ="ProjectData"
ProjectTypeId[1] = "ProjectText"
//ProjectTypeId[2] = "ProjectAwards"

ProjectTypeName = new Array ();
ProjectTypeName[0] ="Facts"
ProjectTypeName[1] = "Text"
//ProjectTypeName[2] = "Awards"


var oLinks = ""

        for (i in ProjectTypeId){
            if (undefined != document.getElementById (ProjectTypeId[i])){
                oLinks = oLinks + "<a id='ProjectLink" + i +  "' href='#' onclick='showProject(" + i + ");return false'>" + ProjectTypeName[i] + "</a>"
             }
			 else
			 {
			 ProjectTypeId[i] = ""
			 }
         document.getElementById ("ProjectLinks").innerHTML = oLinks
        }
    showProject(_ActiveLink);
	
}

function showProject(id){

    for (i in ProjectTypeId){
        if (i == id){
            document.getElementById(ProjectTypeId[i]).className = ""
            document.getElementById("ProjectLink" + i).className = "Active"
        }
        else{
		if (ProjectTypeId[i] != ""){
            document.getElementById(ProjectTypeId[i]).className = "Hidden"
            document.getElementById("ProjectLink" + i).className = ""
			}
        }
    }
	
	if (bNew != true){
	 reSetScroll("#ProjectContent");
	}
	bNew = false	
	
}
