// RETURN THE HTML ID's
function $(idTag){
	return document.getElementById(idTag);
}


// GET WINDOW HEIGHT
function getWindowHeight() {
	var windowHeight = 0
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		windowHeight = window.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight ) {
		//IE
		windowHeight = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight ) {
		//IE 4 compatible
		windowHeight = document.body.clientHeight;
	}
	return windowHeight;
}


// EXPAND MAIN CONTENT ON THE RIGHT COLUMN
function expandMainContent() {
	if($('rightContent')){
		if($('mainContent')){
			$('mainContent').style.width = '545px';
			$('mainContent').style.marginRight = '26px';
			$('rightContent').style.width = '169px';
		}
	}
}

// FOOTER POSITIONING

function setFooter() {
	var windowHeight = getWindowHeight(),
	globalHeight = 0,
	socCarouselHeight = 0,
	bannerHeight = 0,
	contentHeight = 0,
	headerHeight = 0,
	navHeight = 0,
	footerHeight = 0
	
	
	
	
	if (windowHeight > 0) {
		if($('headContainer'))
			headerHeight = $('headContainer').offsetHeight;
		
		if($('mainNav'))
			navHeight = $('mainNav').offsetHeight;

		if($('bannerContainer'))
			bannerHeight = $('bannerContainer').offsetHeight;
			
		if($('content'))
			contentHeight = $('content').offsetHeight;
			
		if($('middleContainer'))
			contentHeight = $('middleContainer').offsetHeight;		
		
		if($("footer"))
			footerHeight = $("footer").offsetHeight;
		
		
		globalHeight = headerHeight + navHeight + bannerHeight + contentHeight;
		
		if($('societyCarousel'))
			socCarouselHeight = $('societyCarousel').offsetHeight;
		
		
				
		if (windowHeight - (globalHeight + footerHeight + socCarouselHeight) >= 0){
			$('footerContainer').style.top = (windowHeight - footerHeight - socCarouselHeight + 4 ) + 'px';
		}
		else{
			$('footerContainer').style.top = globalHeight + 'px';
		}
	}
	$('footerContainer').style.display = 'block';
}


// CRISIS MESSAGE DISPLAY
function openDiv(){
	if($('crisisMessageBg')){
		if($('middleContainer') && (navigator.userAgent.toLowerCase().indexOf('msie')!=-1) && !$('brandsAndActivities')){
			// headContainer is hidden in IE when crisis is shown
			$('middleContainer').style.top='115px';
		}
		var windowHeight = getWindowHeight();
		var headerHeight = $('headContainer').offsetHeight;
		var navHeight = $('mainNav').offsetHeight;
		var bannerHeight = 0;
		if($('bannerContainer')!=null) bannerHeight = $('bannerContainer').offsetHeight;
		
		var globalHeight = headerHeight + navHeight + bannerHeight;
		var footerHeight = $('footerContainer').offsetHeight;
		if (windowHeight - (globalHeight + footerHeight) < 0){
			$('crisisMessageBg').style.display ='block';
			$('crisisMessageBg').style.height = (globalHeight + footerHeight) + 'px';
			$('crisisMessage').style.display ='block';
		}
		else {
			$('crisisMessageBg').style.display ='block';
			$('crisisMessageBg').style.height = windowHeight + 'px';
			$('crisisMessage').style.display ='block';
		}
	}
}

function insertFlash(flashWidth,flashHeight,flashUrl,alternateContent,divID,language){
	<!--
	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
	var hasProductInstall = DetectFlashVer(6, 0, 65);
	
	// Version check based upon the values defined in globals
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	
	// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
	if ( hasProductInstall && !hasRequestedVersion ) {
		// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
		// This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
		// DO NOT MODIFY THE FOLLOWING FOUR LINES
		// Location visited after installation is complete if installation is required
		var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
		var MMredirectURL = window.location;
	    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
	    var MMdoctitle = document.title;
	
		AC_FL_RunContent(
			"src", flashUrl,
			"FlashVars", "language="+language+"&MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
			"width", flashWidth,
			"height", "159",
			"align", flashHeight,
			"id", "",
			"quality", "high",
			"bgcolor", "#869ca7",
			"name", "main",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer",
			"wmode", "transparent"
		);
	} else if (hasRequestedVersion) {
		// if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
		AC_FL_RunContent(
				"src", flashUrl,
				"ext","",
				"width", flashWidth,
				"height", flashHeight,
				"align", "middle",
				"id", "",
				"quality", "high",
				"bgcolor", "#869ca7",
				"name", "main",
				"flashvars","language="+language,
				"allowScriptAccess","sameDomain",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer",
				"wmode", "transparent"
		);
	  } else {  // flash is too old or we can't detect the plugin
	    document.getElementById(divID).innerHTML = alternateContent;  // insert non-flash content
	  }
}

function closeDiv(){
	$('crisisMessageBg').style.display ='none';
	$('crisisMessage').style.display ='none';
	if($('middleContainer'))$('middleContainer').style.top='0';
}
var passed='false';



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();





// FUNCTIONS LOADING
window.onload = function() {
	if(passed=='false'){
		expandMainContent() ;
		passed='true';
		openDiv();
		setFooter();
		window.onresize();
	}
}
window.onresize = function() {
	setFooter();
}



