//For writing out links of different kinds that will always be there

var hrefStart="<a href=\"";
var hrefEnd='\">';
var hrefCloseGen='</a>';
var hrefCloseList='</a><br />';

var hrefJSStart="<a href=\"\" onClick=\"window.open\(\'"; 
var hrefJSEnd="\'\)\">";
var hrefJSGenEnd="\'\)\"";
var hrefJSGenEndClose=">";

//superscript that writes the links on index page right side.
function writeLinks() {
	var headerArtistFriends = "<div class=\"lowernav\"><hr />Possum links of artist friends:<br /><br />";
	var headerLitMagResources = "<br />Lit mags and resources:<br /><br />";
	var headerWriters = "<br />Web sites of great writers:<br /><br />";
	var headerMisc = "<br />Miscellaneous:<br /><br />";
	var headerRPublications = "<br />Journals that publish Robert\'s writings!<br /><br />";

	document.write(headerArtistFriends);
	writeArtistFriendLinks();
	document.write(headerRPublications);
	writePurchaseLinks();
	document.write(headerWriters);
	writeWriterLinks();
	document.write(headerLitMagResources);
	writeArtistLitLinks();
	document.write(headerMisc);writeMiscLinks();
	document.write("</div>");
}

	//subsscripts that write out links on main page, also rollovers
	function writeArtistFriendLinks() {
		for(i=0;i<arrLinksList.length;i++) {
			document.write(hrefJSStart + arrLinksList[i][2] +  hrefJSGenEnd + 'onMouseOver=\"visi(\'plink' + arrLinksList[i][0] + '\')\"; onMouseOut=\"invisi(\'plink' + arrLinksList[i][0] + '\')\"; return false;' + hrefJSGenEndClose + arrLinksList[i][1] + hrefCloseList);
		}
	}

	function writeArtistLitLinks() {
		for(i=0;i<arrLinksLitList.length;i++) {
			document.write(hrefJSStart + arrLinksLitList[i][2] + hrefJSGenEnd + 'onMouseOver=\"visi(\'link' + arrLinksLitList[i][0] + '\')\"; onMouseOut=\"invisi(\'link' + arrLinksLitList[i][0] + '\')\"; return false;' + hrefJSGenEndClose + arrLinksLitList[i][1] + hrefCloseList);
		}
	}

	function writePurchaseLinks() {
		for(i=0;i<arrLinksPurchaseList.length;i++) {
			document.write(hrefJSStart + arrLinksPurchaseList[i][2] + hrefJSGenEnd + hrefJSGenEndClose + arrLinksPurchaseList[i][1] + 
				hrefCloseGen + "<br />");
		}
	}

	function writeWriterLinks() {
		for(i=0;i<arrLinksWriterList.length;i++) {
			document.write(hrefJSStart + arrLinksWriterList[i][2] + hrefJSGenEnd + hrefJSGenEndClose + arrLinksWriterList[i][1] + hrefCloseList);
		}
	}

	function writeMiscLinks() {
		for(i=0;i<arrLinksGenList.length;i++) {
			document.write(hrefJSStart + arrLinksGenList[i][2] + hrefJSGenEnd + 'onMouseOver=\"visi(\'mlink' + arrLinksGenList[i][0] + '\')\"; onMouseOut=\"invisi(\'mlink' + arrLinksGenList[i][0] + '\')\"; return false;' + hrefJSGenEndClose + arrLinksGenList[i][1] + hrefCloseList);
		}
	}

//functions for showing and hiding rollovers on right side
function showBio() {
	if (document.layers) { 	
		document.layers['bio'].visibility = 'show';
	}
	else if (document.all) {
		document.all['bio'].style.visibility = 'visible';
	}
	else if (document.getElementById) {
		document.getElementById('bio').style.visibility = 'visible';
	}
}	

//writing out rollover text for books and links
function writeRolloverText() {
	for(i=0;i<arrLinksLitList.length;i++) {
		document.write('<div class=\"orglinkinfo\" id=\"link' + arrLinksLitList[i][0] + '">' + arrLinksLitList[i][3] + '</div>');
	}	
	for(i=0;i<arrLinksList.length;i++) {
		document.write('<div class=\"friendlinkinfo\" id=\"plink' + arrLinksList[i][0] + '">' + arrLinksList[i][3] + '</div>');
	}
	for(i=0;i<arrLinksGenList.length;i++) {
		document.write('<div class=\"misclinkinfo\" id=\"mlink' + arrLinksGenList[i][0] + '">' + arrLinksGenList[i][3] + '</div>');
	}
}

//show and hide functions
function visi(nr) {
	a = nr;
	document.getElementById(nr).style.visibility = 'visible';
	if (a == 'bookInfo' || a == 'writingInfo' || a == 'versalInfo') {
		document.getElementById('bio').style.visibility = 'hidden';
	}
}

function invisi(nr) {
	a = nr;
	document.getElementById(nr).style.visibility = 'hidden';
	if (a == 'bookInfo' || a == 'writingInfo' || a == 'versalInfo') {
		document.getElementById('bio').style.visibility = 'visible';
	}
}

//blog functions
function newWriteBlog() {
	oTable = document.createElement("table");
	oFooter = document.getElementById("footer");
	//alert(oFooter);
	oParent = oFooter.parentNode;
	oTBody = document.createElement("tbody");
	oTable.appendChild(oTBody);
	var img = '';
	var fotoVert = '';
	var fotoHor = '';
	var imgAlign = '';

	//alert(oTable.className);
	//for(k=arrBlogEntry.length;k>(arrBlogEntry.length-blogCount);k--) {
	for(k=arrBlogEntry.length;k>0;k--) {
		var b=k-1;
		//alert(b);
		//alert(k);
		//must use tbody for ie:
		var oTr = document.createElement("tr");
		var oTd1 = document.createElement("td");
		var oTd2 = document.createElement("td");
		oTd1.className = "blogleft";
		oTd2.className = "blogright";
		oTBody.appendChild(oTr);
		oTr.appendChild(oTd1);	
		oTr.appendChild(oTd2);

		//must figure out image stuff here first
		var oTextNode1 = document.createTextNode(arrBlogEntry[b][0]);
		oTd1.appendChild(oTextNode1);
		oTd2.innerHTML = arrBlogEntry[b][1];

		if (arrBlogEntry[b][2] != '') {
			//alert(b);
			oImg = document.createElement("img");
			oImg.src = "bloggraphics/" + arrBlogEntry[b][2];
			if (arrBlogEntry[b][3] != '') {
				oImg.style.height="100px";
				oImg.style.width="75px";
			} else {
				oImg.style.height="75px";
				oImg.style.width="100px";	
			}
			oTd2.appendChild(oImg);
		}
	}

	oParent.insertBefore(oTable, oFooter);
	oTable.className = "blog";
	//alert(oTable.parentNode.id);
	//alert(oFooter.parentNode.id);
}



function writeBookShortList() {
var b = arrBookList.length;
var loop = arrBookList.length - 7;
document.write("<div class=\"upperlinkinfo\" id=\"bookInfo\">");
for (a=arrBookList.length;a>loop;a--){
var b = a - 1;
document.write(arrBookList[b][2] + '-' + arrBookList[b][3] +'<br />');
}
document.write("</div>");
}

//// functions for short story page
function writeShortStories() {
	//alert("starting");
	//alert("length: " + arrShorts.length);
	//create table
	oTable = document.createElement("table");
	oFooter = document.getElementById("footer");
	oParent = oFooter.parentNode;
	oTBody = document.createElement("tbody");
	oTable.appendChild(oTBody);
	var oTr = document.createElement("tr");
	oTBody.appendChild(oTr);
	var oTd1 = document.createElement("td");
	var oTd2 = document.createElement("td");
	oTd2.id = 'textAdd';
	oTd1.className = "shortstableleft";
	oTd2.className = "shortstableright";
	oTr.appendChild(oTd1);	
	oTr.appendChild(oTd2);	
	
	//get text ready...
	oList1= document.createElement("ul");
	oList2= document.createElement("ul");
	oList3= document.createElement("ul");
	oList4= document.createElement("ul");
	oHeader1= document.createElement("h3");
	oHeader2= document.createElement("h3");
	oHeader3= document.createElement("h3");
	oHeader4= document.createElement("h3");
	
	//here we're putting everything in the second td.
	for(k=0;k<arrShorts.length;k++) {
		oItem= document.createElement("li");
		oItem.innerHTML = '<a href=\"\" onclick=\"writeStoryDivsCopy(' + arrShorts[k][0] + '); return false;\">' + arrShorts[k][2] + '</a>';
		
		switch(arrShorts[k][7])
		{
		case 's':
			oHeader1.innerHTML = "Short Stories";
			oList1.appendChild(oItem);
		  break;    
		case 'p':
			oHeader4.innerHTML = "Performance";
		  	oList4.appendChild(oItem);
		  break;
		case 'm':
			oHeader2.innerHTML = "Non-Fiction";			
			oList2.appendChild(oItem);
		  break;    
		case 'a':
			oHeader3.innerHTML = "Articles";			
		  	oList3.appendChild(oItem);
		  break;		
		default:
		  //code to be executed if n is
		  //different from case 1 and 2
		}
	}
	
	if (oList1.childNodes.length>0) {
		oTd1.appendChild(oHeader1);
		oTd1.appendChild(oList1);	
	}
	if (oList2.childNodes.length>0) {
		oTd1.appendChild(oHeader2);
		oTd1.appendChild(oList2);	
	}
	if (oList3.childNodes.length>0) {
		oTd1.appendChild(oHeader3);
		oTd1.appendChild(oList3);	
	}
	if (oList4.childNodes.length>0) {
		oTd1.appendChild(oHeader4);
		oTd1.appendChild(oList4);	
	}
	
	oTable.className = 'shorts';
	oParent.insertBefore(oTable, oFooter);
}

//in geninfo, can now also put links to read more, so perf should act the same except for link to full text...
function writeStoryDivsCopy(id) {
	//alert(id);
	var i = id;
	var createdInfo = "";
	var publishInfo = "";
	var genInfo = "";
	if (arrShorts[i][4] != '') {
		if (arrShorts[i][7] == 'p') {
			publishInfo = '<br />Performed At: ' + arrShorts[i][4];
		} else {
			publishInfo = '<br />Published In: ' + '<a href=\"' + arrLinksPurchaseList[arrShorts[i][4]][2] + '\" target=\"_blank\">' + arrLinksPurchaseList[arrShorts[i][4]][1] + '</a>' + ' (' + arrShorts[i][5] + ')';
		}
			
	}
	if (arrShorts[i][7] == 'p') {
		fullTextLink =  '<br /><br /><a href=\"fiction/' + arrShorts[i][1] + '.html\" target=\"_blank\">Full Text</a>';
		createdInfo = '<br />Premiere Date: ' + arrShorts[i][3];
	}	else {
		fullTextLink = '';
	}
	if (arrShorts[i][6] != '') {
		genInfo = arrShorts[i][6];
		if (arrShorts[i][8]) {
			if (arrShorts[i][8] != '') {
				storyText = '<br /><br /' + arrShorts[i][8] + '<br /><br />';
			} else {
				storyText = 'sss';
			}		
		} else {
		storyText = '<br /><br />';	
		}	
	}	
	var oTd2 = document.getElementById('textAdd');
	
	//may have to be more selective depending on type...
	
	oTd2.innerHTML = createdInfo + publishInfo + storyText  + genInfo + fullTextLink;
}

// functions for bio page

//Sets initial bio
function setBioPage() {
	//var oSelectedTable = document.getElementById('2');
	var oSelectedTable = document.getElementById('bio');
	//alert(oSelectedTable);
	var oSelectedTableNew = oSelectedTable.cloneNode(true);
	var oDiv = document.getElementById('container');
	//alert(oDiv.childNodes.length);
	if (oDiv.childNodes.length > 1) {
		alert('a');
	} else if (oDiv.childNodes.length == 0) {
		//alert('0 stuff');
		oDiv.appendChild(oSelectedTableNew);
		oDiv.firstChild.className = "";
	} else {
		alert('1 stuff');
			oDiv.removeChild(oDiv.firstChild );   
			oDiv.appendChild(oSelectedTableNew);
			oDiv.firstChild.className = "";
	}
}

//when link is clicked, sets the right table
function reselect(i) {
		var oDiv = document.getElementById('container');
		//alert (oDiv.childNodes.length);
		oDiv.removeChild(oDiv.firstChild );   
		var oSelectedTable = document.getElementById(i);
		var oNewTable = oSelectedTable.cloneNode(true);
		oDiv.appendChild(oNewTable);
		oDiv.firstChild.className = "";
}
