function dropList(eSelect, timeout)
{
	/* properties */
	this.name = eSelect.name;
	this.children = [];
	this.selected = eSelect.selectedIndex;
	this.dropList = null;
	this.dropLink = null;
	this.originalText = "";
	this.closetimer = null;
	this.timeout = parseInt(timeout+"");
	if(!this.timeout) this.timeout = 1000;
	/* end properties */

	/* methods */
	this.toggleDisplay = function() { dropListToggleDisplay(this.dropList); }
	this.hideDisplay = function() { dropListHideDisplay(this.dropList); }
	this.changeSelectedOption = function(newText) { this.dropLink.changeText(newText); }
	this.getCustomArticles = function(sector) { dropListGetCustomArticles("col_"+sector); }
	this.removeCustomArticles = function() { dropListRemoveCustomArticles(this.originalText); }
	this.addArticle = function(articletitle, articlelink) { dropListAddArticle(articletitle, articlelink); }
	/* end methods */

	if(document.getElementById("selectiontext"))
	{
		this.originalText = document.getElementById("selectiontext").innerHTML;
	}

	var dropBox = document.createElement("div");
	this.dropList = document.createElement("ul");
	this.dropList.className = "droplist";
	this.dropLink = new dropLink(eSelect.options[this.selected].text, this);

	selectLength = eSelect.options.length;
	for(var i=0; i<selectLength; i++)
	{
		this.children[i] = new dropItem(eSelect.options[i], this);
		this.dropList.appendChild(this.children[i].optionBox);
	}

	dropBox.className = "dropbox";
	dropBox.appendChild(this.dropList);

	eSelect.parentNode.replaceChild(this.dropLink.linkWrap, eSelect);
	insertAfter(this.dropLink.button, this.dropLink.linkWrap);
	insertAfter(dropBox, this.dropLink.button);
}

function dropListToggleDisplay(eList)
{
	if(eList.style.display == "block")
	{
		eList.style.display = "none";
	}
	else
	{
		eList.style.display = "block";
	}
}

function dropListHideDisplay(eList)
{
		eList.style.display = "none";
		this.closetimer = null;
}

function dropListGetCustomArticles (sSector)
{
	if(customnav[sSector] != null)
	{
		var articleBox = document.getElementById("selectiontext");
		var articles = customnav[sSector];
		var articlecount = articles.items.length;
		var articlename = articles.name;
		var articleintro = articles.description;

		if(articleBox == null)
		{
			return false;
		}

		var newArticleBox = document.createElement("div");
		var collectionIntro = document.createElement("p");
		var articleList = document.createElement("ul");

		newArticleBox.setAttribute("id", "selectiontext");
		if(articleintro != "")
		{
			/*
			collectionIntro.appendChild(document.createTextNode(articleintro));
			*/
			// had to replace DOM approach because of problems with &, ", <, etc chars
			collectionIntro.innerHTML = articleintro;
// removed collection intro
//			newArticleBox.appendChild(collectionIntro);
		}

		newArticleBox.appendChild(articleList);
/*
		// array to hold all possible background images for the collection
		var newBgs = [];
*/
		// feed in the articles
		for(var i=0; i<articlecount; i++)
		{
			var article = articles.items[i];
			var articleLink = dropListAddArticle(article["title"], article["summary"], article["link"]);
			articleList.appendChild(articleLink);
/*
			// feed in the images if they are set
			if(article["thumbnail"] != "")
			{
				newBgs[newBgs.length] = article["thumbnail"];
			}
*/
		}
/*
		// select a new background if there are any
		if(newBgs.length > 0)
		{
			var bgIndex = Math.floor(newBgs.length*Math.random());
			var newBg = newBgs[bgIndex];
			var intro_p = document.getElementById("customnav").getElementsByTagName("p")[0];
			intro_p.style.backgroundImage = "url("+newBg+")";
		}
*/
		articleBox.parentNode.replaceChild(newArticleBox, articleBox);
	}
}

function dropListRemoveCustomArticles (replacement)
{
	var articleBox = document.getElementById("selectiontext");
	var newArticleBox = document.createElement("div");
	newArticleBox.setAttribute("id", "selectiontext");
	newArticleBox.innerHTML = replacement;

	articleBox.parentNode.replaceChild(newArticleBox, articleBox);
}

function dropListAddArticle(sTitle, sSummary, sLink)
{
	sTitle = sTitle.replace(/\<[^>]+\>/, '');
	
	var articleLI = document.createElement("li");
/*
	var articleLink = document.createElement("a");
	var articleBreak = document.createElement("br");
	var articleText = document.createTextNode(sTitle);
	var articleIntro = document.createTextNode(sSummary);

	articleLink.setAttribute("href", sLink);
	articleLink.appendChild(articleText);
	articleLI.appendChild(articleLink);
	if(articleIntro != "")
	{
		articleLI.appendChild(articleBreak);
		articleLI.appendChild(articleIntro);
	}
	*/
	// had to replace DOM approach because of problems with &, ", <, etc chars 
	articleLI.innerHTML = '<a href="'+sLink+'">'+sTitle+'</a>'+sSummary;

	return articleLI;
}

