var object = null;
var increment = 5;
var percent = 0;
var imgNames = new Array('reportlist.png','prompt.png','dashboard_small.png','reportlaunchflex_284.jpg', 'reportlaunchflex2_284.jpg');
var imgs = new Array();
var n = 0
var sq = '\'';
var pauseBetweenTransitions = 3000;
var pictNew = null;
var pictCurrent = null;
var isIE;

function InitPage()
{
	//Determine if IE is running and if so correct png images
	var agent = navigator.userAgent.toLowerCase();
	isIE = (agent.indexOf('msie') != -1);
	if (isIE) 
	{
		FixPngs(); 
	}
	else {
		ShowPngs();
		//enable mouse events
		//if (navigator.appName == 'Netscape') window.captureEvents(Event.MOUSEMOVE);
	}
	
	//TrackGoogleAnalytix();
}

function TrackMouse(objectID)
{
	var object = document.getElementById(objectID);
	object.onclick = GoToProduct;
}

// ************************** Slide Show Functions ********************************
function SetPictAlpha(object, percent) {
	//alert(percent);
	if (!isIE) 
	{
		var frac = (percent / 100);
		object.style.opacity = frac.toString();
	}
	else 
	{
		object.style.filter = 'alpha(opacity=' + percent + ')';
	}
}

function StartSlideShow() {
	
	//Preload images
	for (var i = 0; i < imgNames.length; i++) 
	{
		imgs[i] = new Image();
		imgs[i].src = 'images/' + imgNames[i];
	}
	
	//Initialize slides
	pictNew = document.images.pict1
	pictCurrent = document.images.pict2
	
	//Initialize, showing first slide immediately
	pictNew.src = imgs[0].src;
	SetPictAlpha(pictCurrent,0);
	pictNew.style.visibility = 'visible';
	pictCurrent.style.visibility = 'visible';
		
	//Transition Pictures in x seconds according to configured delay time
	setTimeout('TransitionPicts()', pauseBetweenTransitions);
}

function TransitionPicts()
{
		//Do not transition if still fading
		if (percent > 0 )
		{
			setTimeout('TransitionPicts()', 700);
			return;
		}
		
		n++;
		if (n > imgs.length - 1) 
		{ n = 0; }
		
		//Swap pictures so that the current will fade out, new will fade in
		var pictCurrentOld = pictCurrent;
		pictCurrent = pictNew;
		pictNew = pictCurrentOld;
		
		//Swap new picture to "current" image object and hide "new" image
		pictNew.src = imgs[n].src;
 		FadeIn();
		setTimeout('TransitionPicts()', pauseBetweenTransitions);
}

function FadeIn() {
	
	if (percent <= 100) {
		SetPictAlpha(pictNew, percent);
		SetPictAlpha(pictCurrent, 100 - percent);
		percent = percent + increment;
		setTimeout('FadeIn(pictNew,pictCurrent)',75);
	}
	else
	{
		//"Tag" invisible pict as hidden for easy identification
		percent = 0;
	}
}
//*********************end slide show functions

//*** Fix Png Functions
function FixPngs() 
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (document.body.filters)) 
	{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.className == 'png')
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = "class=" +sq + "png" + sq + ' '; //This strips the "png" class which hides the png image until it is ready
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle //= "display:inline-block;" + img.style.cssText ;
			imgStyle = "visibility:visible";
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			var strNewHTML = "<div " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></div>" ;
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
	}
}

//Pngs are initially hidden to work rounde lack of ie support so they must be shown for other browsers
function ShowPngs() 
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			img.style.visibility = 'visible';
		}
	}
}

//*********************** end FixPNGs function ************************************

function GoToProduct(e)
{
	//accounts for browser differences
	var e = (e) ? e: ((window.event) ? window.event: null);
	var y = e.clientY;
	if (y < 245) {window.location = "ReportLaunch.htm";}
	else if (y < 313) {window.location = "AuditLaunch.htm";}
	else if (y < 380) {window.location = "DashboardLaunch.htm";}
	else {window.location = "RapidNotificationLaunch.htm";}
}

function TrackGoogleAnalytix()
{
	//Track Google Analytix per Kevin request
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

	var pageTracker = _gat._getTracker("UA-5981003-1");
	pageTracker._trackPageview();
}

function validateInputForm()
{

	var f = document.forms.inputForm;
	if (f.fullName.value.length == 0 ) 
	{
		alert("Your full name must be provided!");
		return;
	}
	else if (f.companyName.value.length == 0 )
	{
		alert("Company name must be provided!");
		return;
	}
	else if (f.email.value.length == 0 || f.email.value.indexOf("@") == -1) 
	{
		alert("A valid e-mail address must be provided!");
		return;
	}
	else 
	{
		f.submit();
	}
	
}

