/* index.js */

/**
*** Scramble Text
**/

var text = "";

function scrambleText(element) {

	var elementName = element.id;

	text = document.getElementById(elementName).innerHTML;
	var elementNameLength = text.length;

	var codeArr = new Array();
	for (var x = 0; x < elementNameLength; x++) {
		codeArr[x] = document.getElementById(elementName).innerHTML.substr(x,1);
	}

	var randomNum;
	var listArr = new Array();

        for (x = 0; x < elementNameLength; x++) {
		randomNum = Math.floor(Math.random() * codeArr.length); 
		listArr[x] = codeArr.splice(randomNum,1);
		if (listArr[x] == " ") {
			listArr[x] = "&#160;"; // prevents blank member
		}
    	}

	var val = "";
  	for (x in listArr) {
		val += listArr[x];
	}

	document.getElementById(elementName).innerHTML = val;
}

function normalizeText(element) {

	var elementName = element.id;
	document.getElementById(elementName).innerHTML = text;
}

function domainEffects() {

	var randomNum = Math.floor(Math.random() * 9); 
	var choice = new Array();
	choice[0] = " Greetings, friend! ";
	choice[1] = " Welcome, traveller! ";
	choice[2] = " Well, hello there! ";
	choice[3] = " Thanks for stopping by! ";
	choice[4] = " Good of you to visit! ";
	choice[5] = " Stay as long as you like! ";
	choice[6] = " Failte! ";
	choice[7] = " Say 'friend' and enter! ";
	choice[8] = " Click Me! ";
	var theChoice = choice[randomNum];
	document.getElementById("domain").title = theChoice;	
}

function castleEffects() {

	var imageFile = document.getElementById("castle").src;
	var lengthOfFile = imageFile.length - 7;

	// substr - if start is negative, IE returns the whole string!
	// using slice instead
	var imageFile2 = imageFile.slice(lengthOfFile);

	if (imageFile2 != "red.jpg") {	
		document.getElementById("castle").src = "images/castle_red.jpg";	
	} else {
		document.getElementById("castle").src = "images/castle.jpg";	
	}
}

function contactEffects() {

	if (document.getElementById("contact").style.color != "black") {
		document.getElementById("contact").style.color = "black";
		document.getElementById("contact").style.borderTop = "1px solid black";
	} else {
		document.getElementById("contact").style.color = "#000080";
		document.getElementById("contact").style.border = "none";
	}

}

/**
*** next functions change some text color to random colors
**/

var timer = "";
var randCol = "";
var randomColorCounter = 1;
var isColorChanging = "no";

function startRandomColorFunctions() {

	if (randomColorCounter % 2 != 0) {
		isColorChanging = "yes";
		turnRandomColor();
		turnRandomColor2();
		turnRandomColor3();
		turnRandomColor4();
		randomColorCounter++;
	} else {
		isColorChanging = "no";
		clearTimeout(timer);
		document.getElementById("textColorChange").style.color = "#fff";
		document.getElementById("textColorChange2").style.color = "#fff";
		document.getElementById("textColorChange3").style.color = "#fff";
		document.getElementById("textColorChange4").style.color = "#fff";
		randomColorCounter++;
	}
}

function turnRandomColor() {
    if (isColorChanging == "yes") {
	timer = setTimeout("turnRandomColor()", 100); 
        randCol = randomColorValue();
        document.getElementById("textColorChange").style.color = "#" + randCol;  
    }  
}

function turnRandomColor2() {
        if (isColorChanging == "yes") {
		timer = setTimeout("turnRandomColor2()", 150); 
        	randCol = randomColorValue();    
        	document.getElementById("textColorChange2").style.color = "#" + randCol;   
        }    
}

function turnRandomColor3() {
        if (isColorChanging == "yes") {
		timer = setTimeout("turnRandomColor3()", 200); 
        	randCol = randomColorValue();
        	document.getElementById("textColorChange3").style.color = "#" + randCol; 
        }     
}

function turnRandomColor4() {
        if (isColorChanging == "yes") {
		timer = setTimeout("turnRandomColor4()", 250); 
       		randCol = randomColorValue();
        	document.getElementById("textColorChange4").style.color = "#" + randCol;  
        }    
}

function randomColorValue() {

        // array to hold hexadecimal numbers
        var hexNum = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];

        var digit = [5]; // array to hold 6 digits
        var randomColor = "";

        // loop through array 6 times, storing each digit's value in digit[i]
        for (var i = 0; i < 6; i++) {
            digit[i] = Math.floor(Math.random() * 16); 
            randomColor = randomColor + hexNum[digit[i]];  
        }  

        return randomColor;
}

/**
*** display right nav links
**/

function revealLinks(num) {

	/* for innerHTML bug in IE */
	var newdiv = "";
	var container = "";

	document.getElementById("tidbits_text").innerHTML = "";
	document.getElementById("tidbits_heading").innerHTML = "Tidbits";

	if (num == 0) {

	    if (document.getElementById("ref_h2").innerHTML == "home") {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>From this junction point the site is divided into several main categories, which can be accessed by using the navigational menu on the left side of the screen. If at any time you wish to return to this page, simply click on the <span onmouseover='castleEffects()' onmouseout='castleEffects()'><i>castle</i></span> icon.</p>";

	    } else if (document.getElementById("ref_h2").innerHTML == "codefolio") {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>Mousing over the <span onmouseover='codefolioLinkActive()' onmouseout='codefolioLinkUnactive()'><i>Codefolio</i></span> link on the left will open up a list of possible program selections on the right.<br><br>Some of the scripts were made from scratch, and some of them were pieced together by taking various chunks of available code and modifying them slightly so that they would function correctly in a new context.</p>";

	    } else if (document.getElementById("ref_h2").innerHTML == "designs") {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>Mousing over the <span onmouseover='designsLinkActive()' onmouseout='designsLinkUnactive()'><i>Designs</i></span> link on the left will open up a list of possible web designs on the right.<br><br>Some of these designs are pretty old and will be updated and/or replaced with new designs in the future.</p>";

	    } else if (document.getElementById("ref_h2").innerHTML == "games") {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>Mousing over the <span onmouseover='gamesLinkActive()' onmouseout='gamesLinkUnactive()'><i>Games</i></span> link on the left will open up a list of possible browser-based web games on the right.<br><br>Some of these games are pretty old and will be updated and/or replaced with new games in the near future.</p>";

	    } else if (document.getElementById("ref_h2").innerHTML == "careers") {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>Career Ruler demands no upfront fees to pay or credit card numbers to dig up. Neither is there any negotiation with employers to extract a service charge from your wages.</p>";

	    } else if (document.getElementById("ref_h2").innerHTML == "careerForm") {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>All form fields must be green to submit your information successfully. If a field is not green, please check that the data you entered is in the correct format and that no fields are left blank. A copy of your information will then be emailed to you for your own records, and you should receive a response within 4 business days.</p>";

	    }

           

	} else if (num == 1) {

		document.getElementById("tidbits_heading").innerHTML = "/Codefolio";
		newdiv = document.createElement("div");
newdiv.innerHTML = "<div id='submenu'><a href='#'>Javascript</a><ul><li><a href='http://celtruler.com/codefolio/javascript/allColorValues.html'> &#160;All Color Values </a></li><li><a href='http://celtruler.com/codefolio/javascript/generatedTable.html'> &#160;Generated Table </a></li><li><a href='http://celtruler.com/codefolio/javascript/parseXMLDoc.html'> &#160;Parse XML Doc </a></li><li><a href='http://celtruler.com/codefolio/javascript/randomColors.html'> &#160;Random Colors </a></li><li><a href='http://celtruler.com/codefolio/javascript/scrambleText.html'> &#160;Scramble Text </a></li></ul><br><a href='#'>PHP</a><ul><li><a href='http://celtruler.com/codefolio/php/uploadImage.php'> &#160;Upload Image </a></li></ul></div>";

	} else if (num == 2) {

		document.getElementById("tidbits_heading").innerHTML = "/Designs";
		newdiv = document.createElement("div");
newdiv.innerHTML = "<div id='submenu'><a href='#'>Corporate</a><ul><li><a href='http://celtruler.com/designs/rainyDays.html'> &#160;Rainy Days </a></li><li><a href='http://celtruler.com/webdesign/foobar.html'> &#160;Simple Layout </a></li></ul><br><a href='#'>Image Coding</a><ul><li><a href='http://ozpearlman.com/photos.php' target='_blank'> &#160;OZ Pearlman </a></li><li><a href='http://72.9.151.113/~westcoast/gallery/index.php' target='_blank'> &#160;West Coast Canvas </a></li></ul><br><a href='#'>User Interface</a><ul><li><a href='http://celtruler.com/webdesign'> &#160;Product Menu </a></li><li><a title='Under Construction!' href='http://celtruler.com/restaurants/samurai_sams.php'> &#160;Restaurant Menu </a></li></ul></div>";

	} else if (num == 3) {

		document.getElementById("tidbits_heading").innerHTML = "/Games";
		newdiv = document.createElement("div");
newdiv.innerHTML = "<div id='submenu'><a href='#'>Multi Player</a><ul><li><a href='http://celtruler.com/games/bards'> &#160;Bards </a></li></ul><br><a href='#'>Shooter</a><ul><li><a href='http://celtruler.com/games/flash/game.html'> &#160;(Linux Flash Demo) </a></li></ul><br><a href='#'>Text Adventure</a><ul><li><a href='http://celtruler.com/games/goldensword'> &#160;Golden Sword </a></li></ul></div>";

	} else if (num == 4) {

		newdiv = document.createElement("div");
newdiv.innerHTML = "<p style='text-align: left' id='tidbits_text'>Career Ruler started as an alternative to all of the websites out there promising to get you that <i>perfect</i> job.</p>";

	}
	    
	
	container = document.getElementById("tidbits_text");
	container.appendChild(newdiv);

}

