// Javascript for use with Edna A. Rice site
// Written by Jeffrey Powell (jeff {with} geebodesign {dot} com)
// Some code copyright of its respective original authors (like the Adobe stuff)

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function preload_base() {
	   MM_preloadImages('images/menu_center.jpg',
						'images/menu_contact.jpg',
						'images/menu_contact_on.jpg',
						'images/menu_gallery.jpg',
						'images/menu_gallery_on.jpg',
						'images/menu_help.jpg',
						'images/menu_help_on.jpg',
						'images/menu_orgs.jpg',
						'images/menu_orgs_on.jpg',
						'images/menu_record.jpg',
						'images/menu_record_on.jpg',
						'images/menu_serve.jpg',
						'images/menu_serve_on.jpg',
						'images/menu_what.jpg',
						'images/menu_what_on.jpg',
						'images/menu_who.jpg',
						'images/menu_who_on.jpg');
}

function open_submenu(id) {
			
	//If a submenu exists, open it
	if (document.getElementById(id + "_submenu"))
	{
		if (document.getElementById(id + "_submenu").style.display == 'none')
		{		
			//Effect.Queues.get(id).invoke('cancel');
			new Effect.SlideDown(id + "_submenu", { 
								 queue: { scope: id, limit: 1 },
								 duration: 0.5 });
		}
	}
	
	//Close all other submenus
	for (var i = 0; i < submenus.length; i++) {
		if (submenus[i] == id) continue;
		
		if (document.getElementById(submenus[i] + "_submenu").style.display == 'none') continue;
		
		close_submenu(submenus[i]);
	}
	
	return false;
}

function close_submenu(id) {
		
	//Effect.Queues.get('menu').invoke('cancel');
	new Effect.SlideUp(id + "_submenu", { 
									 queue: { scope: id, limit: 1 },
									 duration: 0.5 });
	return false;
}


function show_section(section_name) {
	//active_section represents the currently visible section
	// _links are the links themselves, _submenu is for any submenu, _right is the contact stuff
		
	// This whole thing only makes sense if we're switching sections
	if (active_section != section_name)
	{
		// Activate the link and deactivate the previous link
		if (document.getElementById(active_section + "_link"))
			document.getElementById(active_section + "_link").setAttribute("class", "");
			
		if (document.getElementById(section_name + "_link"))
			document.getElementById(section_name + "_link").setAttribute("class", "active");	
		
		// Activate the contact information display if necessary
		if (document.getElementById(section_name + "_right"))
		{
			if (document.getElementById('main_right').style.display == 'none')
			{
				document.getElementById(section_name + "_right").style.display = 'block';
				document.getElementById(section_name + "_photo").style.display = 'block';
				new Effect.Appear('main_right', { duration: 1.00 });
			}
			else
			{
				new Effect.Fade(active_section + "_right", {duration: 0.5, afterFinish: function(){
					new Effect.Appear(section_name + "_right", { duration: 0.5 });
				}});
				
				new Effect.Fade(active_section + "_photo", {duration: 0.5, afterFinish: function(){
					new Effect.Appear(section_name + "_photo", { duration: 0.5 });
				}});
			}
		}
		else
		{
			if (document.getElementById('main_right').style.display == 'none')
			{

			}
			else
			{
				new Effect.Fade(active_section + "_photo", { duration: 0.75 });
				new Effect.Fade(active_section + "_right", {duration: 0.5 });
				new Effect.Fade("main_right", { duration: 1.0 });
				
				//new Effect.Fade(active_section + "_right", {duration: 0.5, afterFinish: function() {
				//	new Effect.Fade("main_right", { duration: 1.00, afterFinish: function() {
				//	new Effect.Fade(active_section + "_photo", { duration: 1.00 });
				//}});
			}
		}
			
		new Effect.Opacity(section_name, { to: 0.0, duration: 0.0, afterFinish: function(){
			document.getElementById(section_name).style.display = 'block';
		}});
			
		new Effect.Fade(active_section, { from: 1.0, to: 0.0, duration: 0.75, afterFinish: function(){
			new Effect.Opacity(section_name, { from: 0.0, to: 1.0, duration: 0.75, afterFinish: function(){
				// If the new section is large enough, make the scrollbar appear, otherwise hide it
				if (document.getElementById(section_name).scrollHeight > document.getElementById(section_name).clientHeight)
				{
					new Effect.Appear('scroller', { duration: 0.75 });
				}
				else
				{
					new Effect.Fade('scroller', { duration: 0.75 });
				}	
			}});
		}});
		
		// Set the currently active section
		active_section = section_name;
	}
	
	return false;
}

function setGallery(img) {

	if (document.getElementById('gallery_image').src != 'images/gallery/' + img + '.jpg')
	{
		new Effect.Opacity('gallery_image', { to: 0.0, duration: 0.75, afterFinish: function(){
			document.getElementById('gallery_image').src = 'images/gallery/' + img + '.jpg';
			new Effect.Opacity('gallery_image', { from: 0.0, to: 1.0, duration: 0.75 });
		}});
	}
}

function rotateSlideshow() {
	//Update the array index
	slideshow_index = ((slideshow_index + 1) % slideshow_images.length);
	
	//Update the invisibles
	document.getElementById(slideshow_inactive).innerHTML = slideshow_images[slideshow_index];
	
	Effect.Fade(slideshow_active, { duration: 1.5, from: 1.5, to: 0.0});
	Effect.Appear(slideshow_inactive, { duration: 1.5, from: 0.0, to: 1.5});
	
	var tmpInactive = slideshow_inactive;
	slideshow_inactive = slideshow_active;
	slideshow_active = tmpInactive;
}

function startSlideshow()
{
	setInterval('rotateSlideshow()', 7000);
}


// Smooth Scrolling
scrollStep=1
timerDown=""
timerUp=""

function scrollTop(){
  document.getElementById(active_section).scrollTop=0;
}

function scrollBottom(){
  document.getElementById(active_section).scrollTop=document.getElementById(active_section).scrollHeight;
}

function scrollDivDown(){
  clearTimeout(timerUp) 
  document.getElementById(active_section).scrollTop+=scrollStep;
  timerUp=setTimeout("scrollDivDown()",10);
}

function scrollDivUp(){
  clearTimeout(timerDown)
  document.getElementById(active_section).scrollTop-=scrollStep;
  timerDown=setTimeout("scrollDivUp()",10);
}

function stopScrolling(){
  clearTimeout(timerUp); 
  clearTimeout(timerDown);
}
