/****************************/
/* LR Brown Javascript      */
/* Coded by Jennifer Dungan */
/* www.jenniferdungan.com   */
/****************************/

window.onload = function()
{
	var linkArray = new Array();
	var temp = "";
	
	linkArray = document.getElementsByTagName("a");
	
	for (i=0; i<linkArray.length; i++)
	{
		temp = linkArray[i];
		if (temp.getAttribute("class")=="blank")
		{
			temp.setAttribute("target", "_blank");
		}
	}
	
	// put an onsubmit action on the form
	if ($("brownform"))
	{
		var theForm = $("brownform");
		theForm.onsubmit = function()
		{
			return validateForm();
		}
	}
	
	if ($("photoshow"))
	{
		loadImages();
	}
}

// Validate Form
function validateForm()
{
	// create vars for each field
	var fName = $("fName");
	var lName = $("lName");
	var phone = $("phone");
	var email = $("email");
	var info = $("info");

	var yesno = true;
	var emailCheck = false;
	var message = "";
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	
	//check if any of those fields is ""
	if (fName.value == "")
	{
		message += "First name is a required field.\n";
		yesno = false;
	}
	if (lName.value == "")
	{
		message += "Last name is a required field.\n";
		yesno = false;
	}
	if (phone.value =="")
	{
		message += "Phone number is a required field.\n";
		yesno = false;
	}
	if (email.value == "")
	{
		message += "Email is a required field.\n";
		yesno = false;	
	}
	else
	{
		if (re.test(email.value))
		{
			emailCheck = true;
		}
		else
		{
			message += "Email entered is invalid.\n";
		}
	}
	
	if (yesno == false || emailCheck == false)
	{
		alert(message);
		return false;
	}
	else
	{
		return true;
	}
}


/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html

**************************************************************************************

Image Cross Fade Redux
Version 1.x??
Revised May 3rd, 2006
Jennifer Dungan

Rewrite of code found here: http://slayeroffice.com/code/imageCrossFade/xfade2.html

- added image preloader
- updated code to work with prototype.js


*****/


/* Image Cross Fade Redux starts here ****************************************************/

imgs = new Array();
zInterval = null;
current = 0;
pause = false;

function loadImages()
{
	new Insertion.Bottom('photoshow', '<img src="http://www.lrbrown.com/images/photo2.jpg" width="336" height="252" alt="Projection Screens in a lecture hall" id="img2" /><img src="http://www.lrbrown.com/images/photo3.jpg" width="336" height="252" alt="Projection Screen at a church" id="img3" /><img src="http://www.lrbrown.com/images/photo4.jpg" width="336" height="252" alt="Overhead Projector" id="img4" /><img src="http://www.lrbrown.com/images/photo5.jpg" width="336" height="252" alt="Projection Screen at a school" id="img5" /><img src="http://www.lrbrown.com/images/photo6.jpg" width="336" height="252" alt="Projection Screen behind curved desk" id="img6" /><img src="http://www.lrbrown.com/images/photo7.jpg" width="336" height="252" alt="Projection Screen behind curved desk - different angle" id="img7" />');
	slideshow();
}

function slideshow() {
	if(!document.getElementById || !document.createElement)return;
	
	css = document.createElement("link");
	css.setAttribute("href","http://www.lrbrown.com/styles/xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	document.getElementsByTagName("head")[0].appendChild(css);
	
	imgs = $("img1", "img2", "img3", "img4", "img5", "img6", "img7");
	
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade,2000);
	
}


function so_xfade() {
	
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,2000);
	} else {
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

/* Image Cross Fade Redux ends here ****************************************************/

