// JavaScript Document
var siteimagefile = '/staticfiles/baptistregional/files/admin/images';

//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();
		}
	}
}

//hide throbber
function hideThrobber(){
document.getElementById('throbber').style.display='none';
document.getElementById('video').style.display='';
}

//tab change
function tab_hv(tab,tabLink){
var tabLink = document.getElementById(tabLink);
tab.style.background = 'url('+ siteimagefile +'/tab_right_hv.jpg) no-repeat right top';
tabLink.style.background = 'url('+ siteimagefile +'/tab_left_corner_hv.jpg) no-repeat left top';
}

function tab_no_hv(tab,tabLink){
var tabLink = document.getElementById(tabLink);
tab.style.background = 'url('+ siteimagefile +'/tab_right.jpg) no-repeat right top';
tabLink.style.background = 'url('+ siteimagefile +'/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('+ siteimagefile +'/news_open.jpg) no-repeat top right';
		section.style.display ='';
	} else {
		//close the area
		header.style.color='#7E7C6B';
		header.style.background = 'url('+ siteimagefile +'/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('+ siteimagefile +'/more.jpg) no-repeat right 0';
}

function more_hv(){
	var element = document.getElementById("more");
	element.style.color = '#3E4349';
	element.style.background = 'url('+ siteimagefile +'/more_hv.jpg) no-repeat right 0';
}

//Specitalty area scroll
var doRandom = 1; //1 yes
var multiMore = 0; //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 = '<a href="'+sa_array[array_num][3]+'">'+sa_array[array_num][1]+'</a><span class="header_accent"></span>';
		sa_summary.innerHTML = sa_array[array_num][2];
		sa_link.href = sa_array[array_num][3];

	}

	if (multiMore == 1) {
		for (i=1; i <=3; i++){
			if (start_num>=sa_array.length-1){
				start_num = 0;
			} else {
				start_num = start_num + 1;
			}
		}
	} else {
		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 randomFirst = 0;  //1 yes
var firstImage = 0;  // not used unless rotateMain = 0;
var loadimage = 0;  //0 creates a delay for the first image rotation
var timeout;
var pause = 0; //1 paused

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++){
		timeout = setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function rotateImage(divid,imageid) {
	var url;
	if (randomFirst == 1) {
		image_index = generate(0, listSize-1);
		nextImage = image_list[image_index][0];	
		url = image_list[image_index][1];
	} else {
		image_index = firstImage;
		nextImage = image_list[image_index][0];
		firstImage += 1;
		if (firstImage >= image_list.length){
			firstImage =0;
		}
		url = image_list[image_index][1];
	}
	if (url == "null"){
	    url = "/";	
	}
	document.getElementById('rLink').href =	url;
	changeOpac(0, imageid);
	blendimage(divid,imageid,nextImage);

	if (loadimage == 0) {
		timeout = setTimeout("rotateImage('"+divid+"','"+imageid+"')",15*1000);
	} else {
		timeout = setTimeout("rotateImage('"+divid+"','"+imageid+"')",5*1000);
	}
	loadimage++;
}

function stopRotate(){
	clearTimeout(timeout);
}

function startRotate(){
	rotateImage("rDiv","rImage");
}

function pausePlay(){	
	if (pause == 0){
		stopRotate();
		pause = 1;
	} else {
		startRotate();
		pause = 0;
	}
}

//JS for increase/decrease font size

var min=5;
var max=20;
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].currentStyle) {
		   fs = allContainedElements[i].currentStyle.fontSize;
              } else if (window.getComputedStyle) {
                    fs = document.defaultView.getComputedStyle(allContainedElements[i],
'').getPropertyValue("font-size");   
              }
		else {
			fs = allContainedElements[i].style.fontSize;
              }

		 if(fs.match("px")) {
                 var s = parseInt(fs.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].currentStyle) {
		   fs = allContainedElements[i].currentStyle.fontSize;
              } else if (window.getComputedStyle) {
                    fs = document.defaultView.getComputedStyle(allContainedElements[i],
'').getPropertyValue("font-size");   
              }
		else {
			fs = allContainedElements[i].style.fontSize;
              }

		 if(fs.match("px")) {
                 var s = parseInt(fs.replace("px",""));
		 } else {
		    var s = 12;
		 }
               
		 if(s!=min) {
		    s -= 1;
		 }
		 allContainedElements[i].style.fontSize = s+"px"
         }
   }
   
}

//generates tool tip that will display in a hidden area.
function toolTip(element,top,left,text) {
	el = document.getElementById(element)
	el.innerHTML=text;
	el.style.display="block";
	el.style.top  = top+"px";
	el.style.left = left+"px";
}
function hideMe(element) {
  document.getElementById(element).style.display="none";
}