
//requires tween.js

function init_listMustard() {

//SETUP
// put two side by side columns, id="essay" id="doc_list"
// each link in essay is span id="link_name" class="lMlink" and corresponding doc item
// is div id="lMdoc_name" class="lMdoc", where the "link_" and "lMdoc" parts are literal
// and the "_name" parts are common for those essay text and doc list icons you wish to link.
// 
// 


//listMustard globals

	lM_list_top_pad_min = 0; //px suffix added later
	lM_doc_list = document.getElementById("doc_list");
	lM_list_item_Yoffset = 0;
	lM_list_extraH = 150;
	lM_tween_dur = 1;
	lM_off_color = '';
	lM_on_color = '';

	lM_last_link = new Object();
	lM_last_doc = new Object();
	lM_next_link = new Object();
	lM_next_doc = new Object();

//set doc list height equal to essay col
	var essayCol = document.getElementById("essay");
	var essayColH = essayCol.offsetHeight;
	
	lM_doc_list_origH = essayColH + lM_list_extraH;
	
	lM_doc_list.style.height = (lM_doc_list_origH - lM_list_top_pad_min) + "px";
	essayCol.style.height = (lM_doc_list_origH) + "px";


//set doc list top padding
	lM_doc_list.style.paddingTop = lM_list_top_pad_min + "px";	
	
//set clicks for "link_" id'd spans
	var spanSet = document.getElementsByTagName("span");
	var Nid,Nid_array;
	var pastFirstOne = 0;

	for(var i=0;i < spanSet.length; i++){ 
		Nid = spanSet[i].getAttribute("id");
		if(Nid){ //only for divs with an id and not the null at end of array
			//associate mouseover to all doclink spans
// spans are id'd as "link_individualspan", and indexOf searches for the "ink_" part of it
			if(Nid.indexOf("ink_") > 0) { 
				//AttachEvent(spanSet[i],'mouseover',spreadMustard,false);
				spanSet[i].onmouseover = spreadMustard;
				if(!pastFirstOne) {
					lM_last_link = spanSet[i]; //init the link history to first item found

					//find associated doc item and set to history global
					var idParts = Nid.split("link_");
					if(idParts[1]){
						lM_last_doc = document.getElementById("lMdoc_" + idParts[1]);
						pastFirstOne = 1;
					}
				}
			}
		}
	}
//set clicks for "doc_" id'd divs
	var divSet = document.getElementsByTagName("div");

	for(var i=0;i < divSet.length; i++){ 
		Nid = divSet[i].getAttribute("id");
		if(Nid){ //only for divs with an id and not the null at end of array
			//associate mouseover to all doclink spans
// spans are id'd as "doc_individualdiv", and indexOf searches for the "oc_" part of it
			if(Nid.indexOf("Mdoc_") > 0) {
				//AttachEvent(spanSet[i],'mouseover',spreadMustard,false);
				divSet[i].onmouseover = linkMustard;
			}
		}
	}
	
	
	//global tween
	lMpadTween = new Tween(lM_doc_list.style,'paddingTop',Tween.strongEaseOut,parseInt(lM_doc_list.style.paddingTop),0,1,'px');
	lMpadTween.onMotionAlmostDone = lightMustard;

	lMheightTween = new Tween(lM_doc_list.style,'height',Tween.strongEaseOut,parseInt(lM_doc_list.style.height),0,1,'px');

}



function spreadMustard(){
	var myId = this.getAttribute('id');
	var idParts = myId.split("link_");
	if(idParts[1]){
		var daDoc = document.getElementById("lMdoc_" + idParts[1]);
		daDoc.parentNode.scrollTop = "0";

		//find Y for doc
		var docY = findPosY(daDoc);
		var linkY = findPosY(this);
		
		//starting parent padding
		var origPad = daDoc.parentNode.style.paddingTop;
		var origPadArray = origPad.split("px"); //remove px
		origPad = origPadArray[0] * 1.0;//math makes it a num				
				
		//calc distance from caller
		var newPad = (origPad + (linkY - docY) - lM_list_item_Yoffset) - daDoc.offsetHeight + this.offsetHeight;

		//adjust col padding to push down
		if(newPad > lM_list_top_pad_min) lMpadTween.continueTo(newPad,lM_tween_dur); //non-tween version: daDoc.parentNode.style.paddingTop = newPad + "px";
		else {
			lMpadTween.continueTo(lM_list_top_pad_min,lM_tween_dur); //non-tween version: daDoc.parentNode.style.paddingTop = lM_list_top_pad_min + "px";
			newPad = lM_list_top_pad_min;
		}

		//adjust for strict DOM w/h model
		var newH = lM_doc_list_origH - newPad;
		lMheightTween.continueTo(newH,lM_tween_dur);//non-tween height:		daDoc.parentNode.style.height = newH + "px";		
		
		lM_next_link = this;
		//unmark prev link and doc
		lM_last_link.className = "lMlink";
		lM_last_doc.className = "lMdoc";

		//mark new link
		lM_next_link.className = "lMlink_selected";

		//set current as prev
		lM_last_link = lM_next_link;
		lM_next_doc = daDoc;
	}
}

function lightMustard(){

		lM_next_doc.className = "lMdoc_selected";
		lM_last_doc = lM_next_doc;
}


function linkMustard(){
	var myId = this.getAttribute('id');
	var idParts = myId.split("lMdoc_");
	if(idParts[1]){
		var daLink = document.getElementById("link_" + idParts[1]);
		
		//unmark prev link and doc
		lM_last_link.className = "lMlink";
		lM_last_doc.className = "lMdoc";
		
		//mark new docs
		this.className = "lMdoc_selected";
		daLink.className = "lMlink_selected";
		
		//set current as prev
		lM_last_doc = this;
		lM_last_link = daLink;
	}

}

//http://jstween.blogspot.com/#TextTween


AttachEvent(window,'load',init_listMustard,false);


