// jan 26 2007 Andrew Leslie

//this function is to have a dynamic animated dropdown for a layer from a link

//usage: imageLinkSlidedown("[the layer you want to change]",[the amount in pixels it grows or shrinks by],[how many steps in the animation],[how many milliseconds between steps],"[initial link text]","[link text once activated]")

//       a css class should be on the link with a "_on" at the end.  the script will change it to "_off" once activated.  This means you should make two classes.

//       the link id should be the same name as the layerID but with a "_opener" appended to the end

//start dynamic animated dropdown

function imageLinkSlidedown(layerID,growBy,steps,ms,aText,bText) {
    linktochange = layerID + "_opener";
    var linkref = document.getElementById(linktochange);
    var currentclass = document.getElementById(linktochange).className;
    var newclass
    
    document.getElementById(linktochange).innerHTML = bText;
    
    
    if (growBy > 0){
        newclass = currentclass.replace("_off","_on");   
    }
    else{
        newclass = currentclass.replace("_on","_off");
    }
    linkref.setAttribute("className", newclass);
    linkref.setAttribute("class", newclass);
    
    document.getElementById(linktochange).href = "javascript: void(0)";
    closingStr = "document.getElementById('" + linktochange + "').href = 'javascript: imageLinkSlidedown(\"" + layerID + "\"," + -(growBy) + "," + steps + "," + ms + ",\"" + bText + "\",\"" + aText + "\")'";
    slidedown(layerID,growBy,steps,ms,closingStr);
}


function linkSlidedown(layerID,growBy,steps,ms) {
    linktochange = layerID + "_opener";
    document.getElementById(linktochange).href = "javascript: void(0)";
    closingStr = "document.getElementById('" + linktochange + "').href = 'javascript: linkSlidedown(\"" + layerID + "\"," + -(growBy) + "," + steps + "," + ms + ")'";
    slidedown(layerID,growBy,steps,ms,closingStr);
}

function slidedown(layerID,growBy,steps,ms,closingStr) {
	startHeight = parseInt(document.getElementById(layerID).style.height);
	stepValue = 0;
	animationStr = ""
	
	for (i=0;i<steps; i++) {
		animationStr = animationStr + "setTimeout ( \"document.getElementById('" + layerID + "').style.height = '" + Math.round(stepValue*growBy+startHeight) + "' + 'px'\" , " + i*ms + " ); "
		stepValue = Math.pow(i/steps,.4);
		}
	closingStr = closingStr.replace(/\"/g,"\\" + "\"" );
	animationStr = animationStr + "setTimeout ( \"" + closingStr +"\" , " + steps*ms + " ); "
	changeheight(animationStr);
	animationStr=""
}

function changeheight(animationStr){
	eval(animationStr);
	animationStr=""
	}
	
//end dynamic animated dropdown