$('html').addClass('js');

/***************************************
   =country/language search
-------------------------------------- */
$(document).ready(function() {

  var countries = {
    // COUNTRY/LANGUAGE LIST: all lines must end with a comma except the last one.
    'US - English': 'http://www.ufpi.com/',
    'US - Español': 'http://www.ufpi.com/us/es',
    'Canada - Français': 'http://www.ufpi.com/ca/fr/',
	  'UK - English': 'http://www.ufpi.com/uk/en'
    // END COUNTRY/LANGUAGE LIST
  };
  
  var $wrap = $('#wrapper').length ? $('#wrapper') : $('body');
  $wrap.prepend('<div class="countrylist"></div>');

  $.each(countries,function(country,url) {
    $('div.countrylist').append('<a href="' + url + '">' + country + '</a>');
  });

  $('#country a').click(function() {
    $('div.countrylist').slideToggle('fast');
    if (this.className == "down") {
      $(this).removeClass('down');
    } else {
      $(this).addClass('down');
    };
    this.blur();
    return false;
  });
    $('div.countrylist').hide().hover(function() {
    
  }, function() {
    $(this).slideUp('fast');
    $('#country a').removeClass('down');
  });
});

/***************************************
   =padding/margin fixes for Firefox Mac
-------------------------------------- */
$(document).ready(function() {
  var agt=navigator.userAgent.toLowerCase();
  var is_mac = (agt.indexOf("mac")!=-1);
  if (is_mac && $.browser.mozilla) {
    $('ul.primary-nav li').css('backgroundImage', '/images/2007/whitearrow.gif');
  };
});

/***************************************
   =literature reveal
-------------------------------------- */

$(document).ready(function() {
  $('#literature ul').hide();
  $('#literature > a').click(function() {
    if ( $('body').is('.product-index') ) {
      return true;
    }
    $(this).next('ul').slideToggle('fast');
    var $parent = $(this).parent('li');
    if ( $parent.is('.down') ) {
      $parent.removeClass('down');
    } else {
      $parent.addClass('down');
    };
    this.blur();
    return false;
  });
  
});

/***************************************
   =search form validation
-------------------------------------- */
$(document).ready(function() {
  $('#search').submit(function() {
    var $textField = $('#q');
    if (!$textField.val()) {
      $textField.focus();
      return false;
    };
  });
});

/***************************************
   =table striping
-------------------------------------- */

$(document).ready(function() {
  var $dataTable = $('table:not(.plain)');

  $dataTable.each(function(index) {
    var rowIndex = 0;
    var rowClass = 'even';    
    $(this).find('> tbody > tr:visible').each(function(index) {
      if ($('th', this).length) {
        rowClass = 'subhead';
        rowIndex = -1;
      } else
       if (rowIndex % 2 == 0) {
        rowClass = 'even';
      } else {
        rowClass = 'odd';
      };
      $(this).addClass(rowClass);
      rowIndex++;      
    });
  });
  
//stripe product-info boxes on top-level product pages
//stripe literature lists
  $('div.product-info:odd').add('ul.alternate > li:odd').addClass('odd');
  $('div.product-info:even').add('ul.alternate > li:even').addClass('even');  
});

/***************************************
   =product index
-------------------------------------- */

$(document).ready(function() {
// show "browse" products when hovering over category
  $('ul.product-list').css('visibility','hidden').parent().parent().hover(function() {
    $('ul', this).css('visibility','visible');
  }, function() {
    $('ul', this).css('visibility','hidden');
  });
  
// adjust odd product category margins for slightly better layout
 $('div.browse-category:odd').css('padding', '0 20px 0 10px');  
  
// quick-find GO to page
  $('#quick-find').css('display', 'block');
  $('#go').click(function() {
    var productValue = $('#quick-find select').val();
    if (productValue != "#go") {
      location.href = productValue;
    } else {
      $('div.response').css({visibility:'visible', background:'#ffc'}).html('Please choose a product before clicking GO.');
      this.blur();
      window.setTimeout("$('div.response').css('background', 'transparent')",1500);
    };
  }).hover(function() {
      $(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');      
    });
}); // end document.ready

/***************************************
   =IE6 nav dropdown function
-------------------------------------- */

$(document).ready(function() {
$('#cssdropdown li').hover(function() { $(this).addClass('over'); },  
function() {$(this).removeClass('over');});
						   });
				
$(document).ready(function() {
$('#professionals li').hover(function() { $(this).addClass('over'); },  
function() {$(this).removeClass('over');});
						   }); 

/***************************************
   =attach onclick handlers to pdf links
-------------------------------------- */

$(document).ready(function() {
  $('a[href$=.pdf]').click(function() {
    if (window.pageTracker) {
      pageTracker._trackPageview(this.pathname.replace(/^\/?/,'/'));
    }
  });
});


