// 
// Slideroll Caption Display Script 0.93
// Use at your own risk
// 

var shotTitle, shotCaption, shotCaption2, shotCredit, oldShotTitle, oldShotCaption;

// if container div does not exist, create it
if (!document.getElementById("sliderollText")) {
	document.write('<div id="sliderollText"></div>');
}

function sr_setText(myTitle,myCaption,myCredit) {
		
	shotTitle = myTitle;
	shotTitle = shotTitle.replace(/&quot;/g,"\"");
	if (shotCaption2 != undefined) {
		shotCaption = myCaption + shotCaption2;
	} else {
		shotCaption = myCaption;
	}
	shotCaption2 = "";
	shotCaption = shotCaption.replace(/&quot;/g,"\"");
	shotCredit = myCredit;
	shotCredit = shotCredit.replace(/&quot;/g,"\"");
	
	if ( (shotTitle != oldShotTitle) | (shotCaption != oldShotCaption) ) {
		
		oldShotTitle = shotTitle;
		oldShotCaption = shotCaption;
		
		// put data into page
		var newTitle = document.createElement("h4");
		var newCaption = document.createElement("p");
		var newCredit = document.createElement("cite");
		
		newTitle.appendChild(document.createTextNode(shotTitle));
		newCaption.appendChild(document.createTextNode(shotCaption));
		newCredit.appendChild(document.createTextNode(shotCredit));
		
		newTitle.id = "srTitle";
		newCaption.id = "srCaption";
		newCredit.id = "srCredit";
		
		var theText = document.getElementById("sliderollText");
		
		if (shotTitle != "") {
		
			if (document.getElementById("srTitle")) {
			
				var titleElm = document.getElementById("srTitle");
				var replaced = theText.replaceChild(newTitle, titleElm);
				
			} else {
			
				if (document.getElementById("srCaption")) {
			
					var created = theText.insertBefore(newTitle, document.getElementById("srCaption"));
			
				} else {
			
					var created = theText.appendChild(newTitle, titleElm);
			
				}
				
			}
		
		} else { // if no title, remove the element entirely
		
			if (document.getElementById("srTitle")) {
			
				var titleElm = document.getElementById("srTitle");
				theText.removeChild(titleElm);
				
			}
			
		}
		
		if (shotCaption != "") {				
	
			if (document.getElementById("srCaption")) {
			
				var captionElm = document.getElementById("srCaption");
				var replaced2 = theText.replaceChild(newCaption, captionElm);
			
			} else {

				if (document.getElementById("srCredit")) {
			
					var created2 = theText.insertBefore(newCaption, document.getElementById("srCredit"));
			
				} else {
			
					var created2 = theText.appendChild(newCaption, captionElm);
			
				}				
				
							
			}

		} else {  // if no caption, remove the element entirely
		
			if (document.getElementById("srCaption")) {
			
				var captionElm = document.getElementById("srCaption");
				theText.removeChild(captionElm);
				
			}
			
		}
		
		if (shotCredit != "") {
		
			if (document.getElementById("srCredit")) {

				var creditElm = document.getElementById("srCredit");
				var replaced3 = theText.replaceChild(newCredit, creditElm);
			
			} else {

				var created3 = theText.appendChild(newCredit, creditElm);
							
			}
			
		} else {  // if no credit, remove the element entirely
		
			if (document.getElementById("srCredit")) {
			
				var creditElm = document.getElementById("srCredit");
				theText.removeChild(creditElm);
				
			}
			
		}
		
	}
	
}

function sr_appText(myCaption2) {
	
	shotCaption2 = myCaption2;

}
