/**
* inputTip - puts helper text in an input field
*/
(function(jQuery){
jQuery.fn.inputTip = function(options) {
	var defaults = { /* no options for now */  };
	// Extend our default options with those provided.
	var opts = jQuery.extend(defaults, options);
	jQuery(this).focus(function(){
		if (jQuery(this).val() == jQuery(this).attr('title')) {
			jQuery(this).val('');
		}
	});
	jQuery(this).blur(function(){
		if (jQuery(this).val() == '') {
			jQuery(this).val(jQuery(this).attr('title'));
		}
	});
	jQuery(this).blur();
};
})(jQuery);

jQuery(document).ready(function(){
	jQuery('#ballardSearch input:text').inputTip();
	jQuery('#sidebar #searchform input:text').inputTip();
	jQuery('#newsletterForm input:text').inputTip();
	// look for a code and stash in a cookie for this session only if found
	var url = location.search;
	if (url.indexOf('?') > -1){
		var query = url.split('?').pop() + '&';
		if (query.toLowerCase().indexOf('code=') > -1){
			var pat = new RegExp("CODE\=(.*?)\&","gi");
			var code = pat.exec(query);
			if (code != null){
				jQuery.cookie("CODE", code[1], { path: '/' });
			}
		}
	}
	// add code to all ballarddesigns.com links
	var c = jQuery.cookie("CODE");
	if (c != null){
		var href = '';
		jQuery('a[href*=ballarddesigns.com/]').each(function(){
			href = jQuery(this).attr('href');
			href += ((href.indexOf('?') == -1) ? '?' : '&');
			jQuery(this).attr('href', href + 'CODE='+c);
		});
	}
	
});

