/** @author Kyle Phillips
 *  uses prototype
 *  main page javascript
 */

var flashDetected = false;
/* News Story Div rotation
*/

//var newsStories = new Array('newsText2','newsText3','newsText4');
var currentNewsStory = '#newsText1';



function getNextNewsStory() {
	newsStories.push(currentNewsStory);
	currentNewsStory = newsStories.shift();

	return currentNewsStory;
}

function getPreviousNewsStory() {
	newsStories.unshift(currentNewsStory);
	currentNewsStory = newsStories.pop();
	
	return currentNewsStory;
}


function nextNewsDiv() {
	$(currentNewsStory).hide();
	$(getNextNewsStory()).show();
}

function previousNewsDiv() {
	$(currentNewsStory).hide();
	$(getPreviousNewsStory()).show();
}




/* Upcoming Events Div rotation
*/

var currentEvent = '#eventsText1';
var currentEventsImage = '#eventsPicture1';

function getNextEvent() {
	events.push(currentEvent);
	currentEvent = events.shift();

	return currentEvent;
}

function getNextEventsImage(){
	eventsPictures.push(currentEventsImage);
	currentEventsImage = eventsPictures.shift();
	return currentEventsImage;
}

function getPreviousEvent() {
	events.unshift(currentEvent);
	currentEvent = events.pop();
	
	return currentEvent;
}

function getPreviousEventsImage() {
	eventsPictures.unshift(currentEventsImage);
	currentEventsImage = eventsPictures.pop();
	return currentEventsImage;
}


function nextEventDiv() {
	$(currentEvent).hide();
	$(getNextEvent()).show();
	
	if(flashDetected)playNextinFlash();
	else
	{
		$(currentEventsImage).hide();
		$(getNextEventsImage()).show();
	}
}

function previousEventDiv() {
	$(currentEvent).hide();
	$(getPreviousEvent()).show();
	//$(getPreviousEvent()).scrollTo(1000, {axis:'x'} );
	
	if(flashDetected)playPreviousinFlash();
	else
	{
		$(currentEventsImage).hide();
		$(getPreviousEventsImage()).show();
	}
}



/*
 * Featured Artist Div Rotation
 */
 
 var currentFAStory = '#artistText1';



function getNextFAStory() {
	featuredArtists.push(currentFAStory);
	currentFAStory = featuredArtists.shift();

	return currentFAStory;
}

function getPreviousFAStory() {
	featuredArtists.unshift(currentFAStory);
	currentFAStory = featuredArtists.pop();
	
	return currentFAStory;
}


function nextFADiv() {
	$(currentFAStory).hide();
	$(getNextFAStory()).show();
}

function previousFADiv() {
	$(currentFAStory).hide();
	$(getPreviousFAStory()).show();
}

/* opportunities
 * 
 */

function revealOpportunity(id) {
	$("#more"+id).css('display','none');
	$("#less"+id).css('display','block');
	$("#oppsText"+id).slideToggle(500);
}
function hideOpportunity(id) {
	$("#less"+id).css('display','none');
	$("#more"+id).css('display','block');
	$("#oppsText"+id).slideToggle(500);
}
function postOpportunity(opp_id, user_id) {
	var postAction = "remove";	
	if($("input#oppCheck"+opp_id+":checked").length) postAction = "add";
	$('#oppCheck'+opp_id).after( ' &nbsp;<img src="/common/images/ui/loadingWoB.gif" id="oppUpdater_'+opp_id+'" />')
		
	$.get("oppsAjaxForm.php", {action: postAction,opp_id: opp_id, user_id: user_id},
		function(data){
			$('#oppUpdater_'+opp_id).remove();
			$('#oppBlurb'+opp_id).slideUp();
		});
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function playNextinFlash() {
	getFlashMovie("media_player").playNext();
}
function playPreviousinFlash() {
	getFlashMovie("media_player").playPrevious();
}