﻿//Benjamin Russell wrote these, Bruce externalized the scripts to here :-)

//this script is to make the querystringfeedback when a user clicks 'Site Feedback'
function createQueryStringFeedback(go, varName, url){
	var nu = go + "?" + varName + "=" + url;
	return nu;
}
//Search Bar script from rioscript.js
var text = new Array();
text[0] = "search site&hellip;";
var label = new Array();
label[0] = "site";
	
function searchBarEnterKey(e) {
	var characterCode;
	if(e && e.which) {
		e = e;
		characterCode = e.which;
	}
	else {
		e = event;
		characterCode = e.keyCode;
	}
	if(characterCode == 13) {
		searchBar();
		return false;
	}
	else
		return true;
}

function searchBar() {
	var searchType = $("#searchType").val();
	var searchText = $("#searchText").val();
	if (searchType == 0 && searchText != text[0] && searchText != text[1])
			siteSearch(searchText);
	else {
		window.alert("Please enter one or more search words.");
		$("#searchText").focus();
	}
}

function containsInvalidCharacter(someString) {
	if((someString.indexOf('?') != -1) || (someString.indexOf('#') != -1) || (someString.indexOf('&') != -1) || (someString.indexOf('+') != -1) || (someString.indexOf('%') != -1) || (someString.indexOf('[') != -1) || (someString.indexOf(']') != -1))
		return true;
	else
		return false;
}

function siteSearch(searchText) {
	window.location = '/help/Pages/search.aspx?k=' + searchText;
	return false;
}

function searchFix() {
	var searchType = 0;
	var address = window.top.location.toString();
	if (address.indexOf("/schedule/") != -1)
		searchType = 1
	swapSearch(searchType);
	$("#searchType").val(searchType);
	$("#searchText").val(text[searchType]);
}

//End searchbar script

//Start Rotating Banner Script
	//Initialize banner array         BANNERS  HERE
		var pbanners = new Array();
		pbanners[pbanners.length] = "<a href='http://www.riosalado.edu/online/Pages/default.aspx?utm_source=RioFuturePage&utm_medium=BodyLink&utm_campaign=OnlineLearning'><img src='http://www.riosalado.edu/future/html/images/banner_RioCampus.jpg'/></a>";
		
		pbanners[pbanners.length] = "<a href='http://www.riosalado.edu/advantages?utm_source=RioFuturePage&utm_medium=BodyLink&utm_campaign=RioAdvantage'><img src='http://www.riosalado.edu/future/html/images/banner02.jpg'/></a>";
		
		pbanners[pbanners.length] = "<a href='http://www.riosalado.edu/testimonials/pages/default.aspx?utm_source=RioFuturePage&utm_medium=BodyLink&utm_campaign=Testimonials'><img src='http://www.riosalado.edu/future/html/images/banner_InternationalRSC-Student_Maria.jpg'/></a>";
		
		pbanners[pbanners.length] = "<a href='http://www.uatrio.com/?utm_source=RioFuturePage?&utm_medium=BodyLink&utm_campaign=UatRio'><img src='http://www.riosalado.edu/future/html/images/banner_uatrio.jpg'/></a>";
		
		pbanners[pbanners.length] = "<a href='http://www.riosalado.edu/online/Pages/default.aspx?utm_source=RioFuturePage&utm_medium=BodyLink&utm_campaign=OnlineLearning'><img src='http://www.riosalado.edu/future/html/images/banner01.jpg'/></a>";

		var currentBanner = 0;
		var bannerTimer;
		
	function RotatingBanner() {
		// Initialize string to append
		var bannerDivs = "";
		
		// Concatenate html of each image in Array
		for(var i = 0; i < pbanners.length; i++) {
		
			// Append image html
			bannerDivs += '<div id="ProgramBanner'+i+'" class="RotatingBannerFade">'+pbanners[i]+'</div>\n';
		
		}
		
		// Append all images to DOM
		$('#rotating_banner').append(bannerDivs);
		
		// Show first program banner
		$('#ProgramBanner0').show();
		
		// Show Banner Nav
		$('#bannernav').show();
		
		//Call timer function to rotate banner
		FadeTimer();
			
	}
		
	function FadeBanner(_currentBanner){

		//Fade out the current banner over X milliseconds
		$('#ProgramBanner'+_currentBanner).fadeOut(2500);
		
		//Increment the private currentBanner
		_currentBanner++;
		
		//Loop back to the first banner if no more
		if(_currentBanner >= pbanners.length)
			_currentBanner = 0;
			
		//Bind private instance to global currentBanner
		currentBanner = _currentBanner;
		
		//Fade in the new banner over X milliseconds
		$('#ProgramBanner'+currentBanner).fadeIn(2500);
		
		//Call timer function to rotate to next banner
		FadeTimer();
		
	}
	function FadeTimer(){
	
		// create private instance of currentBanner
		var _currentBanner = currentBanner;
		
		// create timer to call the FadeBanner() function passing the private currentBanner after X milliseconds
		bannerTimer = setTimeout('FadeBanner('+_currentBanner+')',9000);
		
	}
	function PreviousBanner(_currentBanner){
		
		//Stop the banner timer
		clearTimeout(bannerTimer);
		
		//Hide current banner
		$('#ProgramBanner'+_currentBanner).fadeOut(50);
		
		//Decrement the private currentBanner
		_currentBanner--;
		
		//Loop to the last banner if this is the first
		if(_currentBanner <= -1)
			_currentBanner = pbanners.length - 1;
			
		//Bind private instance to global currentBanner
		currentBanner = _currentBanner;
		
		//Show the new banner 
		$('#ProgramBanner'+currentBanner).fadeIn(150);
		
		//Call timer function to restart the rotation proccess
		FadeTimer();
		
	}
	function NextBanner(_currentBanner){
	
		//Stop the banner timer
		clearTimeout(bannerTimer);
		
		//Hide current banner
		$('#ProgramBanner'+_currentBanner).fadeOut(50);
		
		//Increment the private currentBanner
		_currentBanner++;
		
		//Loop back to the first banner if no more
		if(_currentBanner >= pbanners.length)
			_currentBanner = 0;
			
		//Bind private instance to global currentBanner
		currentBanner = _currentBanner;
		
		//Show the new banner 
		$('#ProgramBanner'+currentBanner).fadeIn(150);
		
		//Call timer function to restart the rotation proccess
		FadeTimer();
	}
	
//End Rotating Banner Script
	//On Load scripts
	$(document).ready(function(){
		
		//Call Rotating Banner Function on Page Load
		RotatingBanner();
		
		//On Click function for Banner Nav (Left Arrow)
		$('#bannernavleft').click(function(){
			PreviousBanner(currentBanner);			
		});
		
		//On Click function for Banner Nav (Right Arrow)
		$('#bannernavright').click(function(){
			NextBanner(currentBanner);			
		});

	});



