//////////////////////////////////////////////////////////////////Core Functions

var lastUpdated = "8/19/2009";
var acadUpdated = "11/14/2008";
var homeURL = "http://www.intergeist.com/";
var imageURL = "http://www.intergeist.com/sloat/";

function coder(theString) {
    var newString = "";
    for (a=0; a<theString.length; a++) {
	    if (theString.substr(a,1) == " ") {
	        newString = newString + "_";
	    } else {
	        newString = newString + theString.substr(a,1);
	    }
    }
    return newString;
}

function decoder(theString) {
    var newString = "";
    for (a=0; a<theString.length; a++) {
	    if (theString.substr(a,1) == "_") {
	        newString = newString + " ";
	    } else {
	        newString = newString + theString.substr(a,1);
	    }
    }
    return newString;
}

function get_nodes(the_node) {
    var noder = "";
    var theNode;
	for (a=0; a<ether_array.length; a++) {
	    if (ether_array[a][0] == the_node) {
		    for (b=1; b<ether_array[a].length; b++) {
		        noder = noder + "<script src=\"" + homeURL + "sloat/SubEthers/" + ether_array[a][b] + ".js\"></script>";
		    }
	    }
	}
    document.write(noder);
}

function get_image(theParent, image_file, image_name) {
		 image_name = coder(image_name);
		 //var theParent;
		 	// theParent = get_parent(image_node);
		 //engage_hypernav(image_node, 0);
		 //if ((theParent == '5') || (theParent == '186')) {
		 //	 window.open('http://wave.prohosting.com/dsloat/' + image_link,image_node + 's','plain,resizable,scrollbars');
		 //}
		 var theImage;
		 	 theImage = imageURL + image_file;
		 //if ((theParent == '27') || (theParent == '216') || (theParent == '230')) {
		 	 window.open(theImage, image_name + 's','plain,width=640,height=640,resizable,scrollbars');
		 //}		 
		 if (document.remoteBox.remote.value=='1') {
		 	if (document.remoteBox.multiOpt.value=='1') {
			   window.open(homeURL + 'imageControls.html?' + theParent + '&' + image_name + '&m','image_controls','plain,width=640,height=120,resizable,scrollbars');
			} else {
			   window.open(homeURL + 'imageControls.html?' + theParent + '&' + image_name + '&s','image_controls','plain,width=640,height=120,resizable,scrollbars');
			}
         }
}

function remote_box() {
//	document.write("<input type='checkbox' name='remoteC' onClick='JavaScript:toggleValue(\"remote\")'><left><span class='textS'>Enable Remote Picture Control</span></left><br>");
//	document.write("<input type='checkbox' name='multiOptC' onClick='JavaScript:toggleValue(\"multiOpt\")'><left><span class='textS'>Enable Multiple Pop-Up Images</span></left>");
}

function toggleValue(theField){
	if (document.remoteBox[theField].value == '0') {
	   document.remoteBox[theField].value = '1';
	} else {
	   document.remoteBox[theField].value = '0';
	}
}

////////////////////////////////////////////////////////////////////////////////COOKIE STUFF:

function Cookie(document, name, hours, path, domain, secure)
{
	this.$document = document;
	this.$name = name;
	if (hours)
	        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
	else this.$expiration = null
	if (path) this.$path = path; else this.$path = null;
	if (domain) this.$domain = domain; else this.$domain = null
	if (secure) this.$secure = true; else this.$secure = false;
}

function _Cookie_store()
{
	var cookieval = "";
	for (var prop in this) {
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
			continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ':' + escape(this[prop]);
	}
	var cookie = this.$name + '=' + cookieval;
	if (this.$expiration)
		cookie += '; expires=' + this.$expiration.toGMTString();
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	if (this.$secure) cookie += '; secure';
	
	this.$document.cookie = cookie;
}

function _Cookie_load()
{
	var allcookies = this.$document.cookie;
	if (allcookies == "") return false;

	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) return false;
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);

	var a = cookieval.split('&');
	for (var i=0; i < a.length; i++)
		a[i] = a[i].split(':');

	for (var i=0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}

	return true;
}

function _Cookie_remove()
{
	var cookie;
	cookie = this.$name + '=';
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	cookie += '; expires = Wed, 21-Nov-1973 00:00:00 GMT';
	
	this.$document.cookie = cookie;
}

////////////////////////////////////////////////////////////////////////////////END COOKIE STUFF.

var imageFolder = "images/nav/"
var imageZones = new Array();
    imageZones[0] = new Array("use",0, 100);
    imageZones[1] = new Array("art",9, 30);
    imageZones[2] = new Array("dan",4, 100);
    imageZones[3] = new Array("log",6, 50);
    imageZones[4] = new Array("con",10, 30);
    imageZones[5] = new Array("web",6, 100);    
var images = new Array(imageZones.length, 100);

for (var a=0; a<imageZones.length; a++) {
    images[a] = new Array();
    for (var i=0; i<imageZones[a][1]; i++) {
	images[a][i] = new Image();
        images[a][i].src = imageFolder + imageZones[a][0] + i + ".jpg";
    }
}

function animate(imageIndex) {
    if (timeout_id[imageIndex]) clearTimeout(timeout_id[imageIndex]); timeout_id[imageIndex]=null;
    eval("document.ani.src = images[imageIndex][frame[imageIndex]].src");
    if (frame[imageIndex] < imageZones[imageIndex][1]-1) frame[imageIndex]++;
    if (frame[imageIndex] == (imageZones[imageIndex][1])) {
	clearTimeout(timeout_id[imageIndex]); timeout_id[imageIndex]=null;
	frame[imageIndex] = imageZones[imageIndex][1]-1;
    } else {
	timeout_id[imageIndex] = setTimeout("animate(" + imageIndex + ")", imageZones[imageIndex][2]);
    }
}

function reverse_animate(imageIndex) {
    if (timeout_id[imageIndex]) clearTimeout(timeout_id[imageIndex]); timeout_id[imageIndex]=null;
    eval("document.ani.src = images[imageIndex][frame[imageIndex]].src");
    if (frame[imageIndex] > -1) frame[imageIndex]--;
    if (frame[imageIndex] == -1) {
	clearTimeout(timeout_id[imageIndex]); timeout_id[imageIndex]=null;
	frame[imageIndex] = 0;
    } else {
	timeout_id[imageIndex] = setTimeout("reverse_animate(" + imageIndex + ")", imageZones[imageIndex][2]);
    }
}

var frame = new Array();
var timeout_id = new Array();
    for (a=0; a<imageZones.length; a++) {
	frame[a] = 0;
	timeout_id[a] = null;
	//timeout_id2[a] = null;
    }


function header(currentLoc) {
	document.write("<table border='0' cellpadding='6' cellspacing='0' align='center'>");
	document.write("<tr><td colspan='2' align='center'><a href='http://www.intergeist.com'><img src='header.jpg' border='0' /></a></td></tr>");
//	document.write("<tr><td align='center'><img src='headerBL.jpg' border=0 name='ani'/></td>");
//	document.write("<td align='center'><img src='headerBR.jpg' /></td></tr>");
//	document.write("<tr><td align='center'><a href='GPF.html?Dan_Art_Gallery'><img src='" + imageFolder + "art.jpg' border='0' onmouseover='javascript:if (timeout_id[1] == null) animate(1);' onmouseout='javascript: reverse_animate(1);' /></a> - ");
//	document.write("<a href='GPF.html?Logos'><img src='" + imageFolder + "logos.jpg' border='0' onmouseover='javascript:if (timeout_id[2] == null) animate(2);' onmouseout='javascript: reverse_animate(2);' /></a> - ");
//	document.write("<a href='GPF.html?Web_Development'><img src='" + imageFolder + "sites.jpg' border='0' onmouseover='javascript:if (timeout_id[3] == null) animate(3);' onmouseout='javascript: reverse_animate(3);' /></a> - ");
//	document.write("<a href='GPF.html?Usability'><img src='" + imageFolder + "usability.jpg' border='0' onmouseover='javascript:if (timeout_id[4] == null) animate(4);' onmouseout='javascript: reverse_animate(4);' /></a> - ");
//	document.write("<a href='http://www.dansloat.com/Resume.html'><img src='" + imageFolder + "about.jpg' border='0' onmouseover='javascript:if (timeout_id[5] == null) animate(5);' onmouseout='javascript: reverse_animate(5);' /></a> - ");
//	document.write("<a href='mailto:dan@intergeist.com'><img src='" + imageFolder + "contact.jpg' border='0' onmouseover='javascript:if (timeout_id[6] == null) animate(6);' onmouseout='javascript: reverse_animate(6);' /></a></td></tr></table>");
	document.write("<tr><td align='center'><a href='GPF.html?Dan_Art_Gallery'><img src='" + imageFolder + "art.jpg' border='0' /></a>");
	document.write("<a href='GPF.html?Logos'><img src='" + imageFolder + "logos.jpg' border='0' /></a>");
	document.write("<a href='GPF.html?Web_Development'><img src='" + imageFolder + "sites.jpg' border='0' /></a>");
	document.write("<a href='GPF.html?Usability'><img src='" + imageFolder + "usability.jpg' border='0' /></a>");
	document.write("<a href='http://www.intergeist.com/Sloat_CV_040709.pdf'><img src='" + imageFolder + "about.jpg' border='0' /></a>");
	document.write("<a href='mailto:dan@intergeist.com'><img src='" + imageFolder + "contact.jpg' border='0' /></a></td></tr></table>");

	
	document.write("<form name='remoteBox'><input type='hidden' name='remote' value='0'>");
	document.write("<input type='hidden' name='multiOpt' value='0'>");	
}

function footer() {
	document.write("</form>");
	document.write("<table border='0' cellpadding='0' cellspacing='6' align='center' width='711'>");
	document.write("<tr><td bgcolor='#000000'><img='shim.jpg' /></td></tr>");
	document.write("<tr><td align='right' class='footer'><br />Please direct all questions to <a href='mailto:dan@intergeist.com'>dan@intergeist.com</a>.<br />&copy\; 2009 Intergeist.com. All rights reserved.<br />LinkedIn: <a href='http://www.linkedin.com/in/dansloat'>http://www.linkedin.com/in/dansloat</a></td></tr></table>");
	
}

function sorter(the_array, pri_index, p_sort, sec_index, s_sort, ter_index, t_sort) {
    for (a=0; a<the_array.length; a++) {
	the_array[a][the_array[a].length] = a;
    }
    var holder = new Array();
	for (i=1; i<the_array.length; i++) {
	    for (j=i; j>0; j--) {
   		if (((p_sort == "f") && (the_array[j][pri_index] < the_array[j-1][pri_index])) || ((p_sort == "r") && (the_array[j][pri_index] > the_array[j-1][pri_index]))) {
		    holder = the_array[j-1];
   		    the_array[j-1] = the_array[j];
   		    the_array[j] = holder;
   		} else {
   		    if ((the_array[j-1][pri_index] == the_array[j][pri_index]) && (((s_sort == "f") && (the_array[j][sec_index] < the_array[j-1][sec_index])) || ((s_sort == "r") && (the_array[j][sec_index] > the_array[j-1][sec_index])))) {
   			holder = the_array[j-1];
   			the_array[j-1] = the_array[j];
   			the_array[j] = holder;			  
   		    } else {
   			if ((the_array[j-1][pri_index] == the_array[j][pri_index]) && (the_array[j-1][sec_index] == the_array[j][sec_index]) && (((t_sort == "f") && (the_array[j][ter_index] < the_array[j-1][ter_index])) || ((t_sort == "r") && (the_array[j][ter_index] > the_array[j-1][ter_index])))) {
   			    holder = the_array[j-1];
   			    the_array[j-1] = the_array[j];
   			    the_array[j] = holder;		  	
   			}
   		    }
   		}
	     }
	 }
    return the_array;		 
}

var oldArg;
function getTable(parentName) {
	var currentList = new Array();
	for (c=0;c<node_array.length;c++) {
		if (node_array[c][2] == parentName) {
		    currentList[currentList.length] = node_array[c];
			    currentList[currentList.length-1][currentList[currentList.length-1].length] = c;
	    }
	}
	document.write("<a name='" + parentName.substr(0,3) + "'>&nbsp;</a><br>");
	document.write("<span class='header'>" + parentName + "</span><br>");
	document.write("<center><table border=0 cellpadding=3 cellspacing='1' bgcolor='#dddddd' width='75%'>");
		for (e=0;e<currentList.length;e++) {
			document.write("<tr>");
				   if (currentList[e][2] == node_array[0][0]) {
				   	  document.write("<td bgcolor='#ffffff' width='25%'><a href='" + currentList[e][4] + "'>" + currentList[e][0] + "</a></td>");
				   } else {
					  if (currentList[e][1] == "GPFLink") {
					  	 document.write("<td bgcolor='#ffffff' width='25%' class=\"followCell\" align='center'><br /><a href=" +  currentList[e][4] + "><img src='" + imageURL + currentList[e][5] + "' border='0' /><br />" + currentList[e][0] + "</a><br /><br /></td>");
					  } else {
					  	 document.write("<td bgcolor='#ffffff' width='25%' class=\"followCell\"><br /><a href=\"sloat/linkFrame_2x.html?" +  oldArg + "&" + currentList[e][currentList[e].length-1] + "\">" + currentList[e][0] + "</a><br /><br /></td>");
					  }					  
				   }
				   document.write("<td bgcolor='#ffffff' class='tableCell'>" + currentList[e][6] + "</td>");
			document.write("</tr>");	
		}
	document.write("</table></center>")	
}

function subTable() {
    var subCats = new Array();
	for (b=0; b<node_array.length; b++) {
		if (node_array[b][2] == node_array[0][0]) {
		   subCats[subCats.length] = node_array[b];
		}	
	}
	subCats = sorter(subCats, 0, "f", 4, "f", 6, "f");
   	document.write("<table border=0 cellpadding=0 cellspacing=0 width='100%'>");
   	   for (a=0; a<subCats.length; a++) {
   		  document.write("<tr><td>");
   		  document.write("<br><br>");
   		       //subCats = sort_list_array(subCats, 0, 4, 3);		   
			   if (subCats[a][1] == "Link") {
   		           getTable(subCats[a][0]);
			   } else if (subCats[a][1] == "Image") {
			       image_grid(subCats[a][0], "4", "4", "Name", "Date", "File Name");
			   }
   		  document.write("</td></tr>");
       	  document.write("<tr><td align='right'><a href='#aTop' class=''>Back to the top.</a></td></tr>");		
   	   }
   	document.write("</table>");
}

function build_page(currentLoc, pageIndex) {
    oldArg = coder(currentLoc);
    header(currentLoc);
	if (array_type[0] == "Gallery") {
    	var maxNumInRow = array_type[2];
    	var maxNumOfRows = array_type[3];
    	
    	var endOfLoop = 0;
    	if ((eval(pageIndex) + (eval(array_type[2]) * eval(array_type[3]))) < node_array.length) {
    		endOfLoop = (eval(pageIndex) + (eval(array_type[2]) * eval(array_type[3])));	
    	} else {
    		endOfLoop = node_array.length;
    	}
    	//alert(endOfLoop + ": " + eval(pageIndex) + ": " + (eval(array_type[2]) * eval(array_type[3])));	
    	
    	 
    	    var imageCounter = pageIndex; //0;
    		remote_box();
    	    document.write("<table border=0 cellpadding=10 cellspacing=10 align='center'>");
    	    sorter(node_array, sorting[0], sorting[1], sorting[2], sorting[3], sorting[4], sorting[5]);
    	    for (a=0; a<maxNumOfRows; a++) {
    		document.write("<tr>");
    	            for (b=0; b<maxNumInRow; b++) {
    			    if (imageCounter < endOfLoop) { //node_array.length) {	        
    				document.write("<td align='center' valign='top' class='imageCaption'>");				
    					for (c=0; c<gallery_options.length; c++) {
							if (gallery_options[c] == "top") {
							   document.write(node_array[imageCounter][gallery_options[c-1]] + "<hr><br>");
							}
						}
    				document.write("<a href=\"JavaScript: get_image(\'" + oldArg + "\'\,\'" + node_array[imageCounter][4] + "\'" + "\,\'" + node_array[imageCounter][0] + "\')\"\;\>");
    				document.write("<img src='" + imageURL + node_array[imageCounter][4].substr(0,node_array[imageCounter][4].length-4) + "Th.jpg' alt=\"" + node_array[imageCounter][0] + "\" name='" + node_array[imageCounter][0] + "' border='0'></a>");
						for (c=0; c<gallery_options.length; c++) {
							if (gallery_options[c] == "bottom") {
							   document.write("<br><hr>" + node_array[imageCounter][gallery_options[c-1]]);
							}
						}
    				document.write("</td>");
    	                        imageCounter++;
    			    }	
    	            }
    		document.write("</tr>");
    	    }
    	
            document.write("</table>");
    		//alert(parseInt(node_array.length/(eval(array_type[2]) * eval(array_type[3]))+1));
    	  	document.write("<table border=0><tr><td class='textS'>Pages:&nbsp;</td>");
    		for (a=0; a<parseInt(node_array.length/(eval(array_type[2]) * eval(array_type[3]))+1); a++) { //a>=0; a--){
    
    			if ((a*(eval(array_type[2]) * eval(array_type[3]))) == pageIndex) {    //(parseInt(node_array.length/(eval(array_type[2]) * eval(array_type[3])))-a) == (pageIndex/(eval(array_type[2]) * eval(array_type[3])))) {
    			   document.write("<td class='textM'><b>" + (a+1) + "</b></td>");		
    			}else{
    			   document.write("<td class='textM'><a href='" + homeURL + "GPF.html?" + currentLoc + "&" + (a*(eval(array_type[2]) * eval(array_type[3]))) + "'>" + (a+1) + "</a></td>");		
    			}
    		}
    		document.write("</tr></table>");
 
   			
	} else if (array_type[0] == "Table") {

	    document.write("<table width='100%' border=0 cellpadding=0 cellspacing=0 bgcolor='#ffffff'\>");
	    document.write("<tr>");
	    document.write("<td>");
	    document.write("<br><br>");
	    getTable(node_array[0][0]);
	    document.write("<br><br><hr>");
	    document.write("</td>");
	    document.write("</tr>");
	    document.write("<tr>");
	    document.write("<td>");
	    subTable(); 
	    document.write("</td>");
	    document.write("</tr>");
	    document.write("</table>");

	} else if (array_type[0] == "Timeline") {
    	var maxNumInRow = array_type[2];
    	var maxNumOfRows = array_type[3];
    	
    	var endOfLoop = 0;
    	if ((eval(pageIndex) + (eval(array_type[2]) * eval(array_type[3]))) < node_array.length) {
    		endOfLoop = (eval(pageIndex) + (eval(array_type[2]) * eval(array_type[3])));	
    	} else {
    		endOfLoop = node_array.length;
    	}
    	sorter(node_array,  sorting[0], sorting[1], sorting[2], sorting[3], sorting[4], sorting[5]);
		var imageCounter = pageIndex;
		remote_box();
		
           //Row 1 of 4 (Dates):		   
          	document.write("<br><br><br><table border=0 cellspacing=0 cellpadding=0><tr><td></td>");
         	for (a=pageIndex; a<endOfLoop; a++) {
         		document.write("<td align='center' class='textM'><b>" + node_array[imageCounter][6] + "</b></td>");
				imageCounter++;
         	}
         	document.write("<td></td></tr>");
           //Row 2 of 4 (Pictures/Text):
          	document.write("<tr><td></td>");
         	var theAlignment = "top"
			imageCounter = pageIndex;
         	for (a=pageIndex; a<endOfLoop; a++) {	
         		if (theAlignment == "top") {
         		   document.write("<td align='center' valign='bottom' class='textM'><a href=\"JavaScript: get_image(\'" + oldArg + "\'\,\'" + node_array[imageCounter][4] + "\'" + "\,\'" + node_array[imageCounter][0] + "\')\"\;\><img src='" + imageURL + node_array[imageCounter][4].substr(0,node_array[imageCounter][4].length-4) + "Th.jpg' alt=\"" + node_array[imageCounter][0] + "\" name='" + node_array[imageCounter][0] + "' border=3></a></td>");
         		   theAlignment = "bottom";				
         		} else {
         		   document.write("<td align='center'><a href=\"JavaScript: get_image(\'" + oldArg + "\'\,\'" + node_array[imageCounter][4] + "\'" + "\,\'" + node_array[imageCounter][0] + "\')\"\;\>" + node_array[imageCounter][0] + "</a></td>");
         		   theAlignment = "top";
         		}
				imageCounter++;
         	}
         	document.write("<td></td></tr>");	
           //Row 3 of 4 (Line):
         	if (eval(pageIndex) == 0) {
         	 	document.write("<tr><td><img src='Images/time_line_start.gif' border=0></td>");
         	} else {
         	 	document.write("<tr><td><a href='" + homeURL + "GPF.html?" + currentLoc + "&" + (eval(pageIndex)-(eval(array_type[2]) * eval(array_type[3]))) + "'><img src='Images/time_line_last.gif' border=0></a></td>");		
         	}
         	var theAlignement = "top"
			imageCounter = pageIndex;
         	for (a=pageIndex; a<endOfLoop; a++) {	
         		if (theAlignment == "top") {
         		   document.write("<td><img src='Images/time_line_top.gif' border=0></td>");
         		   theAlignment = "bottom";
         		} else {
         		   document.write("<td><img src='Images/time_line_bottom.gif' border=0></td>");
         		   theAlignment = "top";
         		}
				imageCounter++;
         	}
         	if ((eval(pageIndex) + (eval(array_type[2]) * eval(array_type[3]))) < node_array.length) {
         	 	document.write("<td><a href='" + homeURL + "GPF.html?" + currentLoc + "&" + (eval(pageIndex)+(eval(array_type[2]) * eval(array_type[3]))) + "'><img src='Images/time_line_next.gif' border=0></a></td></tr>");		
         	} else {
         	 	document.write("<td><img src='Images/time_line_end.gif' border=0></td></tr>");
         	}
           //Row 4 of 4 (Text/Picture):
		   
          	document.write("<tr><td></td>");
         	var theAlignment = "top"
			imageCounter = pageIndex;
         	for (a=pageIndex; a<endOfLoop; a++) {	
         		if (theAlignment == "top") {
         		   document.write("<td align='center' valign='top' class='textM'><a href=\"JavaScript: get_image(\'" + oldArg + "\'\,\'" + node_array[imageCounter][4] + "\'" + "\,\'" + node_array[imageCounter][0] + "\')\"\;\>" + node_array[imageCounter][0] + "</a></td>");
         		   theAlignment = "bottom";
         		} else {
         		   document.write("<td align='center'><a href=\"JavaScript: get_image(\'" + oldArg + "\'\,\'" + node_array[imageCounter][4] + "\'" + "\,\'" + node_array[imageCounter][0] + "\')\"\;\><img src='" + imageURL + node_array[imageCounter][4].substr(0,node_array[imageCounter][4].length-4) + "Th.jpg' alt=\"" + node_array[imageCounter][0] + "\" name='" + node_array[imageCounter][0] + "' border=3></a></td>");
         		   theAlignment = "top";
         		}
				imageCounter++;
         	}		   
         	document.write("<td></td></tr><tr><td></td></tr></table>");						 
			
			document.write("<table border=0><tr><td class='textS'>Pages:&nbsp;</td>");
			for (a=parseInt(node_array.length/(eval(array_type[2]) * eval(array_type[3]))); a>=0; a--){
				if ((parseInt(node_array.length/(eval(array_type[2]) * eval(array_type[3])))-a) == (pageIndex/(eval(array_type[2]) * eval(array_type[3])))) {
				   document.write("<td class='textM'><b>" + (a+1) + "</b></td>");		
				}else{
				   document.write("<td class='textM'><a href='" + homeURL + "GPF.html?" + currentLoc + "&" + ((parseInt(node_array.length/(eval(array_type[2]) * eval(array_type[3])))-a)*(eval(array_type[2]) * eval(array_type[3]))) + "'>" + (a+1) + "</a></td>");		
				}
		    }
			document.write("</tr></table>");
	}
    footer();
}








