// JavaScript Document

//Used when need to call script only after page has loaded (innerHTML)
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
 			func();
		}
	}
}

//tab change
function tab_hv(tab,tabLink){
var tabLink = document.getElementById(tabLink);
tab.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/tab_right_hv.jpg) no-repeat right top';
tabLink.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/tab_left_corner_hv.jpg) no-repeat left top';
}

function tab_no_hv(tab,tabLink){
var tabLink = document.getElementById(tabLink);
tab.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/tab_right.jpg) no-repeat right top';
tabLink.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/tab_left_corner.jpg) no-repeat left top';
}


//news area
function news(header, section){
	var section=document.getElementById(section);
	if (section.style.display == 'none'){
		//open the area
		header.style.color= '#362821';
		header.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/news_open.jpg) no-repeat top right';
		section.style.display ='';
	} else {
		//close the area
		header.style.color='#7E7C6B';
		header.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/news_closed.jpg) no-repeat top right';
		section.style.display ='none';
	}
}

function news_over(header, section){

	var section=document.getElementById(section);
	header.style.cursor="pointer";
	if (section.style.display == 'none'){
		if (header.style.color='#7E7C6B'){
			header.style.color= '#362821';
		}
	}
}

function news_out(header, section){
	var section=document.getElementById(section);
	if (section.style.display == 'none'){
		if (header.style.color='#362821'){
			header.style.color='#7E7C6B';
		}
	}
}

//Specialty area 

//more hover
function more(){
	var element = document.getElementById("more");
	element.style.color = '#66717C';
	element.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/more.jpg) no-repeat right 0';
}

function more_hv(){
	var element = document.getElementById("more");
	element.style.color = '#3E4349';
	element.style.background = 'url(http://www.westernbaptist.com/staticfiles/westernbaptist/files/admin/images/more_hv.jpg) no-repeat right 0';
}

//content from VCM will be converted to Javascript in display specialty sections.



var doRandom = 1; //1 yes
var firstPass = 1;
var start_num;

function more_specialty(){

	if (firstPass == 1){
		if (doRandom == 1 ) {
			randomnumber=Math.floor(Math.random()*sa_array.length);
			start_num = randomnumber-1;
		} else {
			start_num = -1;
		}
		firstPass = 0;
	}

	for (i=1; i <=3; i++){
		array_num = start_num+i;
		if (array_num >= sa_array.length){
			array_num = array_num - sa_array.length;
		}

		//next_specailty(array_num, i);
		sa_image = document.getElementById('image'+ i);
		sa_title = document.getElementById('title'+ i);
		sa_summary = document.getElementById('summary'+ i);
		sa_link = document.getElementById('link'+ i);

		sa_image.style.backgroundImage  = 'url('+sa_array[array_num][0]+')';
		sa_title.innerHTML = sa_array[array_num][1]+'<span class="header_accent"></span>';
		sa_summary.innerHTML = sa_array[array_num][2];
		sa_link.href = sa_array[array_num][3];

	}

	if (start_num>=sa_array.length-1){
		start_num = 0;
	} else {
		start_num = start_num + 1;
	}
}



//Random image on main page
//content from VCM will be converted to Javascript in display rotating images.
//www.cryer.co.uk © 2004 and www.brainerror.net ver 1.3 © June 7,2004
//were reference for the following Javascript slide show code
var rotateMain = 0;  //1 yes
var firstImage = 0;  // not used unless rotateMain = 0;
function changeOpac(opacity, id)
{
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}

function generate(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

function blendimage(divid, imageid, imagefile)
{
	var speed = Math.round(100 / 10);
	var timer = 0;
	var div=document.getElementById(divid);
	var image=document.getElementById(imageid);
	
	//set the current image as background
	div.style.backgroundImage = "url(" + image.src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	image.src = imagefile;
	
	//fade in image
	for(i = 0; i <= 100; i++)
	{
	setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
	timer++;
	}
}

function rotateImage(divid,imageid) {
	if (rotateMain == 1) {
		image_index = generate(0, image_list.length-1);
		nextImage = image_list[image_index];	
	} else {
		image_index = firstImage;
		nextImage = image_list[image_index];
		firstImage += 1;
		if (firstImage >= image_list.length){
			firstImage =0;
		}

	}
	
	changeOpac(0, imageid);
	blendimage(divid,imageid,nextImage);

	setTimeout("rotateImage('"+divid+"','"+imageid+"')",5*1000);
}

//JS for increase/decrease font size

var min=8;
var max=18;
function increaseFontSize() {
   var b = document.getElementById('bodyText');
      var allContainedElements = b.getElementsByTagName("*");
      for (i=0;i<allContainedElements.length;i++) {
         if (allContainedElements[i].nodeName != 'H1')  {
		 if(allContainedElements[i].style.fontSize) {
		    var s = parseInt(allContainedElements[i].style.fontSize.replace("px",""));
		 } else {
		    var s = 14;
		 }
		 if(s!=max) {
		    s += 1;
		 }
		 allContainedElements[i].style.fontSize = s+"px"
         }
   }
}
function decreaseFontSize() {
   var b = document.getElementById('bodyText');
   var allContainedElements = b.getElementsByTagName("*");
   for (i=0;i<allContainedElements.length;i++) {
      if (allContainedElements[i].nodeName != 'H1')  {
	      if(allContainedElements[i].style.fontSize) {
		 var s = parseInt(allContainedElements[i].style.fontSize.replace("px",""));
	      } else {
		 var s = 12;
	      }
	      if(s!=min) {
		 s -= 1;
	      }
	      allContainedElements[i].style.fontSize = s+"px"
      }
   }
   
}