var CULLIGAN = {};



CULLIGAN.menu = function( menu_id )
{
   this.id = menu_id;
   this.element = YAHOO.util.Dom.get(menu_id);

   this.show = function( el )
   {
      menu = YAHOO.util.Dom.get( el );
      menu.style.display = 'block';
   }

   this.hide = function( el )
   {
      menu = YAHOO.util.Dom.get( el );
      menu.style.display = 'none';
   }

   var buttons = this.element.getElementsByTagName('LI');

   for( i=0; i<buttons.length; i++ ) {
      var link = null;
      var subnav = null;
      var next_id = 1;

      for( j=0; j<buttons[i].childNodes.length; j++ ) {
         if( link == null && buttons[i].childNodes[j].tagName == 'A' ) {
            link = buttons[i].childNodes[j];
         } else if( subnav == null && buttons[i].childNodes[j].tagName == 'UL' && YAHOO.util.Dom.hasClass( buttons[i].childNodes[j], 'sub_nav' ) ) {
            subnav = buttons[i].childNodes[j];
         }
     }

      if( link != null && subnav != null ) {
         subnav.id = this.id +'_sub_'+ next_id;
         subnav.element = this;
         subnav.onmouseover = function() { this.element.show( this ); };
         subnav.onmouseout = function() { this.element.hide( this ); };

         link.element = this;
         link.rel = subnav.id;
         link.onmouseover = function() { this.element.show( this.rel ); };
         link.onmouseout = function() { this.element.hide( this.rel ); };

         next_id++;
      }
   }
}


CULLIGAN.dealer_map = function( id, map_id, base_dir ) 
{
   this.id = id;
   this.lastLink = null;

   this.map = YAHOO.util.Dom.get(map_id);
   this.element = YAHOO.util.Dom.get(this.id);
   this.sprite = YAHOO.util.Dom.get(this.id +"_sprite");

   this.images = {
      'alberta':        base_dir +'map_alberta_over.png',
      'bc':             base_dir +'map_bc_over.png',
      'manitoba':       base_dir +'map_manitoba_over.png',
      'nb':             base_dir +'map_nb_over.png',
      'ns':             base_dir +'map_ns_over.png',
      'ontario':        base_dir +'map_ontario_over.png',
      'pei':            base_dir +'map_pei_over.png',
      'quebec':         base_dir +'map_quebec_over.png',
      'saskatchewan':   base_dir +'map_saskatchewan_over.png'
   }

   this.show = function( province ) 
   {
      this.hide();

      this.sprite.src = eval('this.images.'+ province);
      this.sprite.style.display = 'block';

      this.lastLink = this.id +"_"+ province;
      YAHOO.util.Dom.addClass( this.lastLink, 'on' );
   }

   this.hide = function()
   {
      YAHOO.util.Dom.removeClass(this.lastLink, 'on');
      this.sprite.style.display = 'none';
   }

   var links = this.element.getElementsByTagName('A');

   for( i=0; i<links.length; i++ ) {
      if( links[i].rel.length > 0 ) {
         links[i].id = this.id +"_"+ links[i].rel;
         links[i].element = this;
         links[i].onmouseover = function() { this.element.show( this.rel ); };
         links[i].onmouseout = function() { this.element.hide(); };
      }
   }

   var shapes = this.map.getElementsByTagName('AREA');

   for( i=0; i<shapes.length; i++ ) {
      shapes[i].element = this;
      shapes[i].onmouseover = function() { this.element.show( this.alt ); };
   }

   this.sprite.element = this;
   this.sprite.onmouseout = function() { this.element.hide(); };
}


CULLIGAN.displayLegal_fr = function( obj )
{  
   var pos = YAHOO.util.Dom.getXY( obj );

   var legal = YAHOO.util.Dom.get('offer_legal');
   var text = obj.getAttribute('text');

   if( legal == null ) {
      legal = document.createElement('div');
      legal.style.position = 'absolute';
      legal.style.right = '0px';
      legal.style.bottom = '0px';
      legal.style.width = '200px';
      legal.style.height = '80px';
      legal.className = 'info';
      legal.id = 'offer_legal';
      if ( text == null ) {
	 legal.innerHTML = '<p>* Sur approbation de cr&#233;dit. Certaines restrictions s\'appliquent. Certains distributeurs peuvent ne pas participer &#224; cette promotion. Communiquez avec votre distributeur pour en savoir plus.</p><p><a onclick="CULLIGAN.hideLegal()"><b>Fermer</b></a></p>';
      }
      else
      {
	 legal.innerHTML = '<p>* '+text+'</p><p><a onclick="CULLIGAN.hideLegal()"><b>Fermer</b></a></p>';
      }

      YAHOO.util.Dom.insertAfter( legal, obj );
   }

   legal.style.display = 'block';
   legal.style.left = (pos[0] - 100) +'px'
   legal.style.top = (pos[1] - 30) +'px';
}

CULLIGAN.displayLegal = function( obj )
{  
   var pos = YAHOO.util.Dom.getXY( obj );

   var legal = YAHOO.util.Dom.get('offer_legal');
   var text = obj.getAttribute('text');

   if( legal == null ) {
      legal = document.createElement('div');
      legal.style.position = 'absolute';
      legal.style.right = '0px';
      legal.style.bottom = '0px';
      legal.style.width = '200px';
      legal.style.height = '60px';
      legal.className = 'info';
      legal.id = 'offer_legal';
      if ( text == null ) {
	 legal.innerHTML = '<p>* OAC. Some restrictions apply. Dealer participation may vary. Contact your dealer for details.</p><p><a onclick="CULLIGAN.hideLegal()"><b>Close</b></a></p>';
      }
      else
      {
	 legal.innerHTML = '<p>* '+text+'</p><p><a onclick="CULLIGAN.hideLegal()"><b>Close</b></a></p>';
      }


      YAHOO.util.Dom.insertAfter( legal, obj );
   }

   legal.style.display = 'block';
   legal.style.left = (pos[0] - 100) +'px'
   legal.style.top = (pos[1] - 30) +'px';
}

CULLIGAN.hideLegal = function()
{
   var legal = YAHOO.util.Dom.get('offer_legal');

   legal.style.display = 'none';
}


CULLIGAN.trackCommercial = function( pageTracker )
{
   if( pageTracker != "undefined" ) {
      pageTracker._trackPageview('/_commercial');
   }
}
