var currentMessage = 0;
var siteMessages = new Array("Speaker at conferences across the globe<br>Unique and practical insights into organisational culture", "Creator of the concept of UGRs<br> A tool to understand and boost culture", "Unique and practical insights into customer service<br> through Steve's 'Discretionary Service' concept", "No hype.<br> Just result-driven insights and strategies that work. ");

var currentSmallPhoto = Math.floor(Math.random()*2);
var imageSmallArray = new Array("page_1.jpg", "page_2.jpg");

var clientArray = new Array ("Barrick","Bayer","GoldFields","KFC", "ACE","ACHSM","AIM","AHRI","post","cipd","combank","dover","gartner","gmac","hdi","home","jhi","kmart","knauf","latrobe","legalgeneral","lexus","lion","nab","nie","northwest","royalyatch","rbs","socap","toyota","lego","optus","airport","ceo","rend","alcoa","rcsa","stgeorge","williams","zurich");

function clear_menu()
{
	$("#dropdown_1").stop().animate({	opacity: 0}, 250);
}

function select_menu(menu, flag)
{	
	if (flag==1)	{
		menu.style.backgroundImage='url(/images/template/menu_arrow.png)';
		menu.style.backgroundRepeat='no-repeat';
		menu.style.backgroundPosition='bottom';
		
		if (menu.childNodes[2].innerHTML!='')
			$("#dropdown_"+menu.getAttribute('id')).stop().show().animate({	opacity: 1}, 250);

	}	else	{
		menu.style.backgroundImage='none';
		$("#dropdown_"+menu.getAttribute('id')).stop().animate({	opacity: 0}, 250, function () {
			$("#dropdown_"+menu.getAttribute('id')).hide();
		});
	}			
}

function hide_menu(menu)
{
	$(menu).stop().animate({	opacity: 0}, 250).hide();
	//menu.style.display="none";
}

var currentPhoto = 0;
var secondPhoto = 1;

var currentOpacity = new Array();
var imageArray = new Array("page_banner_1.png");

var FADE_STEP = 2;
var FADE_INTERVAL = 40;
var pause = false;

function next()	{
	mInterval = setInterval("crossFade()",FADE_INTERVAL);
}

function init_client()
{
	/*
	
	
	var h = document.getElementById('page_title');
	if (returnDocument() == "auto-planners.html")		{
		h.style.backgroundImage="url(/images/template/h1.png)";
		h.style.paddingLeft="30px";
		h.style.backgroundRepeat="no-repeat";
		h.style.backgroundPosition="5px center";
	} else 	if (returnDocument() == "bottom_line.html")		{ 
		h.style.backgroundImage="url(/images/template/h2.png)";
		h.style.paddingLeft="30px";
		h.style.backgroundRepeat="no-repeat";
		h.style.backgroundPosition="5px center";
	} else 	if (returnDocument() == "full_disclosure.html")		{ 
		h.style.backgroundImage="url(/images/template/h3.png)";
		h.style.paddingLeft="30px";
		h.style.backgroundRepeat="no-repeat";
		h.style.backgroundPosition="5px center";
	} else 	if (returnDocument() == "lost.html")		{ 
		h.style.backgroundImage="url(/images/template/h4.png)";
		h.style.paddingLeft="30px";
		h.style.backgroundRepeat="no-repeat";
		h.style.backgroundPosition="5px center";
	}
	*/
	
	cycleClient();
	cSInterval = setInterval("cycleClient()",8000);
	
}

function init_banner() {
	
	currentOpacity[0]=99;
	mHTML="";
	
	for(i=1;i<imageArray.length;i++)
		currentOpacity[i]=0;
	
	for(i=0;i<imageArray.length;i++)
		mHTML += "<img id=\"photo\" name=\"photo\" class=\"mPhoto\" src=\"/images/template/" + imageArray[i]  +"\" />";
	
	//document.getElementById("site_banner").innerHTML = mHTML;
	//document.getElementById("site_small").innerHTML = siteMessages[currentMessage];

	//if(document.all) 
	//	document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=99)";
	// else 
	//	document.getElementsByName("photo")[currentPhoto].style.opacity = "0.99";

	//nextT = setTimeout("next()",12000);
	//mSInterval = setInterval("cycleMessage()",6000);
}

function cycleMessage() {
	currentMessage++;
	if (currentMessage>3)
		currentMessage=0;
	
	document.getElementById("site_small").innerHTML = siteMessages[currentMessage];
}

function cycleClient() 
{
	var currentClient = Math.floor(Math.random()*clientArray.length);
	var f = document.getElementById("site_endorsement");

	f.style.backgroundImage="url('http://www.steve-simpson.com/images/logos/"+clientArray[currentClient]+".jpg')";
	f.style.backgroundPosition="center 40%";
	f.style.backgroundRepeat ="no-repeat";
}

function crossFade() {
	if(pause)return;

	currentOpacity[currentPhoto]-=FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;

	if(document.all) {
		document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
	} else {
		document.getElementsByName("photo")[currentPhoto].style.opacity = currentOpacity[currentPhoto]/100;
		document.getElementsByName("photo")[secondPhoto].style.opacity =currentOpacity[secondPhoto]/100;
	}

	if(currentOpacity[secondPhoto]/100>=0.98) {
		currentPhoto = secondPhoto;
		secondPhoto++;
		if(secondPhoto == imageArray.length)secondPhoto=0;
		pause = true;
		xInterval = setTimeout("pause=false",12000);
	}
}

function overPic(index, flag)
{
	var optionArray = new Array("bomb", "stopclock", "microscope", "signpost");
	var option = document.getElementById('option_'+index);
	var option_over = document.getElementById('option_'+index+'_over');
	if (flag==1)
	{
		option.style.display='none';
		option_over.style.display='block';
	}
	else
	{
		option_over.style.display='none';
		option.style.display='block';
	}
}

function returnDocument() {
	var file_name = document.location.href;
	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	return file_name.substring(file_name.lastIndexOf("/")+1);
}

function select_one(flag)
{
	if (flag==1)
	{
		document.getElementById("td_one").style.color="#212222";
		document.getElementById("header_one").style.color="#212222";
		document.getElementById("hover_one").src="http://www.steve-simpson.com/images/template/folder_1.png";
	}
	else
	{
		document.getElementById("td_one").style.color="#FFF";
		document.getElementById("header_one").style.color="#FFF";
		document.getElementById("hover_one").src="http://www.steve-simpson.com/images/template/folder.png";
	}
	
}

function select_two(flag)
{
	if (flag==1)
	{
		document.getElementById("td_two").style.color="#212222";
		document.getElementById("header_two").style.color="#212222";
		document.getElementById("hover_two").src="http://www.steve-simpson.com/images/template/faces_1.png";
	}
	else
	{
		document.getElementById("td_two").style.color="#FFF";
		document.getElementById("header_two").style.color="#FFF";
		document.getElementById("hover_two").src="http://www.steve-simpson.com/images/template/faces.png";
	}
	
}

function formcheck(){
	
	if(document.getElementById('your_email').value == "") {
		alert("Please fill in your email address.");
		return false;
	}
	else {
		if(!echeck(document.getElementById('your_email').value))
			return false;
	}
	if(document.getElementById('your_name').value == "") {
		alert("Please fill in your name.");
		return false;
	}
	if(document.getElementById('email_1').value == "") {
		alert("Please fill in at least one friends email address.");
		return false;
	}
	else {
		if(!echeck(document.getElementById('email_1').value))
			return false;
	}
	if(document.getElementById('friend_1').value == "") {
		alert("Please fill in at least one friends name.");
		return false;
	}
	
	//test other email addresses
	if(document.getElementById('email_2').value != "") {
		if(!echeck(document.getElementById('email_2').value))
			return false;
	}
	if(document.getElementById('email_3').value != "") {
		if(!echeck(document.getElementById('email_3').value))
			return false;
	}
	if(document.getElementById('email_4').value != "") {
		if(!echeck(document.getElementById('email_4').value))
			return false;
	}
	if(document.getElementById('email_5').value != "") {
		if(!echeck(document.getElementById('email_5').value))
			return false;
	}

	return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

