var container;
var items;
var itemList;
var curSlide = 0;
var slideInterval;

////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//generateMarkup()
	//
	//
	//
function generateMarkup() {
	if(!document.getElementById) return false;
	if(!document.getElementById('mission')) return false;
	
	var parentElem = document.getElementById('contentMain');
	var referenceElem = parentElem.getElementsByTagName('h2')[0];
	
	container = document.createElement('div');
	container.setAttribute('id', 'infoSwitcher');
	parentElem.insertBefore(container, referenceElem);
	
	itemList = document.createElement('ul');
	container.appendChild(itemList);
	
	items = [
				['Bay Hill Occhiali', 'occhiali', 'occhiali.php', generateOcchialiSlide],
				['Designer eyewear', 'eyewear', 'eyewear.php', generateEyewearSlide],
				['Dr. Sean P. Coughlin', 'doctor', 'staff.php', generateDoctorSlide],
				['Our Orlando office', 'tour', 'officeTour.php', generateTourSlide]
	];
	
	for(var i=0; i<items.length; i++) {
		var t = document.createElement('li');
		var a = document.createElement('a');
		a.setAttribute('id', 'item' + i);
		a.slideNum = i;
		a.displayText = items[i][0];
		a.targetDiv = items[i][1];
		a.hrefValue = items[i][2];
		a.func = items[i][3];
		a.setAttribute('href', a.hrefValue);
		a.onclick = released;
		var theText = document.createTextNode(a.displayText);
		a.appendChild(theText);
		t.appendChild(a);
		itemList.appendChild(t);
		
		//set first item active
		if(i==0){
			setActive('item0');
		}
	}
	slideInterval = setInterval(slideshow, 7000);
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//released()
	//
	//
	//
function released() {
	var curId = this.getAttribute('id');
	setActive(curId);
	this.func();
	curSlide = this.slideNum;
	if(slideInterval) {
		clearInterval(slideInterval);
	}
	return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//setActive()
	//
	//
	//
function setActive(id) {
	var curId = id;
	var itemLinks = itemList.getElementsByTagName('a');
	for(var i=0; i<itemLinks.length; i++) {
		if(itemLinks[i].getAttribute('id') == curId){
			itemLinks[i].className = 'here';
			itemLinks[i].onclick = function() { return false };
		}else{
			itemLinks[i].className = '';;
			itemLinks[i].onclick = released;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//slideshow()
	//
	//
	//
function slideshow() {
	if(curSlide < items.length - 1){
		curSlide++;
	}else{
		curSlide = 0;
	}
	var func = items[curSlide][3];
	func();
	setActive('item'+curSlide);
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//generateOcchialiSlide()
	//
	//
	//
function generateOcchialiSlide(){
	if(!document.getElementById('mission')) return false;
	if(document.getElementById('occhiali')) return false;
	var occhialiSlide = document.createElement('div');
	occhialiSlide.setAttribute('id', 'occhiali');
	occhialiSlide.onclick = function() {
		window.location = 'occhiali.php';
	}
	
	var occhialiHeading = document.createElement('h2');
	occhialiHeading.appendChild(document.createTextNode('Bay Hill Occhiali'));
	occhialiSlide.appendChild(occhialiHeading);
	
	var occhialiPara = document.createElement('p');
	occhialiPara.appendChild(document.createTextNode('Introducing our new facility near Sandlake and Della inside the beautiful new Delagio Town Center.'));
	occhialiSlide.appendChild(occhialiPara);
	
	var occhialiLink = document.createElement('a');
	occhialiLink.setAttribute('href', 'occhiali.php');
	occhialiLink.appendChild(document.createTextNode('see new facility'));
	occhialiSlide.appendChild(occhialiLink);
	
	container.appendChild(occhialiSlide);
	occhialiSlide.style.display = 'none';
	fadeUp(occhialiSlide, 0.3, 'occhiali');
}
////////////////////////////////////////////////////////////////////////////////////////////////	//
	//
	//
	//generateDoctorSlide()
	//
	//
	//
function generateDoctorSlide(){
	if(!document.getElementById('mission')) return false;
	if(document.getElementById('doctor')) return false;
	var docSlide = document.createElement('div');
	docSlide.setAttribute('id', 'doctor');
	docSlide.onclick = function() {
		window.location = 'staff.php';
	}
	
	var docHeading = document.createElement('h2');
	docHeading.appendChild(document.createTextNode('Dr. Sean P. Coughlin'));
	docSlide.appendChild(docHeading);
	
	var docPara = document.createElement('p');
	docPara.appendChild(document.createTextNode('With nearly 20 years of experience in the field of Optometry, Dr. Coughlin has a vast understanding of the needs of his patients.'));
	docSlide.appendChild(docPara);
	
	var docLink = document.createElement('a');
	docLink.setAttribute('href', 'staff.php');
	docLink.appendChild(document.createTextNode('read more'));
	docSlide.appendChild(docLink);
	
	container.appendChild(docSlide);
	docSlide.style.display = 'none';
	fadeUp(docSlide, 0.3, 'doctor');
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//generateEyewearSlide()
	//
	//
	//
function generateEyewearSlide(){
	var eyeSlide = document.createElement('div');
	eyeSlide.setAttribute('id', 'eyewear');
	eyeSlide.onclick = function() {
		window.location = 'eyewear.php';
	}
	
	var eyeHeading = document.createElement('h2');
	eyeHeading.appendChild(document.createTextNode('Designer eyewear'));
	eyeHeading.appendChild(document.createElement('br'));
	var eyeSpan = document.createElement('span');
	eyeSpan.appendChild(document.createTextNode('and sunglasses'));
	eyeHeading.appendChild(eyeSpan);
	eyeSlide.appendChild(eyeHeading);
	
	var eyePara = document.createElement('p');
	eyePara.appendChild(document.createTextNode('Names like Cartier, Lindberg, Chrome Hearts, LaFont, Face A Face, Fendi, Coach, D & G, Prada, Gold & Wood, Armani and more.'));
	eyeSlide.appendChild(eyePara);
	
	var eyeLink = document.createElement('a');
	eyeLink.setAttribute('href', 'eyewear.php');
	eyeLink.appendChild(document.createTextNode('read more'));
	eyeSlide.appendChild(eyeLink);
	
	container.appendChild(eyeSlide);
	eyeSlide.style.display = 'none';
	fadeUp(eyeSlide, 0.3, 'eyewear');
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//generateTechSlide()
	//
	//
	//
function generateTechSlide(){
	var techSlide = document.createElement('div');
	techSlide.setAttribute('id', 'tech');
	techSlide.onclick = function() {
		window.location = 'technologies.php';
	}
	
	var techHeading = document.createElement('h2');
	techHeading.appendChild(document.createTextNode('Optomap Retinal Imaging'));
	techSlide.appendChild(techHeading);
	
	var techPara = document.createElement('p');
	techPara.appendChild(document.createTextNode('Learn about this revolutionary technology that allows us access to areas of the retina that were previously beyond our reach.'));
	techSlide.appendChild(techPara);
	
	var techLink = document.createElement('a');
	techLink.setAttribute('href', 'technolgies.php');
	techLink.appendChild(document.createTextNode('read more'));
	techSlide.appendChild(techLink);
	
	container.appendChild(techSlide);
	techSlide.style.display = 'none';
	fadeUp(techSlide, 0.3, 'tech');
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//generateTourSlide()
	//
	//
	//
function generateTourSlide(){
	var tourSlide = document.createElement('div');
	tourSlide.setAttribute('id', 'tour');
	tourSlide.onclick = function() {
		window.location = 'officeTour.php';
	}
	
	var tourHeading = document.createElement('h2');
	tourHeading.appendChild(document.createTextNode('Our Orlando Office'));
	tourSlide.appendChild(tourHeading);
	
	var tourPara = document.createElement('p');
	tourPara.appendChild(document.createTextNode('Our modern office located just outside of downtown Orlando, offers patients a comfortable, relaxing experience.'));
	tourSlide.appendChild(tourPara);
	
	var tourLink = document.createElement('a');
	tourLink.setAttribute('href', 'officeTour.php');
	tourLink.appendChild(document.createTextNode('see more'));
	tourSlide.appendChild(tourLink);
	
	container.appendChild(tourSlide);
	tourSlide.style.display = 'none';
	fadeUp(tourSlide, 0.3, 'tour');
}
function clearChildren(divId){
	var curSlide = document.getElementById(divId);
	var siblings = container.getElementsByTagName('div');
	for(var i=0; i<siblings.length; i++) {
		if(siblings[i] != curSlide) {
			container.removeChild(siblings[i]);
		}
	}
}
function fadeUp(elem, time, divId){
	new Effect.Appear(elem, {duration: time, queue: 'end', afterFinish: function() {clearChildren(divId)}});
}
addLoadEvent(function(){
	generateMarkup();
	generateOcchialiSlide();
});