/* IE 6 navigation hover effects are done with the csshover.htc file in the web root, and invoked in ie6.css, not via javascript here */
/* IE 6 24-bit PNG image transparency is done with the iepngfix.htc file in the web root, and invoked in ie6.css, not via javascript here */

// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/


/* START JQUERY-DEPENDENT CODE */

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function(){

/* Scrolling of items in div.content-nav-items (e.g. PackBot Kits scrolling) */
$('div.content-nav-items').serialScroll({
	items:'li',
	prev:'a.content-nav-prev',
	next:'a.content-nav-next',
	start:0, // 1st item has an index of 0
	duration: 200, // length of scrolling animation
	force:true,
	stop:false,
	lock:false,
	cycle:false, // don't rewind once you reach the end
	easing:'easeOutQuart', // easing equation defined above
	step: 1
});// end serialScroll

/* Scrolling of items in div.content-nav-items2 (e.g. 5th nav in research section) */
$('div.content-nav-items2').serialScroll({
	items:'li',
	prev:'a.content-nav-prev2',
	next:'a.content-nav-next2',
	start:0, // 1st item has an index of 0
	duration: 200, // length of scrolling animation
	force:true,
	stop:false,
	lock:false,
	cycle:false, // don't rewind once you reach the end
	easing:'easeOutQuart', // easing equation defined above
	step: 1
});// end serialScroll

/* Scrolling of photos in div.filmstrip-items (Filmstrip navigation scrolling)*/
$('div.filmstrip-items').serialScroll({
	items:'li',
	prev:'a.filmstrip-prev',
	next:'a.filmstrip-next',
	start:0, // 1st item has an index of 0
	duration: 200, // length of scrolling animation
	force:true,
	stop:false,
	lock:false,
	cycle:true, // don't rewind once you reach the end
	easing:'easeOutQuart', // easing equation defined above
	step: 1
});// end serialScroll

/* Filmstrip navigation button behaviors */

/* roll into a GI splash page filmstrip button */
$("div.filmstrip-items a").mouseover(function() {
	$(this).removeClass("inactive").addClass("active");
	$(this).siblings("span").css("color","#FFFFFF");
	$(".inactive").css("background-position", "0 -126px");
	var caption = $(this).siblings("span").text();
	/* IF statement checks that caption is NOT surrounded by brackets; shouldn't need this check, but do it to be safe */
	if (caption.substring(0,2) != "[ " && caption.substring(caption.length,caption.length-2) != " ]") {
		$(this).siblings("span").prepend("[ ").append(" ]"); /* put the brackets around it */
	}
});

/* roll out of a GI splash page filmstrip button */
$("div.filmstrip-items a").mouseout(function() {
	$(this).addClass("inactive");
	$(this).siblings("span").css("color", "#d2d2d2");
	$(".inactive").css("background-position", "0 0");
	var caption = $(this).siblings("span").text();
	/* IF statement checks that caption IS surrounded by brackets; shouldn't need this check, but do it to be safe */
	if (caption.substring(0,2) == "[ " && caption.substring(caption.length,caption.length-2) == " ]") {
		var noFront = caption.substring(2,(caption.length)); /* strip the front bracket & space */
		var noBack = noFront.substring(0, noFront.length-2); /* strip the back bracket & space */
		$(this).siblings("span").text(noBack); /* set the actual caption to the stripped string */
	}
	/* restore default image in #video-holder */
	$("#video-holder").css("background", "transparent url(images/splash-video-negotiator.png) no-repeat 0 0");
/* 	$("#video-holder").css("background", "none"); */
});

/* Upon roll into filmstrip buttons, change static bg image of #video-holder appropriately */
/* Seaglider */
$("#filmstrip-seaglider a").mouseover(function() {
	$("#video-holder").css("background", "transparent url(images/splash-video-seaglider.png) no-repeat 0 0");
});
/* Packbot */
$("#filmstrip-packbot a").mouseover(function() {
	$("#video-holder").css("background", "transparent url(images/splash-video-packbot.png) no-repeat 0 0");
});
/* Negotiator */
$("#filmstrip-negotiator a").mouseover(function() {
	$("#video-holder").css("background", "transparent url(images/splash-video-negotiator.png) no-repeat 0 0");
});
/* SUGV */
$("#filmstrip-sugv a").mouseover(function() {
	$("#video-holder").css("background", "transparent url(images/splash-video-sugv.png) no-repeat 0 0");
});
/* Warrior */
$("#filmstrip-warrior a").mouseover(function() {
	$("#video-holder").css("background", "transparent url(images/splash-video-warrior.png) no-repeat 0 0");
});
/* Research */
$("#filmstrip-research a").mouseover(function() {
	$("#video-holder").css("background", "transparent url(images/splash-video-research.png) no-repeat 0 0");
});

/* ================== */

/* PACKBOT OVERVIEW PAGE: image swap on silver navbar hover */
/* swap PackBot images when rolling over PackBot content nav buttons */
$("div.content-nav-items a").mouseover(function() { /* on mouseover */
	var myID = $(this).parent().attr("id"); /* get the id of the parent li */
	var kit = myID.substring(myID.lastIndexOf("-")+1, myID.length); /* get string after last hyphen in id */
	var bgCSS = 'transparent url(images/packbot/packbot-image-' + kit + '.png) no-repeat 0 0'; /* build CSS */
	/* following kit check is for IE6: no swap on "extra" LIs with no ID in nav, for scrolling demo; empty swaps kill transparency in IE6 */
	if(kit) { /* don't swap backgrounds if the kit var is empty */
		$("#packbot-image").css("background", bgCSS); /* change bg of image div */
		if ( $.browser.msie && $.browser.version.substring(0,1) == "6") {
			$("#packbot-image").css("behavior", "url(iepngfix.htc)");
		}
	}
});

/* reset PackBot image to default "EOD" when rolling out of a content nav button */
$("div.content-nav-items a").mouseout(function() { /* on mouseout */
	$("#packbot-image").css("background", "transparent url(images/packbot/packbot-image-eod.png) no-repeat 0 0"); /* empty image div */
	if ( $.browser.msie && $.browser.version.substring(0,1) == "6") {
		$("#packbot-image").css("behavior", "url(iepngfix.htc)");
	}
});

$("#packbot-attributes dt a").mouseover(function() {
	var myClass = $(this).parent().attr("class"); /* get the class of the anchor moused over */
/* 	alert(myClass); */
/* 	var ddName = "dd." + myClass; */
/* 	alert(ddName); */
	var defaultClass = "attributes-mobile";
	$("#packbot-attributes dd").hide();
	$("dd." + myClass).css("display", "block");
	if (myClass != defaultClass) {
		$("#packbot-attributes dt." + defaultClass + " a").css("color", "#CE830F");
	}
});

$("#packbot-attributes dt a").mouseout(function() {
	$("#packbot-attributes dd").hide(); /* hide all the dds */
	$("#packbot-attributes dt.attributes-mobile a").css("color", "#000000"); /* colorize the default dt */
	$("#packbot-attributes dd.attributes-mobile").css("display", "block"); /* show the default dd */
});

});//end document.ready

/* END JQUERY-DEPENDENT CODE */

function swapRobotDiv(oldDiv, newDiv) {
	if (document.getElementById(newDiv)) {
		document.getElementById(oldDiv).style.display = "none";
		document.getElementById(newDiv).style.display = "block";
	}
}

/*Splash page robot image rollover*/
function toggleLandingRobot(y, header, state) {
	/*Sets the sprite background position on main image*/
	document.getElementById('misLandingImageCont').style.backgroundPosition = y;
}

/* Kit Page Functions*/
function toggleProductKit(on, off) {
	document.getElementById('kit-right' + on).style.display = "block";
	document.getElementById('kit-right' + off).style.display = "none";
	if (on == 0) {
		document.getElementById('kit-sub-head' + off).className = "kit-sub-heads";
		document.getElementById('kit-left-bracket' + off).className = "kit-left-bracket-off";
		document.getElementById('kit-right-bracket' + off).style.display = "none";
	} else {
		document.getElementById('kit-sub-head' + on).className = "kit-sub-heads-over";
		document.getElementById('kit-left-bracket' + on).className = "kit-left-bracket-on";
		document.getElementById('kit-right-bracket' + on).style.display = "block";
	}
}

function toggleProductKitExpanded(on, off, url) {
	var backUrl = "url(" + url + on + ".jpg)";
	document.getElementById('kitRightExpand').style.backgroundImage = backUrl;
	if (on == 0) {
		document.getElementById('kit-sub-head' + off).className = "kit-sub-heads";
		document.getElementById('kit-left-bracket' + off).className = "kit-left-bracket-off";
		document.getElementById('kit-right-bracket' + off).style.display = "none";
	} else {
		document.getElementById('kit-sub-head' + on).className = "kit-sub-heads-over";
		document.getElementById('kit-left-bracket' + on).className = "kit-left-bracket-on";
		document.getElementById('kit-right-bracket' + on).style.display = "block";
	}
}

function toggleFeatureKit(featureNum) {
	if (document.getElementById('kitFeature' + featureNum).style.display == 'block') {
		document.getElementById('kitFeature' + featureNum).style.display = "none";
		document.getElementById('kitFeaturesDots' + featureNum).style.background = "url(/images/main/spacer.gif)";
		/*document.getElementById('kitFeatureBg').style.display = "none";*/
		document.getElementById('kit-sub-head1').style.display = "block";
		document.getElementById('kit-sub-head2').style.display = "block";
		document.getElementById('kit-sub-head3').style.display = "block";
	} else {
		document.getElementById('kitFeature' + featureNum).style.display = "block";
		document.getElementById('kitFeaturesDots' + featureNum).style.background = "url(/images/govt/robots/packbot/kitfeaturedots.gif)";
		/*document.getElementById('kitFeatureBg').style.display = "block";*/
		document.getElementById('kit-sub-head1').style.display = "none";
		document.getElementById('kit-sub-head2').style.display = "none";
		document.getElementById('kit-sub-head3').style.display = "none";
	}
}
/* End Kit Page Functions*/

/*Mission Pages Functions*/

/*
y is a string value to set background position for the main research sprite in format Xpx Ypx
header is the name of the div set to modify on roll-over. posible values:
   warfighters
   first
   maritime
state determines if we're turning the rollover on or off.  posible values:
	a (default)
	b (over)
*/
function toggleMissionLanding(y, header, state) {
	/*Sets the sprite background position on main image*/
	document.getElementById('misLandingImageCont').style.backgroundPosition = y;
	
	/*Sets the style for the brackets and text on roll-over*/
	document.getElementById(header + '1').className = "missionLandingHead1" + state;
	document.getElementById(header + '2').className = "missionLandingHead2" + state;
	document.getElementById(header + '3').className = "missionLandingHead3" + state;
	
	/*Switches the footer div on roll-over to the appropriate text by toggling style.display*/
	if (state == "a") {
		document.getElementById('misLandFt' + header).style.display = "none";
		document.getElementById('misLandFtdefault').style.display = "block";
	} else {
		document.getElementById('misLandFt' + header).style.display = "block";
		document.getElementById('misLandFtdefault').style.display = "none";
	}
}

function toggleSolution (solNum) {
	var left = 472 + (140 * (solNum - 1));
	document.getElementById('miscontentarearight1').style.display = "none";
	document.getElementById('miscontentarearight2').style.display = "none";
	document.getElementById('miscontentarearight3').style.display = "none";
	document.getElementById('misSol1').style.backgroundPosition = "0 0";
	document.getElementById('misSol2').style.backgroundPosition = "0 0";
	document.getElementById('misSol3').style.backgroundPosition = "0 0";
	
	document.getElementById('miscontentarearight' + solNum).style.display = "block";
	document.getElementById('misSolutionArrow').style.left = left + "px";
	document.getElementById('misSolutionArrow').style.display = "block";
	document.getElementById('misSol' + solNum).style.backgroundPosition = "0 -106px";
}

function toggleMissionName(page, over) {
	if (document.getElementById('misName' + over).style.display == 'block') {
		document.getElementById('misName' + over).style.display = "none";
		document.getElementById('misName' + page).style.display = "block";
	} else {
		document.getElementById('misName' + over).style.display = "block";
		document.getElementById('misName' + page).style.display = "none";
	}
}
/*End Mission Pages Functions*/

/*General usage Function to toggle div visibility*/
function toggleDivVisibility(divId) {
	var divVar = document.getElementById(divId);
	if (divVar.style.display == 'block')
		divVar.style.display ='none';
	else
		divVar.style.display = 'block';
}

function devGraphShow(liID, divID) {
	toggleDivVisibility(divID);
	var liVar = document.getElementById(liID);
	if (liVar.className == "over") liVar.className = "hidden";
	else liVar.className = "over";
}

function swapDevKit(divNum) {
	for (var i = 1; i < 7; i++) {
		document.getElementById('kitImage' + i).style.display = "none";
		document.getElementById('devKitTitle' + i).className = "hidden";
	}
	document.getElementById('kitImage' + divNum).style.display = "block";
	document.getElementById('devKitTitle' + divNum).className = "over";
}

function toggleDevPlatform(platNum) {
	var left = 150 + (156 * (platNum - 1));
	document.getElementById('plat1Text').style.display = "none";
	document.getElementById('plat2Text').style.display = "none";
	document.getElementById('plat3Text').style.display = "none";
	document.getElementById('plat4Text').style.display = "none";
	document.getElementById('plat1').style.backgroundPosition = "0 0";
	document.getElementById('plat2').style.backgroundPosition = "0 0";
	document.getElementById('plat3').style.backgroundPosition = "0 0";
	document.getElementById('plat4').style.backgroundPosition = "0 0";
	
	document.getElementById('plat' + platNum + 'Text').style.display = "block";
	document.getElementById('devPlatformArrows').style.left = left + "px";
	document.getElementById('plat' + platNum).style.backgroundPosition = "0 -144px";
}

function sectionInfoContainer(masterContentId, mainImageUri, overImageUri, extraImageId, extraImageUri, extraOverImageUri, mainBkgndImageUri, subBkgndImageUri)
{
	this.masterContentId = masterContentId;
	this.navBkgndImage = new Image();
	this.navBkgndImage.src = mainImageUri; 
	this.navBkgndImageUri = mainImageUri;
	this.navBkgndOvrImage = new Image();
	this.navBkgndOvrImage.src = overImageUri;
	this.navBkgndOvrImageUri = overImageUri;
	this.extraImageId = extraImageId;
	this.extraImage= new Image();
	this.extraImage.src = extraImageUri;
	this.extraImageUri = extraImageUri;
	this.extraImageOver= new Image();
	this.extraImageOver.src = extraOverImageUri;
	this.extraImageOverUri = extraOverImageUri;
	this.subBkgroundImage = new Image();
	this.subBkgroundImage.src = subBkgndImageUri;
	this.mainBkgroundImageUri = mainBkgndImageUri;
	this.subBkgroundImageUri = subBkgndImageUri;
}

function mouseOverShowNewContent(objId)
{
	for(count=0; count< sections.length; count++)
	{
		if(sections[count] != objId)
		{
			navId = 'nav-' + sections[count];
			document.getElementById(navId).style.background="url("+sectionInformation[sections[count]].navBkgndOvrImageUri+")";		
		}
	}

	document.getElementById(sectionInformation[objId].extraImageId).src=sectionInformation[objId].extraImageOver.src;
	document.getElementById('research-bkgnd').style.background = "url("+sectionInformation[objId].subBkgroundImageUri+")";
	document.getElementById('research-main-content').style.display="none";
	document.getElementById(objId+'-content').style.display="block";
}

function mouseOffHideNewContent(objId)
{

	for(count=0; count< sections.length; count++)
	{
		if(sections[count] != objId)
		{
			navId = 'nav-' + sections[count];
			document.getElementById(navId).style.background = "url("+sectionInformation[sections[count]].navBkgndImageUri+")";
		}
	}
	document.getElementById(sectionInformation[objId].extraImageId).src = sectionInformation[objId].extraImage.src;
	document.getElementById('research-bkgnd').style.background = "url("+sectionInformation[objId].mainBkgroundImageUri+")";
	document.getElementById(objId+'-content').style.display="none";
	document.getElementById('research-main-content').style.display="block";
}

/*video pop-up*/
function showCustomPopUp(thisUrl,thisName,theseParams)
{
	remote = open(thisUrl, thisName, theseParams);
}

function showVideoPopUp(video)
{
	remote = window.open("http://resources.irobot.com/index.php/givideoplayer/" + video, "videoWindow", "height=500,width=600,status=0,toolbar=0,menubar=0,location=1,scrollbars=0,resizable=0,directories=0");
}

function toggle2DivState(showDiv,hideDiv)
{
	alert(document.getElementById(hideDiv));
    toggleDivVisibility(hideDiv);
    toggleDivVisibility(showDiv);
}

function resCoreSwap(divID, state) {
	if(state == "over") {
		pos = "-45px";
		document.getElementById('resLandingCoreText' + divID).style.display = "block";
		document.getElementById('resLandingMainText').style.display = "none";
		document.getElementById('resLandingHeaderRight').style.backgroundImage = "url(../images/govt/research/research_top_right" + divID + ".jpg)";
	} else {
		pos = "0px";
		document.getElementById('resLandingCoreText' + divID).style.display = "none";
		document.getElementById('resLandingMainText').style.display = "block";
		document.getElementById('resLandingHeaderRight').style.backgroundImage = "url(../images/govt/research/research_top_right.jpg)";
	}
	document.getElementById('resLandingButton2').style.backgroundPosition = "0 " + pos;
	document.getElementById('resLandingButton3').style.backgroundPosition = "0 " + pos;
	document.getElementById('resLandingButton4').style.backgroundPosition = "0 " + pos;
	document.getElementById('resLandingButton5').style.backgroundPosition = "0 " + pos;
	document.getElementById('resLandingButton' + divID).style.backgroundPosition = "0 0";
}



