var quotes = new Array(
 "\"So, Lone Star, now you see that evil will always triumph because good is dumb.\" - Dark Helmet",
 "\"To live, you must be willing to die.\" - Amir Vahedi",
 "\"It's immoral to let a sucker keep his money.\" - <i>Rounders</i>",
 "\"Tomorrow we will run faster, stretch out our arms farther...\" - <i>The Great Gatsby</i>",
 "\"I can accept failure. Everyone fails at something. But I can't accept not trying.\" - Michael Jordan",
 "\"Feet fail me not cuz maybe the only opportunity that I got\" - Eminem",
 "\"Destiny is calling me, open up my eager eyes\" - The Killers",
 "\"Only a fool is sure of anything, a wise man keeps on guessing.\" - MacGyver",
 "\"Sometimes my life just don't make sense at all\" - Rich Mullins",
 "\"Who wants everything to come easily?\" - Tom Brady",
 "\"In matters of style, swim with the current. In matters of principle, stand like a rock.\" - Thomas Jefferson",
 "\"Words offer the means to meaning and for those who will listen, the annunciation of truth\" - <i>V for Vendetta</i>"
);

var styles = new Array();
	styles["optimistic"] = "styles-site.css";
	styles["new"] = "main2.css";
	styles["sunny"] = "sunny.css";
	styles["somber"] = "somber.css";
	
function showQuote() {
	var index = Math.floor(Math.random() * quotes.length);
	document.getElementById("quoteBlock").innerHTML = quotes[index];
	
	setTimeout("showQuote()",10000);
}


function swapStyles(ancElem) {
	var title = ancElem.innerText;

	var linkArr = document.getElementsByTagName("link");
  	for (var i=0; i<linkArr.length; i++) {
  		var linkNode = linkArr[i];
  		var relAttr = linkNode.getAttribute('rel');
  		if (relAttr && (relAttr.indexOf("style") != -1) && linkNode.getAttribute("title")) {
  			linkNode.disabled = true;
  		  	if (linkNode.getAttribute("title") == title)
  		    	linkNode.disabled = false;
  		}
  	}

	/*
	var elemId = "style" + ancElem.innerText;
	var cssElem = document.getElementById(elemId);

	for (var i=0; i<linkArr.length; i++) {
		if (cssElem == linkArr[i]) {
			linkArr[i].rel = "stylesheet";
			//linkArr[i].disabled = false;
		} else {
			linkArr[i].rel = "alternate";
			//linkArr[i].disabled = true;
		}
	}
	*/

	//cssElem.href = styles[ancElem.innerText];
	//alert(styles[ancElem.innerText])

	var aColor = ancElem.style.color;

	var ancArr = ancElem.parentNode.getElementsByTagName("a");
	for (var i=0; i<ancArr.length; i++) {
		ancArr[i].style.color = aColor;
		ancArr[i].style.textDecoration = "underline";
	}
	
	ancElem.style.color = document.getElementById("banner").style.color;
	ancElem.style.textDecoration = "none";
}



var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1 && document.all);
var is_ie5=(agt.indexOf("msie 5")!=-1 && document.all);

function XmlHttpCreate(){
	var xmlhttp = null;
	if(is_ie){
		var control=(is_ie5)?"Microsoft.XMLHTTP":"Msxml2.XMLHTTP";
		try{
			xmlhttp=new ActiveXObject(control);
		} catch(e) {
			DumpException(e);
			alert("You need to enable active scripting and activeX controls.");
		}
	} else {		
		xmlhttp=new XMLHttpRequest();
		if(!xmlhttp){
			alert("XMLHttpRequest is not supported on this browser.");
		}
	}
	return xmlhttp;
}

function XmlHttpGET(xmlhttp, url, handler){
	xmlhttp.onreadystatechange=handler;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function XmlHttpPOST(xmlhttp, url, data, handler){
	xmlhttp.onreadystatechange=handler;
	xmlhttp.open("POST",url,true);
	xmlhttp.send(data);
}

function getFlickrImage() {
	var url = "http://www.flickr.com/badge_code.gne?nsid=63138566@N00&count=1&display=random&name=0&size=mid&raw=1";

	var xmlhttp=XmlHttpCreate();
	var handler = function() {
	  	if (xmlhttp.readyState == 4) {
	  		alert(xmlhttp.responseText)
				document.getElementById("flickr").innerHTML=xmlhttp.responseText;
				//alert(xmlhttp.responseText);
				
				setTimeout("getFlickrImage()",3000);
		}
	}
	XmlHttpGET(xmlhttp, url, handler);
}

function getPosition(elem) {
	// determine exact placement of list (stolen from popup calendar script)
	var topPos 	= 0;
	var leftPos = 0;
	var parElem	= elem;
	do {
		//alert(parElem.id)
		if (parElem.offsetParent == null) {
			break;
		}
		topPos 	+= parElem.offsetTop;
		leftPos	+= parElem.offsetLeft;
		parElem = parElem.offsetParent;

		//alert(parElem.id + ":\nleftPos = " + leftPos + "\ntopPos = " + topPos)

	} while (parElem.tagName != "BODY" & parElem.tagName != "HTML");
	
	var posInfo 	= new Array();
	posInfo.top 	= topPos;
	posInfo.left 	= leftPos;

	return posInfo;	
}

function showCmtForm(ancElem,entryId) {
	var id = entryId.split("a")[1];
		id = parseInt(id);
	
	var divForm = document.getElementById("cmtForm");
	if (divForm == null) {
		divForm = document.createElement("div");
		divForm.id = "cmtForm";
	}
	divForm.style.display = "block";

	var posData = getPosition(ancElem);
	divForm.style.left 	= posData.left;
	divForm.style.top  	= posData.top + 20;


	var html  = "<form name=\"comments_form\">";
		html += "<input type=\"hidden\" name=\"static\" value=\"1\" />";
		html += "<input type=\"hidden\" name=\"entry_id\" value=\"" + id + "\" />";
		html += "<div id=\"name_email\">";
		html += "	<p>"
		html += "		<label for=\"author\">Name:</label>";
		html += "		<input tabindex=\"1\" id=\"author\" name=\"author\" />";
		html += "	</p><br />";
		html += "	<p>";
		html += "		<label for=\"email\">Email Address:</label>";
		html += "		<input tabindex=\"2\" id=\"email\" name=\"email\" />";
		html += "	</p><br />";
		html += "</div>";	
		html += "<p>";
		html += "	<label for=\"URL\">URL:</label>";
		html += "	<input tabindex=\"3\" type=\"text\" name=\"url\" id=\"url\" /><br />";
		html += "	Remember Me?";
		html += "	<input type=\"radio\" class=\"radio\" id=\"remember\" name=\"bakecookie\" onclick=\"rememberMe(this.form)\" /><label for=\"remember\">Yes</label>";
		html += "	<input type=\"radio\" class=\"radio\" id=\"forget\" name=\"bakecookie\" onclick=\"forgetMe(this.form)\" value=\"Forget Info\" style=\"margin-left: 15px;\" /><label for=\"forget\">No</label>";
		html += "	<br style=\"clear: both;\" />";
		html += "</p>";
		html += "<p>";
		html += "	<label for=\"text\">Comments:</label> (you may use HTML tags for style)<br/>";
		html += "	<textarea tabindex=\"4\" id=\"text\" name=\"text\" rows=\"10\" cols=\"50\"></textarea>";
		html += "</p>";
		html += "<div align=\"center\">";
		//html += "	<input type=\"submit\" name=\"preview\" tabindex=\"5\" value=\"&nbsp;Preview&nbsp;\" />";
		//html += "	<input style=\"font-weight: bold;\" type=\"submit\" name=\"post\" tabindex=\"6\" value=\"&nbsp;Post&nbsp;\" onclick=\"submitCmtForm(this)\" />";
		html += "	<button style=\"font-weight: bold;\" type=\"button\" name=\"post\" tabindex=\"6\" onclick=\"submitCmtForm(this)\" />Post</button>";
		html += "</div>";
		html += "</form>";
	
	divForm.innerHTML = html;

	document.body.appendChild(divForm);
	
	ancElem.innerText = "Close Comments";
	ancElem.onclick = function () { hideCmtForm(this,entryId); };
}

function hideCmtForm(ancElem,entryId) {
	var divForm = document.getElementById("cmtForm");
	divForm.style.display = "none";
	divForm.innerHTML = "";

	ancElem.innerText = "Add Comment";
	ancElem.onclick = function () { showCmtForm(this,entryId); };
}


function submitCmtForm(btnElem) {
	var frmCmt = btnElem.parentNode.parentNode;
	
	if (frmCmt.bakecookie[0].checked) 
		rememberMe(this);
		
	
}

