// Dependencies:
// - Mootools Core with Tips plugin
//   http://mootools.net

// Event handlers to emulate Safari Search field for other user agents
function startSearch()
{
	if (this.value == "Search...")
	{
		this.value = "";
	}
	this.style.color = "#333";
}

function endSearch()
{
	var trimmedValue = this.value.replace(/^\s+|\s+$/g, '');
	if ( trimmedValue == "")
	{
		this.value = "Search...";
		this.style.color = "#888";
	}
}

// INITIALIZATION FUNCTION:

window.addEvent('domready', function(){
	var isWebkit = (navigator.userAgent.indexOf('WebKit') > -1) ? 1:0;

	// alert for IE users
	// if (document.all) alert("InTwo.ca currently does not support Internet Explorer. Please visit http://getfirefox.com for a better experience.");
	
	
	// Start toolTips
	if( $('tag_cloud') )
	{
		var tips = new Tips( $('tag_cloud').getElements('a') );
	}
	
	// Safari users get to see the nice native search box
	// (provided user's navigator.userAgent property hasn't been changed to something unexpected)
	if(isWebkit)
	{
		var safariSearchEl = new Element('input', {
			'type': 'search',
			'class': 'searchbox_safari',
			'placeholder': 'Search...',
			'autosave': 'intwo_search',
			'results': '5',
			'name': 's'
		});
		var oldSearchEl = $('apple_search');
					
		var replacedEl = safariSearchEl.replaces( oldSearchEl );
	}
	// All other user agents get a pretty good replacement search box.
	else
	{
		var searchBox = $('search');
		searchBox.addEvent('focus', startSearch);
		searchBox.addEvent('click', startSearch);
		searchBox.addEvent('blur', endSearch);
	}
	
});
