/* PRELOAD ROLLOVERS */

if (document.images) {
	img1= new Image(88,18);
	img1.src= "../images/global/nav/home_learnmore_btn_over.jpg"

	img2= new Image(100,24);
	img2.src= "../images/global/nav/nav_about_over.gif";

	img3= new Image(93,24);
	img3.src= "../images/global/nav/nav_contact_over.gif";

	img4= new Image(72,24);
	img4.src= "../images/global/nav/nav_home_over.gif";

	img5 = new Image(141,24);
	img5.src= "../images/global/nav/nav_news_over.gif";

	img6 = new Image(104,24);
	img6.src= "../images/global/nav/nav_products_over.gif";

	}

/* DETECT FF WINDOWS AND ADD EXTRA CSS */

/* PUT THIS IN THE WIN FIELD BELOW AFTER TESTING */
	// ADD THE CONDITIONAL FOR IE6 -- this should fix IE6 specific files
	document.write("<!--[if lte IE 6]><link rel=\"stylesheet\" type=\"text/css\" href=\"resources/css/ie6.css\" /><![endif]-->");



if (navigator.userAgent.indexOf('Win') != -1) {


     if (navigator.appName.indexOf('Netscape') != -1) {

           // Fix for dropdowns in FF Windows only
           document.write("<style type=text\/css>#about-menu {position:absolute; top:14px; left:0px; padding-top:5px; border-top:4px solid #fff;}#resource-menu {position:absolute; top:14px; left:0px; padding-top:5px; border-top:4px solid #fff;}#news-menu {position:absolute; top:14px; left:0px; padding-top:5px; border-top:4px solid #fff;}#contact-menu {position:absolute; top:14px; left:0px; padding-top:5px; border-top:4px solid #fff;}<\/style>");

           }

     }






/* TEMP HOME PAGE INSET ROLLOVERS */

function flip (theID, theState) {

	var theID = theID;
	var theTagID = theID + "_t";;
	var theState = theState;
	var theExt = ".";

	theImg = document.getElementById(theID).src;
	theTag = document.getElementById(theTagID).src;

	if (theState == "over") {

		theImgRoll = theImg.replace(".jpg", "_over.jpg");
		theTagRoll = theTag.replace(".gif", "_over.gif");

		document.getElementById(theID).src = theImgRoll;
		document.getElementById(theTagID).src = theTagRoll;
		}


	if (theState == "out") {

		theImg = theImg.replace("_over", "");
		theTag = theTag.replace("_over", "");

		document.getElementById(theID).src = theImg;
		document.getElementById(theTagID).src = theTag;
		}


	}





/* JQUERY menu handling */

$(document).ready(function(){


	/* MAIN NAV ROLLOVERS  */
	$("#nav-buttons img.roll").hover(
		function(){
			var theImg = $(this).attr("src");
			var theExt = ".gif";
			var theRoll = theImg.replace(theExt, "_over.gif");
			$(this).attr("src", theRoll);
			},
			function(){
				var theRoll = $(this).attr("src");
				var theExt = "_over";
				var theImg = theRoll.replace(theExt, "");
				$(this).attr("src", theImg);
				});

	/* JPG ROLLOVERS */
	$("img.jpgroll").hover(
		function(){
			var theImg = $(this).attr("src");
			var theExt = ".jpg";
			var theRoll = theImg.replace(theExt, "_over.jpg");
			$(this).attr("src", theRoll);
			},
			function(){
				var theRoll = $(this).attr("src");
				var theExt = "_over";
				var theImg = theRoll.replace(theExt, "");
				$(this).attr("src", theImg);
				});


	/* ARROW ROLLOVERS */
	$("a.complink").hover(
		function(){
			var theImg = $("a.complink img.arrow").attr("src");
			var theStory = $(this).attr("id");
			var theExt = "blueon";
			var theRoll = theImg.replace(theExt, "greenon");
			$("#" + theStory + " img.arrow").attr("src", theRoll);
			},
			function(){
				var theRoll = $("a.complink img.arrow").attr("src");
				var theExt = "greenon";
				var theImg = theRoll.replace(theExt, "blueon");
				$("img.arrow").attr("src", theImg);
				});





	/* TOGGLE MENUS ON/OFF */

	// About Menu
	$("#about").hover(
	function() {
		$("#about-menu").show();
		$("#about img").attr("src", "resources/images/global/nav/nav_about_over.gif");
		},
		function() {
			$("#about-menu").hide("fast");
			$("#about img").attr("src", "resources/images/global/nav/nav_about.gif");
			}
		);

/*
	// Product Menu
	$("#product").hover(
	function() {
		$("#product-menu").show();
		$("#product img").attr("src", "resources/images/global/nav/nav_products_over.gif");
		},
		function() {
			$("#product-menu").hide("slow");
			$("#product img").attr("src", "resources/images/global/nav/nav_products.gif");
			}
		);
*/


	// Resource Center Menu
	$("#resource").hover(
	function() {
		$("#resource-menu").show();
		$("#resource img").attr("src", "resources/images/global/nav/nav_resource_center_over.gif");
		},
		function() {
			$("#resource-menu").hide("fast");
			$("#resource img").attr("src", "resources/images/global/nav/nav_resource_center.gif");
			}
		);



	// News Menu
	$("#news").hover(
	function() {
		$("#news-menu").show();
		$("#news img").attr("src", "resources/images/global/nav/nav_news_over.gif");
		},
		function() {
			$("#news-menu").hide("fast");
			$("#news img").attr("src", "resources/images/global/nav/nav_news.gif");
			}
		);




	// Contact Menu
	$("#contact").hover(
	function() {
		$("#contact-menu").show();
		$("#contact img").attr("src", "resources/images/global/nav/nav_contact_over.gif");
		},
		function() {
			$("#contact-menu").hide("fast");
			$("#contact img").attr("src", "resources/images/global/nav/nav_contact.gif");
			}
		);




	/* SUBNAV SIDEBAR ROLLOVERS */

	$("#subnav a").hover(function(){

		$(this).prepend("<img width='10' height='8' src='resources/images/global/arrows/arrow_gray.gif' class='arrow' style='margin-right:5px;' class='r' alt='selected' />");
		},
		function(){

		    var theLink = $(this).attr("href");
		    var theText = $(this).text();
			var theURL = theText;

			$(this).text(theText);
			}

		);


	/* SUBNAV SELECTED SIDEBAR ITEMS */
	// these items stay selected //

//	$("#subnav li.selected").prepend ("<img width='10' height='8' src='resources/images/global/arrows/arrow_gray.gif' class='arrow' style='margin-right:5px;' class='r' alt='selected' />");




/* HOME PAGE INSET ROLLOVERS
	$("#home_patients").hover(function(){
			$("#home_patients img").src.replace(theExt, "_over.");
			},
			function(){
				var theRoll = $(this).attr("src");
				var theExt = "_over";
				var theImg = theRoll.replace(theExt, "");
				$(this).attr("src", theImg);
				});
*/





	})



/* SHOW/HIDE VIDEO OVERLAY */
function showVideo(name) {
	var name = name;


	// ON THE CASE STUDY PAGE WE NEED TO HIDE ALL PLAYERS BEFORE LOADING A NEW ONE.
	var elementRef = document.getElementById('video');



	for (var i = 0; i < elementRef.children.length; i++) {
	    if (elementRef.children[i].tagName == "DIV") {
		   elementRef.children[i].style.display = "none";
	    }
	}


	// NOW SHOW THE VIDEO SCREEN
	document.getElementById('vidoverlay').style.display = "block";
	document.getElementById('videocont').style.display = "block";
	document.getElementById('close').style.display = "block";
	document.getElementById(name).style.display = "block";

	}

function hideVideo() {
	document.getElementById('vidoverlay').style.display = "none";
	document.getElementById('videocont').style.display = "none";
	}



/* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
/* DYNAMICALLY LOADS TEXT AND PLACES IT IN A DIV ON THE PAGE */
/* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */

function loadData(thePage, theSection, theDestination) {

	var thePage = thePage;
	var theSection = theSection;
	var theDestination = theDestination;
	var sectionPath = "";

	// DETERMINE WHERE DATA IS
	if (theSection == "feat") {
		sectionPath = "content/features-pages/";
		}

	if (theSection == "stanton") {
		sectionPath = "content/stanton/";
		}

	// CONSTRUCT THE URL
//	var url = mainPath + sectionPath + thePage + ".html";
	var url = "http://10.0.0.5/~testsite/interlace/resources/" + thePage;


	// TEST AJAX COMPATIBILITY
	var xmlHttp;
	try {   // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}

	catch (e){ // Internet Explorer
	try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e) {
	try {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (e) {
		alert("Your browser does not support AJAX!");
		return false;
		}
		}
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
		document.getElementById(theDestination).innerHTML = xmlHttp.responseText;
		}
	}

}













/* CHECK THE FORM FOR REQUIRED FIELDS */

function checkFields () {
	var organization = document.getElementById('organization').value;
	var first = document.getElementById('first').value;
	var last = document.getElementById('last').value;
	var phone = document.getElementById('telephone').value;
	var email = document.getElementById('email').value;

	var flag = true;
	var i = 0;
	var j = 0;
	var theFields = new Array();


	if (organization == "" || organization == "This field is required.") {
		var flag = false;
		theFields[i] = "organization";
		i++;
		}


	if (first == "" || first == "This field is required.") {
		var flag = false;
		theFields[i] = "first";
		i++;
		}

	if (last == "" || last == "This field is required.") {
		var flag = false;
		theFields[i] = "last";
		i++;
		}

	if (phone == "" || phone == "This field is required.") {
		var flag = false;
		theFields[i] = "telephone";
		i++;
		}

	if (email == "" || email == "This field is required.") {
		var flag = false;
		theFields[i] = "email";
		}

	if (flag == false) {
		for (j in theFields) {
			document.getElementById(theFields[j]).className = "required";
			document.getElementById(theFields[j]).value = "This field is required.";
			}
		return false;
		}

	if (flag == true) {
		var send = document.getElementById('submitform');
		send.style.display = "inline";
		send.disabled = false;
		}


	}
