// JavaScript Document

function insertDescription(title, description)
{
	if(!document.getElementById) return false
	
	var panel = document.getElementById("cartoonWrapper");
	
	if(!panel) return false;
	
	if(document.getElementById('cartoonDetails'))
	{
		panel.removeChild(document.getElementById('cartoonDetails'));
	}
	
	// Create the element to house the title and desc
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id','cartoonDetails');
	
	// Creates title element and text
	var header = document.createElement('h2');
	header.setAttribute('id','cartoonHeader');
	var headerText = document.createTextNode(title);
	header.appendChild(headerText);
		
	// Creates desc element and text
	var descriptionElement = document.createElement('p');
	var descriptionText = document.createTextNode(description);
	descriptionElement.appendChild(descriptionText);
	
	newDiv.appendChild(header);
	newDiv.appendChild(descriptionElement);
	
	
	// Iterates through the child nodes of the element, once it 
	// finds it's first child element it carries out the insert before that element
	for(var ii=0;ii<panel.childNodes.length;ii++) {
		
		if(!panel.insertBefore) return false;

		if(panel.childNodes[ii].nodeType == 1) {
			panel.insertBefore(newDiv,panel.childNodes[ii]);
		}
		
		
	}
}
	