function isNull(what) {
	return what == null;
}

function Slide(img,tabText,detailText,link) {

	this.siteUrl = "/";
	this.link = null;

	this.img = img;
	this.tabText = tabText;
	this.detailText = detailText;
	if (!isNull(link)) {
		this.link = this.siteUrl + link;
	}

}

var s_slides = new Array();

//s_slides.push(new Slide("helpforhaiti2.jpg","Help For Haiti","<p>Thanks to the efforts of 300 church and community volunteers, over 75,000 meals were packaged on May 1st & 2nd at Crossroads to be sent to Haiti. </p><p>Our goal was to raise $6,000 for meals but through your generosity, we were able to raise more than $12,000.</p><a href='/meals-for-haiti/' class='button'>Click here for more details. &raquo;</a>",null));
s_slides.push(new Slide("sermon-godwetrust.jpg","Current Sermon Series","If money really could talk, what would yours say? Good-bye?<br /><br />No matter how much debt you have, no matter how many bills you have to pay, no matter how much - or how little - money you make, you can achieve financial freedom. For 4 weeks beginning Sept 12, we'll learn how to take practical steps, spend smarter, make personalized goals and learn why, when it comes to money, IN God We <strong><em>definitely</em></strong> Trust.",null));
s_slides.push(new Slide("kid_junction.jpg","Kids","While the adults worship, children have an exciting worship and learning experience of their own. KID JUNCTION (ages 3 years- K) and K'Motion (1st-5th grade) activities are offered in safe and fun learning environments.","children"));
s_slides.push(new Slide("crossroads_youth.jpg","Crossroads Youth","<p>If you're in 6th through 12th grade, join our group every Wednesday night as we examine issues our youth encounter in their daily lives. </p><br /><a href='/youth/' class='button'>Click here for more details. &raquo;</a>",null));
s_slides.push(new Slide("weekly_groups.jpg","Weekly Community Group Questions","Crossroads Church offers Sermon Based Community Groups (small groups).  Each week groups are provided questions that correspond to the message of the week.  Please click on the following link to download this week's Community Group Questions.","communitygroups"));
s_slides.push(new Slide("ultimate_journey.jpg","The Ultimate Journey","<em>The Ultimate Journey</em> focuses on the biblical model of bringing about real change by renewing our minds, or in other words, by changing our thinking patterns.","groups"));
//s_slides.push(new Slide("sports_camp02.jpg","Sports Camp","FREE Sports Camp ages K-5th grade. August 9th-12th. 6:30-8:30PM. <br /><br /><a href='/downloads/Sports_Camp_Registration_2010.pdf' class='button'>Click here for online registration form</a>","events"));
//s_slides.push(new Slide("sermon-godwetrust.jpg","Upcoming Sermon Series","If money really could talk, what would yours say? Good-bye?<br /><br />No matter how much debt you have, no matter how many bills you have to pay, no matter how much - or how little - money you make, you can achieve financial freedom. For 4 weeks beginning Sept 12, we'll learn how to take practical steps, spend smarter, make personalized goals and learn why, when it comes to money, IN God We <strong><em>definitely</em></strong> Trust.",null));
s_slides.push(new Slide("","Labor Day Schedule","<strong>Only one service on <br />Labor Day weekend (9:00AM)</strong>",null));



var s_current_slide = 0;
var s_int = 10000;

function slides_draw() {
	var slide_holder = document.getElementById("slide_holder");
	var tab_holder = document.getElementById("tab_holder");
	var text_holder = document.getElementById("text_holder");
	for (i = 0; i < s_slides.length; i++) {
		var tab = document.createElement("div");
		tab.className = "tab";
		tab.id = tab.className + i.toString();
		if (tab.addEventListener) {
			tab.addEventListener("click",slide_clicked,false);
		} else if (tab.attachEvent) {
			tab.attachEvent('onclick',slide_clicked);
		}
		tab.appendChild(document.createTextNode(s_slides[i].tabText));
		tab_holder.appendChild(tab);
		var tabs_height = parseInt(tab_holder.clientHeight,10);
		var slide_height = parseInt(slide_holder.clientHeight,10);
		if (tabs_height > slide_height) {
			slide_holder.style.height = tabs_height.toString() + "px";			

			text_holder.style.height = (tabs_height - 16).toString() + "px";
		}
	}
	show_slide();
}

function slide_clicked(e) {
	if (e.target) {
		var clicked = e.target.id;
	} else if (e.srcElement) {
		var clicked = e.srcElement.id;
	}
	var p = /\d/i;
	var n = parseInt(clicked.match(p),10);
	s_current_slide = n;
	show_slide();
	--s_current_slide;
	//alert('clear interval!');
	clearInterval(s_i); // stop the auto-rotate if they click something
}

function show_slide() {
	for (i = 0; i < s_slides.length; i++) {
		var tid = "tab" + i.toString();
		document.getElementById(tid).style.backgroundColor = "#f3ddcc";
	}
	
	var slide_holder = document.getElementById("slide_holder");
	if (s_slides[s_current_slide].img != null)
	{
		slide_holder.style.backgroundImage = "url(/images/" + s_slides[s_current_slide].img + ")";
	}
	else
	{
		slide_holder.style.backgroundImage = 'none';
	}
	var tid = "tab" + s_current_slide.toString();
	document.getElementById(tid).style.backgroundColor = "#f7e7db";

	var text = document.getElementById("text_holder");
	text.innerHTML = s_slides[s_current_slide].detailText;
	if (!isNull(s_slides[s_current_slide].link)) {
		text.appendChild(document.createElement("br"));
		text.appendChild(document.createElement("br"));
		var a = document.createElement("a");
		a.setAttribute("href",s_slides[s_current_slide].link);
		a.appendChild(document.createTextNode("Click to find out more..."));
		text.appendChild(a);
	}
}

function next_slide() {
	++s_current_slide;
	if (s_current_slide >= s_slides.length) {
		s_current_slide = 0;
	}
	show_slide();
}

function cancelRotate()
{
	// Stop rotating already!
	clearInterval(s_i);	
}
