window.onload = init;
function init() {
	if(document.getElementsByTagName("body")[0].className == "home") {
		doTabs();
	}
	if(document.getElementsByTagName("body")[0].className == "signup") {doForm();}
	hideEmail();
	rollOvers();
}

function doTabs() {
  // $("#left").find("a").click(function(){
  //     $("#left li").removeClass("active");
  //     $(this).parent().addClass("active");
  //     var no = $(this).attr("id");
  //     $.getJSON("/retail/tidbit/" + no, function(d){
  //       // these are the codes that made the full-on cms work. 
  //       // var oView = $("#overview > div")
  //       // oView.empty(); 
  //       // oView.append(d["overview"]).css("display", "block");
  //       // these are the codes that make the partly-cms work.
  //       $("#overview").empty().append(d["overview"]);
  //       $("#overview > div").css("display", "block");
  //       $("#content").empty();
  //       $("#content").append(d["content"]);
  //       document.title = "Playbook | " + d["title"]
  //   });      
  // });    
  // $('#content').children().eq(0).show();
}

function doForm() {
	var name = document.getElementById("name");
	name.onfocus = function() {if(this.value == "Your Name") {this.value = "";}}
	name.onblur = function() {if(this.value == "") {this.value = "Your Name";}}
	var email = document.getElementById("email");
	email.onfocus = function() {if(this.value == "Your E-Mail") {this.value = "";}}
	email.onblur = function() {if(this.value == "") {this.value = "Your E-Mail";}}
}
function hideEmail() {
	var alltags = document.all? document.all : document.getElementsByTagName("*");
	for (i=0; i < alltags.length; i++) {
		if (alltags[i].className == "hideMe") {
			var oldText = alltags[i].firstChild;
			var emailAddress = alltags[i].firstChild.nodeValue;
			var user = emailAddress.substring(0, emailAddress.indexOf("("));
			var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			var newText = user+"@"+website;
			var a = document.createElement("a");
			a.href = "mailto:"+newText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			alltags[i].replaceChild(a,oldText);
		}
  	}
}
function rollOvers() {
	if(document.getElementById) {
		var images = document.getElementsByTagName('IMG');
		var buttons = document.getElementsByTagName('INPUT');
	}
	else if(document.all) {
		var images = document.all.tags('IMG');
		var buttons = document.all.tags('INPUT');
	}
	else return;
	preloads = new Object();
	for (var i = 0; i < images.length; i++) {
		var imageOffSrc = images[i].src + "";
		if(imageOffSrc.indexOf("_off") != -1) {
			var imageOverSrc = imageOffSrc.replace(/_off/g, "_over");
			preloads['imageOff_' + i] = new Image();
			preloads['imageOff_' + i].src = imageOffSrc;
			preloads['imageOver_' + i] = new Image();
			preloads['imageOver_' + i].src = imageOverSrc;
			images[i].onmouseover = function(){this.src = this.src.replace(/_off/g, "_over");}
			images[i].onmouseout = function(){this.src = this.src.replace(/_over/g, "_off");}
		}
	}
	for (var i = 0; i < buttons.length; i++) {
		if(buttons[i].src) {
			var imageOffSrc = buttons[i].src + "";
			if(imageOffSrc.indexOf("_off") != -1) {
				var imageOverSrc = imageOffSrc.replace(/_off/g, "_over");
				preloads['imageOff_' + i] = new Image();
				preloads['imageOff_' + i].src = imageOffSrc;
				preloads['imageOver_' + i] = new Image();
				preloads['imageOver_' + i].src = imageOverSrc;
				buttons[i].onmouseover = function(){this.src = this.src.replace(/_off/g, "_over");}
				buttons[i].onmouseout = function(){this.src = this.src.replace(/_over/g, "_off");}
			}
		}
	}
}

