/*
 * Clorox Common JS
 *
 * Library of commonly used functions on Clorox sites. Include jQuery, and then this file.
 * To use a given function, call it from a $(document).ready() in your own code; e.g.:
 *
 * $(document).ready( function() {
 *	$clxcommon.initExternal();
 *  $clxcommon.initWarning();
 * }
 * 
 * Details of each specific function are outlined below.
 *
 * @version 1.0
 * @requires jquery 1.3.2
 *
 */

// init the $clxcommon namespace. All functions should be part of this namespace
var $clxcommon = window.$clxcommon || {};  

/**
 * initExternal(): Open a link in a new window if it has rel='external'
 *
 */
$clxcommon.initExternal = function() {
 	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
}

/**
 * createLink(): Given a jQuery selector and a URL, add an onclick event that 
 * lets you click on a div to go to a new page 
 *
 */
$clxcommon.createLink = function(cssSelector, url) {
	$(cssSelector).click(function() { 
		if ($(this).hasClass('external')) {
			window.open( url );
        	return false;
		} else {
			location.href=url;
		}
	});
}

// initialize the functions you need on document ready. You'll want to do this in YOUR
// code; this is just an example how in this common file.
$(document).ready( function() {
	$clxcommon.initRelExternal();
});
