//JS for the slideshow.

var sBacklink = "/"

function getBackLink(){
//Write the back link if the redirecting page was the projects page
// Look for a cookie from the current level, up the tree
	for (i=_myLevel; i>0; i--){
		if (undefined != readCookie(backLinkCookie + i)){
			var sLink = ""
			sLink = readCookie (backLinkCookie + i)
			var aTmp = new Array();
			aTmp = sLink.split("|")
			sBacklink = aTmp[0]
			document.getElementById("backlink").href = sBacklink
			document.getElementById("backlinklogo").href = sBacklink
			return ""
		}
	}
}

getBackLink();

jQuery(document).keyup(function(event){
    if (event.keyCode == 27) {
        document.location = sBacklink
    }
});


function getImgLink(id){
//Create one of the background-image links
return "<a href='#' onclick='setBackground(" + id + ")'>" + id + "</a>"
}

function ShowImageLinks(sLinks){
//Add the image links to the page
var oImgLinks = document.getElementById("imgLinks")

if (undefined != oImgLinks){
    oImgLinks.innerHTML = sLinks
    }
}


var iCurrentId

function setBG(id){
    //Set the background-image for the page
    jQuery("#SlideShowNext").removeClass ("HideIcon")
    jQuery("#SlideShowPrev").removeClass ("HideIcon")
    
    if (id < 1){
        id = 0;
        jQuery("#SlideShowPrev").addClass ("HideIcon")
        
    }
    
    var arrMax
    arrMax = _ImgArray.length -1
    
    if (id >= arrMax)    {
        id = arrMax;
        jQuery("#SlideShowNext").addClass ("HideIcon")
    }
    iCurrentId = id
    jQuery("#bgimg").attr("src", getBgLink(_sImgTemplate, id))
    

}

function setBgNext (LinkId){
    if (iCurrentId < (_ImgArray.length - 1)){
        setBG (iCurrentId + 1)
        
        }
    else
    {
    jQuery("#" + LinkId).addClass ()
    }

}

function setBgPrev (LinkId){
    if (iCurrentId > 0){
        setBG (iCurrentId - 1)
        jQuery("#" + LinkId).addClass ("")
    }
        else
    {
    jQuery("#" + LinkId).addClass ("HideIcon")
    }
}


function getBgLink (sImgTemplate, id){
    sImgTemplate = regexString(sImgTemplate, _TokenId, _ImgArray[id])
    sImgTemplate = regexString(sImgTemplate, _TokenWidth, _BgIngWidth)
    sImgTemplate = regexString(sImgTemplate, _TokenHeight, _BgIngHeight)
    sImgTemplate = regexString(sImgTemplate, _TokenType, "normal")
    
    return sImgTemplate

}

function regexString (sIn, sRegex, sVal){
    var rxId = new RegExp(sRegex)
    return sIn.replace(sRegex , sVal)
}


/*
var posX = 0
var posY = 0 

var timeToFade = 1500

var fadeTimer

var iconsVisible = true

function startCounter(iTime){
    if (iconsVisible == true){
    fadeTimer = setTimeout (hideIcons, iTime);
    }
}

function showIcons(){
        jQuery("#slideshownav").fadeIn(300)
        iconsVisible = true
    }

function hideIcons(){
        jQuery("#slideshownav").fadeOut(500)
        iconsVisible = false
    }

        jQuery("#skincontainer").mousemove(function(e){
        if (e.pageX != posX || e.pageY != posY){
            clearTimeout (fadeTimer)
            startCounter(timeToFade);
            posX = e.pageX;
            posY = e.pageY
        
            if (iconsVisible == false){
                showIcons()
            
        }
    }
    });
    */

//startCounter(timeToFade)

