var current = 'featured';

window.addEvent('domready', function() {
	// Header Sliding
	$('slogan'+currentSlogan).move({relativeTo: $('header'), position: 'center', edge: 'topLeft', offset: {x: -118, y:-21}});
	setTimeout("nextSlide()", 7500 );
	
	//Featured Articles slider system
	$('featured').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:0}});
	$('news').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 792, y:0}});
	$('success').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 1584, y:0}});
	$('smlContent').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:191}});
	
	$('articlesBtn').style.textDecoration = 'underline';
	
	$('articlesBtn').addEvent('click', function(e){
		showArticles();
	});
	$('newsBtn').addEvent('click', function(e){
		showNews();
	});
	$('successBtn').addEvent('click', function(e){
		showSuccess();
	});
	
});

function showArticles(){
	current = 'featured';
	
	$('featured').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:0}});
	$('news').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 792, y:0}});
	$('success').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 1584, y:0}});
	$('smlContent').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:191}});
	
	$('articlesBtn').style.textDecoration = 'underline';
	$('newsBtn').style.textDecoration = 'none';
	$('successBtn').style.textDecoration = 'none';
	
	document.getElementById('featuredTitle').innerHTML = 'Featured Articles';
}

function showNews(){
	current = 'news';
	
	$('featured').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: -792, y:0}});
	$('news').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:0}});
	$('success').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 792, y:0}});
	$('smlContent').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:191}});
	
	$('articlesBtn').style.textDecoration = 'none';
	$('newsBtn').style.textDecoration = 'underline';
	$('successBtn').style.textDecoration = 'none';	
	
	document.getElementById('featuredTitle').innerHTML = 'News &amp; Events';
}

function showSuccess(){
	current = 'success';
	
	$('featured').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: -1584, y:0}});
	$('news').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: -792, y:0}});
	$('success').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:0}});
	$('smlContent').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:191}});
	
	$('articlesBtn').style.textDecoration = 'none';
	$('newsBtn').style.textDecoration = 'none';
	$('successBtn').style.textDecoration = 'underline';
	
	document.getElementById('featuredTitle').innerHTML = 'Success Stories';
}

function showLast(){
	if(current == 'featured'){
		showArticles();
	} else if (current == 'news'){
		showNews();
	} else if(current == 'success'){
		showSuccess();
	}
}

var currentSlide = 1;
var currentSlogan = 1;

function nextSlide(){
	if(currentSlide == 4){
		setTimeout("nextSlide()", 7500);
	} else {
		setTimeout("nextSlide()", 5000);
	}
	
	setTimeout("nextSlogan()", 250 );
	
	var coord = $('header').getCoordinates();
	var coord2 = $('img'+currentSlide).getCoordinates();
	
	$('img'+currentSlide).move({relativeTo: $('header'), position: 'upperLeft', edge: 'upperRight', offset: {x: 0, y:0}});
	
	if(currentSlide < 4 ){
		currentSlide++;
	} else {
		currentSlide = 1;
	}
	
	$('img'+currentSlide).setPosition({x: coord['width'] + coord['left'] + (coord2['width'] / 2), y: 0});
	$('img'+currentSlide).move({relativeTo: $('header'), position: 'center', edge: 'center', offset: {x: 0, y:0}});
}

function nextSlogan(){
	var coord = $('header').getCoordinates();
	
	$('slogan'+currentSlogan).move({relativeTo: $('header'), position: 'center', edge: 'topLeft', offset: {x: -118, y:-130}});
	//$('slogan'+currentSlogan).set('tween', {duration: 'short'});
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
	} else {
		$('slogan'+currentSlogan).fade('out');
	}
	
	if(currentSlogan < 4 ){
		currentSlogan++;
	} else {
		currentSlogan = 1;
	}
	
	$('slogan'+currentSlogan).fade('show');
	$('slogan'+currentSlogan).setPosition({x: coord['width'] + coord['left'], y: 65});
	$('slogan'+currentSlogan).move({relativeTo: $('header'), position: 'center', edge: 'topLeft', offset: {x: -118, y:-21}});
}

function showContent(cont){
	document.getElementById('smlContent').innerHTML = document.getElementById(cont).innerHTML + '<div id="goBack"><a href="javascript:showLast();">&laquo;Back</a></div>';
	
	$('smlContent').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: 0, y:0}});
	
	var mainCoord = $('articles').getCoordinates();
	var featuredCoord = $('featured').getCoordinates();
	var newsCoord = $('news').getCoordinates();
	var successCoord = $('success').getCoordinates();
	
	$('featured').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: featuredCoord['left'] - mainCoord['left'], y:-191}});
	$('news').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: newsCoord['left'] - mainCoord['left'], y:-191}});
	$('success').move({relativeTo: $('articles'), position: 'upperLeft', edge: 'upperLeft', offset: {x: successCoord['left'] - mainCoord['left'], y:-191}});
}
