function openLightBoxFromFlash(url)
{
	if(myLightWindow)
	{
		var Width=new Array();
		var Height=new Array();
		
		Width["/readwritestories.html"]=600;
		Height["/readwritestories.html"]=225;
		
		Width["/topicsread.html"]=900;
		Height["/topicsread.html"]=425;
		
		
		myLightWindow.activateWindow({href:url,title:'',author:'',caption:'',type:'page',width:Width[url],height:Height[url]})
		
	}
}


var currentGalleryInt=0;
var maxGalleryInt=10;
function nextImage()
{
	currentGalleryInt++;
	if(currentGalleryInt==maxGalleryInt)
	{
		// start over if gets too far;
		currentGalleryInt=0;
	}
	LoadGallery();
}

function prevImage()
{
	currentGalleryInt--;
	if(currentGalleryInt<0)
	{
		// go to end if goes too far
		currentGalleryInt=maxGalleryInt-1;
	}
	LoadGallery();
}

function LoadGallery()
{
	document.getElementById("GalleryItem_"+currentGalleryInt).click();
	
	if(currentGalleryInt==0)
	{
		$('prevImageAnchor').style.visibility="hidden";
	}
	else
	{
		$('prevImageAnchor').style.visibility="visible";
	}
	
	if(currentGalleryInt==maxGalleryInt-1)
	{
		$('nextImageAnchor').style.visibility="hidden";
	}
	else
	{
		$('nextImageAnchor').style.visibility="visible";
	}
}

// add the .click() method to html elements
try{
	HTMLElement.prototype.click = function()
	{
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}catch(e){;}

function change (logo) 
{
	document.getElementById("picture").src = logo;
}
function changeImgData(local, desc)
{
	if(document.getElementById('main_img'))
	{
		document.getElementById('main_img').src = local;
		document.getElementById('main_desc').innerHTML = desc;
	}
}

function changeVideoData(local)
{
	var div=document.getElementById('swf_div');
	if(div!=null)
	{		
		div.getElementsByTagName("iframe")[0].src="/swf.php?src="+local;
	}
	
}


function init() 
{
	showDiv(0)
}
function showFAQ( faq_id ) 
{
  var divs=document.getElementById("faqAnswers").getElementsByTagName("div");
  for(var x=0;x<divs.length;x++)
  {
     divs[x].style.display=((divs[x].id=='faq'+faq_id)?'block':'none');
  }
}

function getResources(topic)
{
	if(xmlhttp_loadTopic=getAjaxObj())
	{		
		xmlhttp_loadTopic.open("GET","/ajax/getResources.php?topic="+topic,true);
		xmlhttp_loadTopic.send(null);
	}
	else
	{
			alert("Your browser does not support AJAX.");
	}
}

function getAmbassadors(topic)
{
	if(topic==null)
		topic=0;
	if(xmlhttp_loadTopic=getAjaxObj())
	{		
		xmlhttp_loadTopic.open("GET","/ajax/getAmbassadors.php?topic="+topic,true);
		xmlhttp_loadTopic.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function getTopicPage(topic)
{
	if(xmlhttp_loadTopic=getAjaxObj())
	{		
		xmlhttp_loadTopic.open("GET","/ajax/getTopicPage.php?page="+topic,true);
		xmlhttp_loadTopic.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function submitContact(submitting)
{
	if(xmlhttp_submitContact=getAjaxObj())
	{		
		var params="";
		if(submitting==1)
		{
			var frm=document.getElementById("contactFrm");
			params+="submitting=1";			
			params+="&fname="+frm.fname.value;
			params+="&lname="+frm.lname.value;
			params+="&email="+frm.email.value;
			params+="&phone="+frm.phone1.value+frm.phone2.value+frm.phone3.value;
		}		
		
		xmlhttp_submitContact.open("POST","/ajax/saveContact.php",true);
		xmlhttp_submitContact.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_submitContact.setRequestHeader("Content-length", params.length);
		xmlhttp_submitContact.setRequestHeader("Connection", "close");
		xmlhttp_submitContact.send(params);		
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}

function getAjaxObj(func)
{
	var xmlhttp=false;
	if(window.XMLHttpRequest)
	{
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			// 4 = "loaded"
			if (xmlhttp.status==200)
			{
				// 200 = OK					
				if(xmlhttp.responseText!="")
				{	
					if(func==null)
						eval(xmlhttp.responseText)
					else
						func(xmlhttp.responseText)
				}
			}
			else
			{
				alert("Problem retrieving XML data");
			}
		}
	};
	return xmlhttp;
}
