/*---------------------------------------
	Project:		OneGoal.com Redesign
	
	+ Ajax Init
	+ Functions
		++ Redirect
		++ Change Navs
		++ Nav Rollovers
*/

// + Ajax Init
// Create a new XMLHttpRequest object to talk to the Web server
var loopStart = false;
var xmlHttp = false;

try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e2) {
    xmlHttp = false;
  }
}
if(!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

// + Functions
function getMovie(movieName){
	return document.getElementById(movieName);
}
function checkFooter(id){
	if(id == 23 || id== 24 || id== 25 || id== 26 || id==33){
		var headerFlash = getMovie('headerFFE');
		headerFlash.swapFFE(200);
	}
};
// ++ Redirect
function reDirect(id) {
	var stripID = id.replace('#','');
	var newID = Number(stripID);
	// for selecting the language
	if(newID == 56){
		langSelect('FR');
	}else{
		langSelect('EN');
	}
	location.href = '/includes/redirect.php?id=' + newID;
}
// ++ Change Navs
function changeMainNav(id) {
	if(id > 36 && id < 41) {
		if(currentSection == undefined) {
			currentSection = 37;
		}
	}
	if(currentSection == undefined) {
		currentSection = 2;
	}
	if(currentSection != id) {
		document.getElementById('nav_' + currentSection).className = 'nav_' + currentSection;
		document.getElementById('nav_' + id).className = 'nav_' + id + '-active';
		currentSection = id;
	var dropdown = "#dropdown_" + id;
	$(dropdown).hide();

	}
	startAjax(id);
	
	// for talking to the headerFFE
	var headerFlash = getMovie('headerFFE');
	headerFlash.swapFFE(id);
	
	if(!loopStart){
		checkHash();
	}
	
}
function changeSubNav(id) {
	startAjax(id);
	
	if(!loopStart) {
		checkHash();
	}
}

var currentPage;
function startAjax(id) {
	// for selecting the language
	if(id == 56){
		langSelect('FR');
	}else{
		langSelect('EN');
	}
	
	// for the back button
	currentPage = id;
	
	xmlHttp.open("GET","/includes/navigate.php?id=" + id,true);
	xmlHttp.onreadystatechange = loadPage;
	xmlHttp.send(null);
	location.hash = id;
	pageTracker._trackPageview(id);
	// checking to see if the page is part of the footer
	checkFooter(id);
}
function loadPage() {
	if(xmlHttp.readyState == 4) {
		//alert(document.getElementById('contentWrap').offsetHeight);
		// jQuery
		$(document).ready(function() {
			$("#contentWrap").fadeOut(function() {
				document.getElementById('contentWrap').innerHTML = xmlHttp.responseText;
			});
			$("#contentWrap").fadeIn();
		});
	}
}
// for the footer search box
var domainroot="www.onegoal.com"

function Gsitesearch(curobj){
	curobj.q.value="site:"+domainroot+" "+curobj.qfront.value;
}

// ++ Nav Rollovers
function rollOver(id) {
	//console.log('rollOver('+ id +')');
	var dropdown = "#dropdown_" + id;
	document.getElementById('nav_' + id).className = 'nav_' + id + '-hover';
	$(dropdown).show();
}
function active(id) {
	//console.log('active('+ id +')');
	document.getElementById('nav_' + id).className = 'nav_' + id + '-active';
}
function rollOut(id) {
	//console.log('rollOut('+ id +')');
	var dropdown = "#dropdown_" + id;
	$(dropdown).hide();
	if(currentSection != id) {
		$('#nav_' + id).removeClass('nav_' + id + '-hover');
		document.getElementById('nav_' + id).className = 'nav_' + id;
	}
	else{
		document.getElementById('nav_' + id).className = 'nav_' + id + '-active';
	}
}
