/*
 * MomWire - Common Javascript
 *
 */

// init $momwire namespace 
var $momwire = window.$momwire || {};

//
// 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 
//
$momwire.createLink = function(cssSelector, url) {
	$(cssSelector).click(function() { 
		if ($(this).hasClass('external')) {
			window.open( url );
        	return false;
		} else {
			location.href=url;
		}
	});
}

//
// initRelExternal(): open a popup window of a certain size when rel='popupWindow' attached to it
//
$momwire.initRelPopupwindow = function() {
 	$('A[rel="popupWindow"]').click( function() {
        window.open( $(this).attr('href'), 'popup', 'width=650,height=500,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
        return false;
    });
}
 


//
// initRelExternal(): open a link in a new window if it has class='external' attached to it
//
$momwire.initRelExternal = function() {
 	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href'));
        return false;
    });
    
    // insert a tooltip span that tells you that you're leaving the site
    // class='warning' can be applied to anything other than a link
    // class='warningLink' should only be applied to <a> tags, as it is needed to keep IE6 happy
    $('.warning, a.warningLink').append("<span>You are now exiting this web site.  The Clorox Company is not responsible for the content or data collection of the website you are about to go to.</span>");
    $('.warning span').addClass('externalTooltip');	// only add externalTooltip class to the 'warning' objects (not the 'warningLink' objects)
    												// because IE6 has a hissy fit if the span inside the warningLink object has a class
}

$(window).load(function () {

 $momwire.initRelExternal();
 $momwire.initRelPopupwindow();
});
