
window.addEvent('domready', function(){
   setBrowser();
   /*
   * Set the value 'block' to each ul#option
   */
   var submenu = $$('li.submenu ul');
   submenu.each(function(elem){
                elem.setStyle('display','block');
   });


   /*
   * Create the drop down efect, according the 'id' passed to parameter
   */
   dropdownMenu('autos');
   dropdownMenu('camionetas');
   dropdownMenu('suvs');
   dropdownMenu('sol_eficientes');
   dropdownMenu('herramientas');
   dropdownMenu('novedades');

   setBackgroundAutosHover();
   setBackgroundCamionetasHover();
   setBackgroundSuvsHover();
   setBackgroundSolucionesHover();
   setBackgroundHerramientasHover();
   setBackgroundNovedadesHover();

   showBBCard();

   /*
    * When the user do click over Herramientas de Compra -> Transaccion de Canje, the script show a
    * pop-up using the function 'newWin'
    */
   var transaccionCanje = $$('li#herramientas ul li a')[2];
   transaccionCanje.addEvent('click', function() {
                       newWin('http://web1.intellipriceauto.com/ETRADEINSP/IDENTIFY.ASPX?LCDEALER=3045202&SPANISH=YES&DEALERID=3045202S',765,610,'not','not','not','yes','not');
                        return false;
    });

   enterLeaveBBcard();



}); // End of domready event


/*
* When the user enter on any bbcard, the script add the class 'active' and launch the event 'mouseenter'
* to show the ul's rollover.
* Then when the user exit of the bbcard, the scrip remove the class 'active' and launch the event
* 'mouseleave' to remove the rollover of the ul.
*/
function enterLeaveBBcard(){
   var bbcard = $$('.flyout');
   bbcard.each(function(element){
       element.addEvents({
               'mouseenter':function(){
                   element.addClass('active');
                   var padre = element.getParent('li.submenu');
                   padre.getElement("ul").fireEvent('mouseenter');
                   element.setStyle('cursor','pointer');
               },
               'mouseleave':function(){
                   element.removeClass('active');
                   var padre = element.getParent('li.submenu');
                   padre.getElement("ul").fireEvent('mouseleave');
               },
               'click':function(){
                   var enlace = element.getElement('a');
                   var location = enlace.getProperty('href');
                   window.location = location;
					
               }
       }); //End addEvents
   });// end of for each
}

/*
* Show the bb-cards according the value of rel property on the tag <a>
* Ej. <a rel="aveo" href="/es/aveo/">aveo</a>
* The script found the div with id 'aveo' and set the state 'active'
*/
function showBBCard(){
   var opciones = $$('.submenu ul li');
   opciones.each(function(element){
       var links = element.getElement('a');
       var flyout = links.getProperty('rel');
       if(flyout){
           links.addEvents({
                   'mouseenter':function(){
                       var div = $(flyout);
                       if(div)
                           div.addClass('active');
                   },
                   'mouseleave':function(){
                       var div = $(flyout);
                       if(div)
                           div.removeClass('active');
                   }
           }); //End addEvents
       }
   });// end of for each
}


/*
* Generate the drop down efect on the menu's id passed to parameter
*/
function dropdownMenu(id){
   var submenu = $(id);
   var option = submenu.getElement('ul');
   var myFx = new Fx.Slide(option).hide();
   submenu.addEvents({
       'mouseenter':function(){
           myFx.cancel();
           myFx.slideIn();
       },
       'mouseleave':function(){
           myFx.cancel();
           myFx.slideOut();
       }
   }); // End of events
}

/*
* Create a new pop-up window
*/



/*
* The following functions put the correct background image to each option of the top menu
* Auto - Camionetas - SUV/Crossover - Soluciones Eficientes - Herramientas de Compra - Novedades
*
*/


/*
* Puts the background image to the top menu Autos when the user move the mouse over each options.
*/
function setBackgroundAutosHover(){
   var listAutos = $("autos");
   var option = listAutos.getElement("ul");
   option.addEvents({
               'mouseenter':function(){
                   var linkAuto = listAutos.getElement('a#menu_autos');
                   linkAuto.setStyle('background-image','url(../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_autos_on.png)');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 5){ //IE7
                       linkAuto.setStyle('width','81px');
                   }
                   if(Browser.Engine.name == 'gecko'){ //FF
                       linkAuto.setStyle('width','81px');
                   }
                   if(Browser.Engine.webkit){ //Safari
                       linkAuto.setStyle('width','84px');
                   }
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('background-image','none');
                       linkAuto.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_autos_on.png\')');
                       linkAuto.setStyle('width','81px');
					   linkAuto.setStyle('margin-left','4px');

                   }

               },
               'mouseleave':function(){
                   var linkAuto = listAutos.getElement('a#menu_autos');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('filter','none');
                   }
                   linkAuto.setProperty('style','');
                   linkAuto.removeProperty('style');
               }
     }); //End evento for li#autos
} // End function setBackgroundAutosHover


/*
* Puts the background image to the top menu Camionetas when the user move the mouse over each options.
*/

function setBackgroundCamionetasHover(){
   var listAutos = $("camionetas");
   var option = listAutos.getElement("ul");
   option.addEvents({
               'mouseenter':function(){
                   var linkAuto = listAutos.getElement('a#menu_camiones');
                   linkAuto.setStyle('background-image','url(../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_camiones_on.png)');
                   linkAuto.setStyle('width','117px');

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 5){ //IE7
                       linkAuto.setStyle('width','117px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('background-image','none');
                       linkAuto.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_camiones_on.png\')');
                       linkAuto.setStyle('width','114px');
                       linkAuto.setStyle('margin-left','21px');
                   }

               },
               'mouseleave':function(){
                   var linkAuto = listAutos.getElement('a#menu_camiones');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('filter','none');
                   }
                   linkAuto.setProperty('style','');
                   linkAuto.removeProperty('style');
               }
     }); //End evento for li#autos
} // End function setBackgroundCamionetasHover


/*
* Puts the background image to the top menu SUV/Crossover when the user move the mouse over each options.
*/

function setBackgroundSuvsHover(){
   var listAutos = $("suvs");
   var option = listAutos.getElement("ul");
   option.addEvents({
               'mouseenter':function(){
                   var linkAuto = listAutos.getElement('a#menu_suvs');
                   linkAuto.setStyle('background-image','url(../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_suvs_on.png)');
                   linkAuto.setStyle('width','150px');

                   if(Browser.Engine.webkit){ //Safari
                       linkAuto.setStyle('width','152px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 5){ //IE7
                       linkAuto.setStyle('width','150px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('background-image','none');
                       linkAuto.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_suvs_on.png\')');
                       linkAuto.setStyle('width','145px');
                       linkAuto.setStyle('margin-left','3px');
                   }

               },
               'mouseleave':function(){
                   var linkAuto = listAutos.getElement('a#menu_suvs');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('filter','none');
                   }
                   linkAuto.setProperty('style','');
                   linkAuto.removeProperty('style');
               }
     }); //End evento for li#autos
} // End function setBackgroundSuvsHover


/*
* Puts the background image to the top menu Soluciones Eficientes when the user move the mouse over each options.
*/

function setBackgroundSolucionesHover(){
   var listAutos = $("sol_eficientes");
   var option = listAutos.getElement("ul");
   option.addEvents({
               'mouseenter':function(){
                   var linkAuto = listAutos.getElement('a#menu_sol_eficientes');
                   linkAuto.setStyle('background-image','url(../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_soluciones_on.png)');
                   linkAuto.setStyle('width','177px');
				   if(Browser.Engine.webkit){ //Safari
                       linkAuto.setStyle('width','179px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 5){ //IE7
                       linkAuto.setStyle('width','177px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('background-image','none');
                       linkAuto.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_soluciones_on.png\')');
                       linkAuto.setStyle('width','172px');
                       linkAuto.setStyle('margin-left','3px');
                   }

               },
               'mouseleave':function(){
                   var linkAuto = listAutos.getElement('a#menu_sol_eficientes');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('filter','none');
                   }
                   linkAuto.setProperty('style','');
                   linkAuto.removeProperty('style');
               }
     }); //End evento for li#autos
} // End function setBackgroundSolucionesHover


/*
* Puts the background image to the top menu Herramientas when the user move the mouse over each options.
*/

function setBackgroundHerramientasHover(){
   var listAutos = $("herramientas");
   var option = listAutos.getElement("ul");
   option.addEvents({
               'mouseenter':function(){
                   var linkAuto = listAutos.getElement('a#menu_herramientas');
                   linkAuto.setStyle('background-image','url(../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_herramientas_on.png)');
                   linkAuto.setStyle('width','203px');

                   if(Browser.Engine.webkit){ //Safari
                       linkAuto.setStyle('width','203px');
                   }
				   
				   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 5){ //IE7
                       linkAuto.setStyle('width','203px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('background-image','none');
                       linkAuto.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_herramientas_on.png\')');
                       linkAuto.setStyle('margin-left','2px');
                       linkAuto.setStyle('width','200px');
                   }

               },
               'mouseleave':function(){
                   var linkAuto = listAutos.getElement('a#menu_herramientas');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('filter','none');
                   }
                   linkAuto.setProperty('style','');
                   linkAuto.removeProperty('style');
               }
     }); //End evento for li#autos
} // End function setBackgroundHerramientasHover


/*
* Puts the background image to the top menu Herramientas when the user move the mouse over each options.
*/

function setBackgroundNovedadesHover(){
   var listAutos = $("novedades");
   var option = listAutos.getElement("ul");
   option.addEvents({
               'mouseenter':function(){
                   var linkAuto = listAutos.getElement('a#menu_novedades');
                   linkAuto.setStyle('background-image','url(../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_novedadesie6_on.png)');
                   linkAuto.setStyle('width','177px');

                   if(Browser.Engine.webkit){ //Safari
                       linkAuto.setStyle('width','178px');
                   }
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 5){ //IE7
                       linkAuto.setStyle('width','177px');
                   }

                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('background-image','none');
                       linkAuto.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'crop\', src=\'../../../../en/pages/open/sitelet/es/i/pic/09/structure/menu/top_menu/btn_novedadesie6_on.png\')');
                       linkAuto.setStyle('margin-left','2px');
                       linkAuto.setStyle('width','170px');
                   }

               },
               'mouseleave':function(){
                   var linkAuto = listAutos.getElement('a#menu_novedades');
                   if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){ //IE6
                       linkAuto.setStyle('filter','none');
                   }
                   linkAuto.setProperty('style','');
                   linkAuto.removeProperty('style');
               }
     }); //End evento for li#autos
} // End function setBackgroundHerramientasHover

function setBrowser(){
    var browser = BrowserDetect.browser+BrowserDetect.version;
    var myobj = document.getElementById('gMdsPage');
    var numi = 1;
      var num = 2;
      numi.value = num;
    myobj.className=browser;
}




