// -------------- VARIABLES --------------
var bgs = 16;		// 16 Set this to the total number of background images

// -------------- ALWAYS RUN --------------
// Set copyright year
var d = new Date();
var currentYear = d.getFullYear();

// NS4 resize workaround...
MM_reloadPage(true);

var nextPage = "";
var curPage = "";
var nextTopic = "";

//reloads the window if Nav4 resized

//check browser
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isDHTML = (isIE5 || isNS6);
var isPc = navigator.userAgent.indexOf("Windows") != -1;
var isMac = !isPc;
var yPos = 0;
var isIE6 = false;
var isIE7 = navigator.userAgent.indexOf("MSIE 7.") != -1;
if (isIE7) {
  isIE6 = false;
} else {
  isIE6 = navigator.userAgent.indexOf("MSIE 6.0") != -1;
}

// check flash
var useFlash = false;

if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
// Check for Flash version 5 or greater in Netscape
var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
//alert(plugin);
//alert(parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)));
if (plugin && parseInt(plugin.description.substring(plugin.description.indexOf(".")-1))>=5)
	useFlash = true;
} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	// Assume any Windows IE except for Windows 3.1 supports the OBJECT tag
	useFlash = true;
}

fadeEndOpacity = 90;
fadeIncreaseBy = 5;
fadeIncreaseTimeout = 1; 
fadePause = 100;
currentOpacity = 0;
var timer = null;

function fadeOut(goToPage){
	nextPage = goToPage;
	fadeContentContainer.start();
}
function showNextPage() {
	document.location.href=nextPage;
}

// *** SPRY STUFF
function buildPage(pg) {
curPage = pg;
	if (pg == 'HOME') {
		buildHomePage();
	} else {
		buildStandardPage();
	}
}
function buildStandardPage() {
	showRandomBackground();
}
function showRandomBackground() {
	if (document.images) {
		var limit = bgs + 1;

		j=parseInt(Math.random()*limit);
		j=(isNaN(j))?0:j;
		if (j>bgs) {
		 j = bgs;
		}
		if (j==0) {
			j = 1;
		}
		
		document.getElementById('mainContentContainer').style.background = "url('img/bg" + j + ".jpg') no-repeat top center";
		setTimeout("showContent();",100);
	}
}

function fadeThenShowContent(divToShow) {
	nextTopic = divToShow;
	
	fadeContentText.start();
}

function showContent() {
	
	var defaultSelected = false;

	
	// If no topics defined in XML, just fade in the content region
	if (typeof dsTopics != "undefined") {
		var topics = dsTopics.getData();
	
		for (var i = 0; i < topics.length; i++)
		{
			document.getElementById(topics[i]["id"]).style.display = "none";				// turn off all content divs
			document.getElementById(topics[i]["id"] + 'link').className = "footerLink";	// set all links to footerLink class
		}
		
		var divID = nextTopic;
		if (divID == "") {	
				divID = topics[0]["id"];
				defaultSelected = true;
		}
	
		// set current link to footerLinkCurrent class
		document.getElementById(divID + "link").className = "footerLinkCurrent";
		
		// turn on current content div
		document.getElementById(divID).style.display = "block";
		
		if (curPage == "CUSTOMERS") {
			document.getElementById('mainContentListCustomers').style.visibility = "visible";
		} else if (curPage == "PRODUCTS") {
			document.getElementById('mainContentListProducts').style.visibility = "visible";
		} else {
			document.getElementById('mainContentSubLinks').style.visibility = "visible";
		}
	} else {
		defaultSelected = true;
	}
	
	if (!defaultSelected) {
	showContentText.start();
	}

}

//*****************************************
// *** HOME PAGE STUFF
function buildHomePage() {
	document.getElementById('mainContentContainer').style.background = "url('img/bgHome.jpg') no-repeat top center";
	showBackground.start();
	setTimeout("fadeInFeatures();",500);
	psgPreload();
}
function fadeInFeatures() {
	showContentBg.start();
	showFeature1.start();
	setTimeout("fadeInFeature2();",600);
	setTimeout("fadeInFeature3();",900);
	setTimeout("fadeInFeature4();",1200);
}
function fadeInFeature2() {
	showFeature2.start();
}
function fadeInFeature3() {
	showFeature3.start();
}
function fadeInFeature4() {
	showFeature4.start();
}
function fadeInFeature5() {
	showFeature5.start();
}
// ****** END SPRY STUFF

function hideLink(pageLink) {
	document.getElementById(pageLink).className = "mastheadText";
	document.getElementById(pageLink).removeAttribute("href");
}
function hideFooterLink(pageLink) {
	document.getElementById(pageLink).className = "footerText";
	document.getElementById(pageLink).removeAttribute("href");

}
function showMainContentPic() {
		showContentContainer.start();
		if (isIE6) {
			setTimeout("forceDisplay();",500);
		}
}

function forceDisplay() {
	document.getElementById('mainContentContainer').style.opacity = 99;
	document.getElementById('mainContentContainer').style.opacity = 100;
}



function MM_reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function psgPreload()
{
	setTimeout("psgPreloadImages('mainContentBackground.gif','bgX1','bgX2','bgX3','bgX4','bgX5','bgX6','bgX7','bgX8','bgX9','bgX10','bgX11','bgX12','bgX13','bgX14','bgX15','bgX16')",1000);
}
function psgPreloadImages()
{ 
  var args = psgPreloadImages.arguments;
  document.imageArray = new Array(args.length);
  for(var i=1; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = '../img/' + args[i] + '.jpg';
  }
}

