var pageShowing = 'home';
var isAnimating = false;

function setLocationCookie(location) {
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() + 1440000);
	document.cookie = "current_page=" +
                  location + "; expires=" + cookie_date.toGMTString() + "; path=/";
                  

}

function commentBoxFocus() {
	if ($('welcome_comment_box').value== 'Ready to talk? Just click right here and start typing...') {
		$('welcome_comment_box').value = '';
	}
}

function commentBoxBlur() {
	if ($('welcome_comment_box').value== '') {
		$('welcome_comment_box').value = 'Ready to talk? Just click right here and start typing...';
	}
}

function portfolioSelect(idx) {
	switch (idx) {
		case 1:
			$('port_link_image_1').src = 'images/portDotOn.png';
			$('port_link_image_2').src = 'images/portDotOff.png';
			$('port_link_image_3').src = 'images/portDotOff.png';
			$('port_link_image_4').src = 'images/portDotOff.png';
			$('port_link_image_5').src = 'images/portDotOff.png';
			break;
		case 2:
			$('port_link_image_1').src = 'images/portDotOff.png';
			$('port_link_image_2').src = 'images/portDotOn.png';
			$('port_link_image_3').src = 'images/portDotOff.png';
			$('port_link_image_4').src = 'images/portDotOff.png';
			$('port_link_image_5').src = 'images/portDotOff.png';
			break;
		case 3:
			$('port_link_image_1').src = 'images/portDotOff.png';
			$('port_link_image_2').src = 'images/portDotOff.png';
			$('port_link_image_3').src = 'images/portDotOn.png';
			$('port_link_image_4').src = 'images/portDotOff.png';
			$('port_link_image_5').src = 'images/portDotOff.png';
			break;
		case 4:
			$('port_link_image_1').src = 'images/portDotOff.png';
			$('port_link_image_2').src = 'images/portDotOff.png';
			$('port_link_image_3').src = 'images/portDotOff.png';
			$('port_link_image_4').src = 'images/portDotOn.png';
			$('port_link_image_5').src = 'images/portDotOff.png';
			break;
		case 5:
			$('port_link_image_1').src = 'images/portDotOff.png';
			$('port_link_image_2').src = 'images/portDotOff.png';
			$('port_link_image_3').src = 'images/portDotOff.png';
			$('port_link_image_4').src = 'images/portDotOff.png';
			$('port_link_image_5').src = 'images/portDotOn.png';
			break;
	}
	
	var calcX = -1 * (idx-1) * 975;
	$('port_select_link_' + idx).blur();
	new Effect.Move('portfolio_display_inner', {x: calcX, mode: 'absolute'});
}

function slideToPortfolioFromAlternate() {
	$('portfolio_area').show();

	new Effect.Parallel([
			new Effect.Move('alternate_area', {y: -460, mode: 'relative'}),
			new Effect.Move('portfolio_area', {y: -460, mode: 'relative'})
		], { duration: 0.65, afterFinish: function() {
			isAnimating = false;
/*			$('alternate_area').hide();
			$('portfolio_area').style.top = "-545px";*/
		}});
}

function slideFromPortfolioToAlternate() {
	$('alternate_area').show();
	$('portfolio_area').style.top = "-1005px";
	$('alternate_area').style.top = "-1005px";
	
	new Effect.Parallel([
			new Effect.Move('alternate_area', {y: 460, mode: 'relative'}),
			new Effect.Move('portfolio_area', {y: 460, mode: 'relative'})
		], { duration: 0.65, afterFinish: function() {
			isAnimating = false;
			/*$('portfolio_area').hide();
			$('alternate_area').style.top = "-545px";*/
		}});
}

function slideRightBody(section) {
	if (isAnimating) return;
	isAnimating = true;

	$('altleft_container').innerHTML = '<div id="altleft_upper" class="alternate_left_inner" style="position: relative; top: -440px;">' 
		+ $(section + "_left").innerHTML 
		+ "</div>"
		+ $('altleft_container').innerHTML;
	$('altleft').style.position = "relative";
	$('altleft').style.top = "-440px";
	
	$('altright_container').innerHTML = '<div id="altright_upper" class="alternate_right_inner" style="position: relative; top: -460px;">' 
		+ $(section + "_right").innerHTML 
		+ "</div>"
		+ $('altright_container').innerHTML;
	$('altright').style.position = "relative";
	$('altright').style.top = "-460px";
			
	new Effect.Parallel([
			new Effect.Move('altright', {y: 460, mode: 'relative'}),
			new Effect.Move('altright_upper', {y: 460, mode: 'relative'}),
			new Effect.Move('altleft', {y: 440, mode: 'relative'}),
			new Effect.Move('altleft_upper', {y: 440, mode: 'relative'})
		], { duration: 0.65, afterFinish: function() {
			isAnimating = false;
			$('altright_container').removeChild($('altright'));
			$('altright_upper').id = 'altright';
			$('altleft_container').removeChild($('altleft'));
			$('altleft_upper').id = 'altleft';
		}});
}

function slideRightContentTo(section) {
	if (isAnimating) return;
	isAnimating = true;
	$('link_' + section).blur();
	
	var newdiv = document.createElement("div");
	newdiv.innerHTML = $(section).innerHTML;
	newdiv.id = "altright_lower";
	newdiv.className = "alternate_right_inner";
	newdiv.style.top = "0px";
	newdiv.style.position = "relative";
	$('altright_container').appendChild(newdiv);

	if (section=='about_right') {
		$('link_about_right').className = 'about_left_menu_item_link_selected';
		$('link_about_right_leadership').className = 'about_left_menu_item_link';
		$('link_about_right_social').className = 'about_left_menu_item_link';
		$('link_about_right_media').className = 'about_left_menu_item_link';
	} else if (section=='about_right_leadership') {
		$('link_about_right').className = 'about_left_menu_item_link';
		$('link_about_right_leadership').className = 'about_left_menu_item_link_selected';
		$('link_about_right_social').className = 'about_left_menu_item_link';
		$('link_about_right_media').className = 'about_left_menu_item_link';
	} else if (section=='about_right_social') {
		$('link_about_right').className = 'about_left_menu_item_link';
		$('link_about_right_leadership').className = 'about_left_menu_item_link';
		$('link_about_right_social').className = 'about_left_menu_item_link_selected';
		$('link_about_right_media').className = 'about_left_menu_item_link';
	} else if (section=='about_right_media') {
		$('link_about_right').className = 'about_left_menu_item_link';
		$('link_about_right_leadership').className = 'about_left_menu_item_link';
		$('link_about_right_social').className = 'about_left_menu_item_link';
		$('link_about_right_media').className = 'about_left_menu_item_link_selected';
	}
			
	new Effect.Parallel([
			new Effect.Move('altright', {y: -460, mode: 'relative'}),
			new Effect.Move('altright_lower', {y: -460, mode: 'relative'})
		], { duration: 0.65, afterFinish: function() {
			isAnimating = false;
			$('altright_container').removeChild($('altright'));
			$('altright_lower').id = 'altright';
			newdiv.style.top = "0px";
		}});

}

function showPortfolio() {
	isAnimating = true;
	$('alternate_area').hide();
	$('portfolio_area').show();
	$('alternate_area').style.top = "-545px";
	$('portfolio_area').style.top = "-545px";
	new Effect.Parallel([
		new Effect.Move('welcome_area', { x: -1000, mode: 'relative' }),
		new Effect.Move('alternate_area', { x: -1000, mode: 'relative' }),
		new Effect.Move('portfolio_area', { x: -1000, mode: 'relative' })
	], {duration: 0.65,
		afterFinish: function() {
			isAnimating = false;
		}});
}

function showAlternate() {
	isAnimating = true;
	$('alternate_area').show();
	$('portfolio_area').hide();
	$('alternate_area').style.top = "-545px";
	$('portfolio_area').style.top = "-545px";
	new Effect.Parallel([
		new Effect.Move('welcome_area', { x: -1000, mode: 'relative' }),
		new Effect.Move('alternate_area', { x: -1000, mode: 'relative' }),
		new Effect.Move('portfolio_area', { x: -1000, mode: 'relative' })
	], {duration: 0.65,
		afterFinish: function() {
			isAnimating = false;
		}});
}

function showHome() {
	isAnimating = true;
	new Effect.Parallel([
		new Effect.Move('welcome_area', { x: 1000, mode: 'relative' }),
		new Effect.Move('alternate_area', { x: 1000, mode: 'relative' }),
		new Effect.Move('portfolio_area', { x: 1000, mode: 'relative' })
	], {duration: 0.65,
		afterFinish: function() {
			isAnimating = false;
		}});
}

function switchToPortfolio() {
	if (isAnimating) return;
	
	setLocationCookie("portfolio");
	
	$('home_button').src = 'images/btn_home_g.png';
	$('about_button').src = 'images/btn_about_g.png';
	$('contact_button').src = 'images/btn_contact_g.png';
	$('news_button').src = 'images/btn_news_g.png';
	$('portfolio_button').src = 'images/btn_portfolio_b.png';
	$('portfolio_button_link').blur();
	
	if (pageShowing == 'home') {
		showPortfolio();
	} else if (pageShowing == 'contact') {
		slideToPortfolioFromAlternate();
	} else if (pageShowing == 'news') {
		slideToPortfolioFromAlternate();
	} else if (pageShowing == 'about') {
		slideToPortfolioFromAlternate();
	}

	
	pageShowing = 'portfolio';
}

function switchToHome() {
	if (isAnimating) return;

	setLocationCookie("home");
	
	$('home_button').src = 'images/btn_home_b.png';
	$('about_button').src = 'images/btn_about_g.png';
	$('contact_button').src = 'images/btn_contact_g.png';
	$('news_button').src = 'images/btn_news_g.png';
	$('portfolio_button').src = 'images/btn_portfolio_g.png';
	$('home_button_link').blur();
	
	if (pageShowing=='about') {
		showHome();
	} else if (pageShowing=='contact') {
		showHome();
	} else if (pageShowing=='news') {
		showHome();
	} else if (pageShowing == 'portfolio') {
		showHome();
	}
	
	pageShowing = 'home';
}

function switchToAbout() {
	if (isAnimating) return;
	
	setLocationCookie("about");

	$('home_button').src = 'images/btn_home_g.png';
	$('about_button').src = 'images/btn_about_b.png';
	$('contact_button').src = 'images/btn_contact_g.png';
	$('news_button').src = 'images/btn_news_g.png';
	$('portfolio_button').src = 'images/btn_portfolio_g.png';
	$('about_button_link').blur();
	
	if (pageShowing == 'home') {
		$('altleft').innerHTML = $('about_left').innerHTML;
		$('altright').innerHTML = $('about_right').innerHTML;
		showAlternate();
	} else if (pageShowing == 'contact') {
		slideRightBody('about');
	} else if (pageShowing == 'news') {
		slideRightBody('about');
	} else if (pageShowing == 'portfolio') {
		$('altleft').innerHTML = $('about_left').innerHTML;
		$('altright').innerHTML = $('about_right').innerHTML;
		slideFromPortfolioToAlternate();
	}

	
	pageShowing = 'about';
}

function switchToContact() {
	if (isAnimating) return;
	
	setLocationCookie("contact");
	
	$('home_button').src = 'images/btn_home_g.png';
	$('about_button').src = 'images/btn_about_g.png';
	$('contact_button').src = 'images/btn_contact_b.png';
	$('news_button').src = 'images/btn_news_g.png';
	$('portfolio_button').src = 'images/btn_portfolio_g.png';
	$('contact_button_link').blur();
	
	if (pageShowing == 'home') {
		$('altleft').innerHTML = $('contact_left').innerHTML;
		$('altright').innerHTML = $('contact_right').innerHTML;
		showAlternate();
	} else if (pageShowing == 'about') {
		slideRightBody('contact');
	} else if (pageShowing == 'news') {
		slideRightBody('contact');
	} else if (pageShowing == 'portfolio') {
		$('altleft').innerHTML = $('contact_left').innerHTML;
		$('altright').innerHTML = $('contact_right').innerHTML;
		slideFromPortfolioToAlternate();
	}
	
	pageShowing = 'contact';
}


function switchToNews() {
	if (isAnimating) return;
	
	setLocationCookie("news");

	$('home_button').src = 'images/btn_home_g.png';
	$('about_button').src = 'images/btn_about_g.png';
	$('contact_button').src = 'images/btn_contact_g.png';
	$('news_button').src = 'images/btn_news_b.png';
	$('portfolio_button').src = 'images/btn_portfolio_g.png';
	$('news_button_link').blur();
	
	if (pageShowing == 'home') {
		$('altleft').innerHTML = $('news_left').innerHTML;
		$('altright').innerHTML = $('news_right').innerHTML;
		showAlternate();
	} else if (pageShowing == 'about') {
		slideRightBody('news');
	} else if (pageShowing == 'contact') {
		slideRightBody('news');
	} else if (pageShowing == 'portfolio') {
		$('altleft').innerHTML = $('news_left').innerHTML;
		$('altright').innerHTML = $('news_right').innerHTML;
		slideFromPortfolioToAlternate();
	}
	
	pageShowing = 'news';
}

function showPost(pid) {
	$('current_post_date').innerHTML = $('post_date_' + pid).innerHTML;
	$('current_post_body').innerHTML = $('post_' + pid).innerHTML;
}

function sendContact() {
	var pname = $('contact_name').value;
	var pemail = $('contact_email').value;
	var pphone = $('contact_phone').value;
	var pmessage = $('contact_message').value;
	var pdirect = $('contact_direct').value;
	
	if (pname=='') {
		alert("Please enter your name.");
		$('contact_name').focus();
		return;
	}
	
	if (pmessage=='') {
		alert("Please enter a message.");
		$('contact_message').focus();
		return;
	}
		
	new Ajax.Request('contact_ajax.php', {
		parameters: {
			name: pname,
			email: pemail,
			phone: pphone,
			message: pmessage,
			direct: pdirect
		}, 
		onSuccess: function(transport) {
			$('contact_name').value = '';
			$('contact_email').value = '';
			$('contact_phone').value = '';
			$('contact_message').value = '';
			$('contact_direct').value = '';
			alert("Your message has been sent!");
			return;
		}, 
		onFailure: function(transport) { 
			alert("Your message could not be sent at this time.  Please try again later.");
			return;
		}
	});
}
				
