/*  ================================
     Sitewide JavaScript
    ================================ */

	// Detected and set from HTML
	var isIE6;
	isIE6 = false;

	function sitewidePageLoaded()
	{
		navInit();
		// All pages on load
	}

/*  ================================
     Template 1 JavaScript
    ================================ */

	function template1Loaded()
	{
		sitewidePageLoaded();	
	}

	function loadBanner()
	{
		var so = new SWFObject("/flash/billboard.swf", "swf_id", "847", "322", "9", "");
		so.addVariable("imageUrl1", "/solutions.aspx");
		so.addVariable("imageUrl2", "/solutions.aspx");
		so.addVariable("imageUrl3", "/solutions.aspx");
		so.addVariable("iconUrl1", "/solutions.aspx");
		so.addVariable("iconUrl2", "/solutions.aspx");
		so.addVariable("iconUrl3", "/solutions.aspx");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("billboard");
	}

	function toggleVideos()
	{
		var videoHolder = document.getElementById("motion-control-videos");
		var videoLink = document.getElementById("video-toggle");
		if(videoHolder.style.display=="block")
		{
			videoLink.innerHTML = "Watch videos";
			videoHolder.style.display = "none";
		}
		else
		{
			videoLink.innerHTML = "Hide video";
			videoHolder.style.display = "block";
		}
	}

	function loadVideos()
	{
		var so = new SWFObject("/flash/motion_control.swf", "swf_id", "680", "320", "9", "");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("motion-control-videos");
	}

//displays the first ul in the container when called in rollover script init()
function navOn(temp) {	
	//safe function to show an element with a specified id
	var x=temp.getElementsByTagName('ul');
	if(x[0]){x[0].style.display = 'block';}
	
	var y=temp.getElementsByTagName('a');
	AddClassName(y[0], "navIsOn", true)
}

//displays the first ul in the container when called in rollover script init()
function navOff(temp) {
    //safe function to hide an element with a specified id
	var x=temp.getElementsByTagName('ul');
	if(x[0]){x[0].style.display = 'none';}
	
	var y=temp.getElementsByTagName('a');
	y[0].style.backgroundColor = "";
	RemoveClassName(y[0], "navIsOn");
}

//loads the onmouseover/onmouseout actions onto all the nav elements
function navInit(){
	x = document.getElementById('menu').getElementsByTagName('li');
    for (var i=0;i<x.length;i++)
	{
	    x[i].onmouseover = function () {navOn(this);}
		x[i].onmouseout = function () {navOff(this);}
	}
}


function changeCase(x){
	$('.motion-control').css("display", "none");
	$('.process-control').css("display", "none");
	$('.error-detection').css("display", "none");
	
	$('.' + x).css("display", "block");	
}

// http://snippets.dzone.com/posts/show/2630
// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // we found it
            return true;

            }

         }

      }

   // if we got here then the class name is not there
   return false;

   }
// 
// HasClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {

         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {

            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {

               // remove array item
               arrList.splice(i, 1);

               // decrement loop counter as we have adjusted the array's contents
               i--;

               }

            }

         }

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   else
      {

      // assign modified class name attribute      
      objElement.className = strClass;
   
      }

   }
// 
// AddClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

   }
// 
// RemoveClassName
// ----------------------------------------------------------------------------


