﻿// PRELOAD ROLLOVER IMAGES
// -----------------------
if (document.images) {
	img1 = new Image();
	img1.src = "images/home/welcome_button.jpg";
	img2 = new Image();
	img2.src = "images/home/welcome_button-on.jpg";
	img3 = new Image();
	img3.src = "images/home/ethos_button-on.jpg";
	img4 = new Image();
	img4.src = "images/home/search_button-over.gif";
	img5 = new Image();
	img5.src = "images/home/ethos_button-on.jpg";
	img6 = new Image();
	img6.src = "images/news/top_nav_back-over.gif";
	img7 = new Image();
	img7.src = "images/news/top_nav_next-over.gif";
	img8 = new Image();
	img8.src = "images/news/bottom_nav_back-over.gif";
	img9 = new Image();
	img9.src = "images/search_page/search_button-over.gif";
	img9 = new Image();
	img9.src = "images/home/parents_button-over.gif";
}


// FADING PHOTOS
// -------------
function fading_photos(container_id, total_images, img_path) {
	var img_extension = ".jpg";
	var i = 1;
	
	// insert first image
	$('<img src="' + img_path + i + img_extension + '" class="pic' + i + '" />').appendTo(container_id).show();
	i++;
	
	// every 5 seconds - run the change_photo function
	setInterval(change_photo, 6000);

	function change_photo() {
		if(i > total_images) {
			i = 1;
			current_img = 1;
		}
		else current_img = i;
		
		if(current_img == 1) last_img = total_images;
		else last_img = (current_img - 1);
		
		// fade in the new image
		$('<img src="' + img_path + current_img + img_extension + '" class="pic' + current_img + '" />').appendTo(container_id).fadeIn(1500);
		// fade out + remove the existing image
		$(container_id + ' img.pic' + last_img).fadeOut(1500, function() {
			$(container_id + ' img.pic' + last_img).remove();
		});
		
		i++;
	}
}


// CHANGE SEARCH RESULTS PAGE
// --------------------------
function change_search_results(div_class) {
	
	// create array of <div> tags within #search_results	
	var mydivs = document.getElementById('search_results').getElementsByTagName('div');
	// foreach <div>
	for(var i = 0; i < mydivs.length; i++) {
		// if div_class provided and matches current <div> - make <div> visible
		if (div_class != null & mydivs[i].className == div_class) mydivs[i].style.display = 'block';
		else if (mydivs[i].className == 'nav') mydivs[i].style.display = 'block';
		else mydivs[i].style.display = 'none';		// else - hide it
	}
	
	window.scroll(0,0);
	
	return false;
}




function createWindow(page, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'width='+w+',height='+h+',top='+wint+',left='+winl+',scrollbars=no';
	newwindow = window.open(page,'name',winprops);
	return false;
}

function treeclick(a) {
    var curr_status = a.parentNode.className;
    
    // create array of <li> classes
	var mylis = document.getElementById('side_nav').getElementsByTagName('li');
	// hide all <li>s
	// for(var i = 0; i < mylis.length; i++) {
		// if(mylis[i].className = 'open') mylis[i].className = 'closed';
	// }
	
    if(curr_status == 'open') a.parentNode.className = 'closed';
    else a.parentNode.className = 'open';
    return false;
}