// JavaScript Document
var lastLink;

function loadQuote(){
	var quotes = new Array();
	quotes[0] = "\"It was tremendous to see kids of all ages enjoying you. As you're well aware, high-quality, family-friendly entertainment isn't easy to find these days. That's why we felt especially blessed by you. The audiences were fascinated by your skill and spiritual lessons.\"";
	quotes[1] = "\"David's presentation was the best children's program this church has ever had.\"";
	quotes[2] = "\"Absolutely wonderful!\"";
	quotes[3] = "\"It was tremendous to see kids of all ages enjoying you. As you're well aware, high-quality, family-friendly entertainment isn't easy to find these days. That's why we felt especially blessed by you. The audiences were fascinated by your skill and spiritual lessons.\"";

	var people = new Array();
	people[0] = "Dr. James C. Dobson, Ph.D., Founder of Focus on the Family";
	people[1] = "Pastor Darrell Fraley, Overlake Christian Church - Redmond, WA, Largest Church in the state of Washington";
	people[2] = "Deborah Edwards, Kid's Crusade Coordinator for the Billy Graham Crusade - Cincinnati 2002";
	people[3] = "Dr. James C. Dobson, Ph.D., Founder of Focus on the Family";

	var number = Math.floor(Math.random() * quotes.length);
	document.getElementById('quote').innerHTML = '<em>' + quotes[number] + '</em><br /><br />' + people[number];
	
	setTimeout("loadQuote()", 10000);
}

function changePage(page){
	if (lastLink == null){ lastLink = document.getElementById('home'); }
	lastLink.className = "notselected";
	var contentFrame = document.getElementById('contentFrame');
	linkObj = document.getElementById(page);
	contentFrame.src = '/' + page + '.html';
	if (page != "home"){
		setTimeout('document.title = \'David Cain - Juggler for Jesus - \' + contentFrame.contentWindow.document.title', 500);
	}else{
		setTimeout('document.title = \'David Cain - Juggler for Jesus\'', 500);
	}
	linkObj.className = 'selected';
	lastLink = linkObj;
}

function setLastLink(page){
	if (top == self){
		top.location = 'index.html?page='+page;
	}else{
		lastLink = parent.document.getElementById(page);
		lastLink.className = "selected";
		
		if (page != "home"){
			parent.document.getElementById('home').className = "notselected";
		}
	}
}

function pageLoadLastLink(page){
	lastLink = document.getElementById(page);
	lastLink.className = "selected";
		
	if (page != "home"){
		document.getElementById('home').className = "notselected";
	}
	
	changePage(page);	
}

function resizeFrame(){	
	var contentFrame = parent.document.getElementById('contentFrame');
	
	if (document.body.offsetHeight > 500){	
		contentFrame.style.height = (contentFrame.contentWindow.document.body.offsetHeight + 20) + "px";
	}else{
		contentFrame.style.height = "500px";
	}
}

function doGallery(maxImg){
	galleryCell = document.getElementById('gallery');
	
	for (i = 1; i <= maxImg; i++){
		var image = document.createElement('img');
		image.setAttribute('hspace', 10);
		image.setAttribute('vspace', 10);
		image.src = 'img/gallery/'+i+'.jpg';
		image.onclick = function(){ window.open(this.src); }
		image.style.cursor = 'pointer';
		
		//if (!image.width){
			image.setAttribute("width", 150);	
			image.setAttribute("height", 200);
		//}else{
		//	var perc = 150 / image.width;
		//	image.setAttribute("width", image.width * perc);
		//	image.setAttribute("height", image.height * perc);
		//}
		
		galleryCell.appendChild(image);		
	}
}

function doGallery2(img, maxImg){
	if (img <= maxImg){
		left = document.getElementById('left');
		right = document.getElementById('right');
		gallery = document.getElementById('galleryPicture');
		progress = document.getElementById('progress');
		
		gallery.innerHTML = '<img src="img/gallery/'+img+'.jpg" />';
		if (img > 1){
			left.innerHTML = '<input type="button" onClick="Javascript:doGallery('+(img-1)+', '+maxImg+');" value="&laquo;">';
		}else{
			left.innerHTML = '';	
		}
		
		if (img < maxImg){
			right.innerHTML = '<input type="button" onClick="Javascript:doGallery('+(img+1)+', '+maxImg+');" value="&raquo;">';
		}else{
			right.innerHTML = '';
		}
		
		progress.innerHTML = img + ' of ' + maxImg + ' images';
		resizeFrame();
	}
}


function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	
	return vars;
}