/*  ================================
     Sitewide JavaScript
    ================================ */

	// Detected and set from HTML
	var isIE6;
	isIE6 = false;

	function sitewidePageLoaded()
	{
		navInit();
	}

/*  ================================
     Template 1 JavaScript
    ================================ */

	function template1Loaded()
	{
		// Per template on load
		sitewidePageLoaded();
	}
	
	var mWin
	function loadSWF(video){
	    mWin = window.open('/flash/default.aspx?video=' + video, 'VideoPlayer','width=320,height=240');
	    mWin.focus();
	}
	

	//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 section=$(temp).find("a:eq(0)").html();
		    //we determine what background color now using js
		    var  maincssobj = {
		                'background-image' : 'url(/images/menu-header-over.gif)'
		                }
		    var  cssobj = {
                        'background-color' : '#78A632'
                        
                      }
           
		    switch(section)
            {
                case "About Us": //#1C7D3A
                    cssobj = {'background-color' : '#1C7D3A'}
                     maincssobj = {'background-image' : 'url(/images/about-us-ro.gif)'}
                    break;
                case "Quiénes somos": //#1C7D3A
                    cssobj = {'background-color' : '#1C7D3A'}
                     maincssobj = {'background-image' : 'url(/images/about-us-ro.gif)'}
                    break;
                    
                case "Equipment": //#78A632
                    cssobj = {'background-color' : '#78A632' }
                    break;
                case "Equipos": //#78A632
                    cssobj = {'background-color' : '#78A632' }
                    break;
                    
                case "Parts": //#D3A92A
                     cssobj = {'background-color' : '#D3A92A'}
                      maincssobj = {'background-image' : 'url(/images/parts3-ro.gif)'}
                    break;
                case "Partes": //#D3A92A
                     cssobj = {'background-color' : '#D3A92A'}
                      maincssobj = {'background-image' : 'url(/images/parts3-ro.gif)'}
                    break;
                    
                case "Resources": //#4481B5
                     cssobj = {'background-color' : '#4481B5'}
                     maincssobj = {'background-image' : 'url(/images/resources-ro.gif)'}
                    break;
                case "Recursos": //#4481B5
                     cssobj = {'background-color' : '#4481B5'}
                     maincssobj = {'background-image' : 'url(/images/resources-ro.gif)'}
                    break;
                    
                case "Dealers": //#5A257C
                     cssobj = {'background-color' : '#5A257C'}
                     maincssobj = {'background-image' : 'url(/images/dealers-ro.gif)'}
                    break;
                case "Distribuidores": //#5A257C
                     cssobj = {'background-color' : '#5A257C'}
                     maincssobj = {'background-image' : 'url(/images/dealers-ro.gif)'}
                    break;
                    
                case "Contact Us": //#2225A7
                    cssobj = {'background-color' : '#2225A7'}
                     maincssobj = {'background-image' : 'url(/images/contact-us-ro.gif)'}
                    break;
                case "Contáctenos": //#2225A7
                    cssobj = {'background-color' : '#2225A7'}
                     maincssobj = {'background-image' : 'url(/images/contact-us-ro.gif)'}
                    break;
                default:
                    
              
            }
            $(temp).find("ul:eq(0)").css(cssobj);
              $(temp).find("a:eq(0)").css('background-image','none');
              
            $(temp).css(maincssobj);
		//}
		
		var y=temp.getElementsByTagName('a');
		AddClassName(y[0], "navIsOn", true)
		if($(temp).parent().attr("id")=='main-menu'){
		
		}
		else{
		    if($(temp).parent().length !=0){
		    
		    applyFontColor(temp,$(temp).parents('ul:eq(0)').parents("li:eq(0)").find("a:eq(0)").html());
//		         var color = $(temp).parent("ul").find("a").css('background-color');
//		         var cssfont = {'color' : color}
//		       $(temp).find("a").css(cssfont);
		      // alert($(temp).parent().get(0).css('background-color'));
		      // alert($(temp).parent().css('background-color'));
		      //alert($(temp).find("a").css('color'));
		      }
		      else{
		     // $(temp).find("a").css('color','black');
		      }
		}
	}
	
	///for whatever reason, we could get the proper color to work here.
	function applyFontColor(elem,section){
	var cssobj = {
                        'color' : 'black'
                      }
	      switch(section)
            {
                case "About Us": //#1C7D3A
                    cssobj = {'color' : '#1C7D3A'}
                    break;
                case "Equipment": //#78A632
                    cssobj = {'color' : '#78A632'}
                    break;
                case "Parts": //#D3A92A
                     cssobj = {'color' : '#D3A92A'}
                    break;
                case "Resources": //#4481B5
                     cssobj = {'color' : '#4481B5'}
                    break;
                case "Dealers": //#5A257C
                     cssobj = {'color' : '#5A257C'}
                    break;
                case "Contact Us": //#2225A7
                    cssobj = {'color' : '#2225A7'}
                    break;
                default:
                    
              
            }
           // alert(section);
            $(elem).find("a").css(cssobj);
	
	
	}
	
	
	
	//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");
	    var  maincssobj = {
		         'background-image' : 'none'
		                }
		 $(temp).css(maincssobj);
		  //if it is the top li a in the main menu we remove the placed background image
		  if($(temp).parent().attr("id")=='main-menu'){
		   $(temp).find("a:eq(0)").css('background-image','url(/images/menu-header.gif)');  
		    } else{
		 $(temp).find("a").css('color' , 'white');
		}           
	}
	
	//loads the onmouseover/onmouseout actions onto all the nav elements
	function navInit(){
		x = document.getElementById('main-menu').getElementsByTagName('li');
		for (var i=0;i<x.length;i++)
		{
			x[i].onmouseover = function () {navOn(this);}
			x[i].onmouseout = function () {navOff(this);}
		}
	}
	
	
	
	// 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
   // ----------------------------------------------------------------------------
