
/* CONSTANTS */
var FLASH_VERSION_SUPPORTED = '9';

/*footer fix for ie6 & ie7*/
$(document).ready(function() {
	$('#footer .nav li:last-child').css({ paddingRight: '0', border: '0' });
	
	//update top nav
	var q_array = document.location.search.replace('?','').split('&');
	var category = '';
	$.each(q_array, function(i, item) {
		if(item.indexOf('category=') !== -1) {
			category = item.substring(item.indexOf('=') + 1);
		}
	});
	if (category !== '') {
		var _cla = category === 'cpsc' ? 'cpsc-letters' : category === 'msds' ? 'msds' : category === 'ingredients' ? 'product-ingredients' : '';
		$('body').addClass(_cla);		
	}
	
	
	
});

/* UTILITY VARIABLES */
var isIE = $.browser.msie;
var isIE6 = isIE && parseInt($.browser.version) === 6;
var isOpera = $.browser.opera;

/*
 * ENABLE JS and FLASH FLAGS
 */
$('html').addClass('js-enabled');
if(typeof(swfobject) !== 'undefined' && swfobject.hasFlashPlayerVersion(FLASH_VERSION_SUPPORTED)) {
	$('html').addClass('flash-enabled');
}

/*
 * ONLOAD EVENTS
 */
$(document).ready(function() {

	/* pretty checkboxes (see jquery.checkboxes.js) */
	$('#site-search input[type=radio]').prettyCheckboxes({
		checkboxWidth: 14, // The width of your custom checkbox
		checkboxHeight: 14, // The height of your custom checkbox
		display: 'inline' // The style you want it to be display (inline or list)
	});
	/* open external urls in new window */
	$('a.ext, a.external, a.doc').live('click', function() {
		window.open(this.href);
		return false;
	});

	/* open external urls in new window */
	$('a.pop').click(function() {
		window.open(this.href, 'popup', 'height=520, width=740');
		return false;
	});

	//makes customized select boxes, used throughout the site
	if(!isOpera) {
		$('.select').sSelect();
	} else {
		$('select.select').css('visibility','visible')
	}
	
	//add onchange events for selects
	$('select.autosubmit').change(function() {
		$(this).parents('form').submit();
	});

	$.get($('span.count').attr('id'), { ajax: 'true' }, function(data)
	{
		$('span.count').text(data);
	});
});

/*
 * EXPANDER
 */
$(function() {
	//hide divs with expander class
  $('div.expander > div').hide();
  $('div.expander > .expander-header').addClass('expanding_');
	//toggle first tab on and switch header class.
  $('div.expander > .expander-header').click(function() {
    $(this).next().slideToggle('fast');
    //If an expanding class is on, turn it off, if it's off turn it on.
    $(this).toggleClass('expanding_');
    $(this).toggleClass('expanded_');
  });

  //activate keyboard tabbing and keyboard 'enter/return' navigation on expander
  $('.expander-header').attr('tabindex',0).keyup(function(evt){
  	if (evt.keyCode == 13) $(this).click(); //if key = enter/return fire click, see code above
  });

});
