/*-----------------------------------------------
Title:   Global site behavior
Created: August 2008-08-28 (IVG)
Updated: 
----------------------------------------------- */

var keywordString = 'Enter Keywords';

$(document).ready(
function() 
{
	initGlobal();	
}
);


function initGlobal()  {
	setSearchBoxBehavior();
	
	if ($('#pageTools')) {
		// if this page has a hook for the page tools, initialize them  
		addPageTools();	
	}
}

// Set the default text for the search box, clear the search box on focus, and if no iput, redisplay default text on blur.
function setSearchBoxBehavior() {
	$('#searchBox').val($('#searchBox').val() == '' ? keywordString : $('#searchBox').val());
	$('#searchBox').focus(function() {$(this).val($(this).val() == keywordString ? '' : $(this).val());}).blur(function() {$(this).val($(this).val() == '' ? keywordString : $(this).val())});
}

function addPageTools() {
	$('#pageTools').show();
	
	addPrintLink();
	addBookmarkLink();
}

function addPrintLink() {
	if (window.print) {
		// if browser supports print, add the link
		
		var listItem = document.createElement('li');
		$(listItem).attr('id', 'print');
		
		var printLink = document.createElement('a');
		$(printLink).attr('href','#').html('Print').click(function() {window.print(); return false;});

		$(listItem).append(printLink);
		$('#pageTools').append(listItem);
	}
}

function addPrintLink() {
	if (window.print) {
		// if browser supports print, add the link
		
		var listItem = document.createElement('li');
		$(listItem).attr('id', 'print');
		
		var printLink = document.createElement('a');
		$(printLink).attr('href','#').html('Print').click(function() {window.print(); return false;});

		$(listItem).append(printLink);
		$('#pageTools').prepend(listItem);
	}
}

function addBookmarkLink() {
	// only add the bookmark link if the browser supports using javascript to create bookmarks.
	if (canBookmark()) {
		var listItem = document.createElement('li');
		$(listItem).attr('id', 'bookmark');
		
		var bookmarkLink = document.createElement('a');
		$(bookmarkLink).attr('href','#').html('Bookmark').click(function() {bookmark(document.title, document.location); return false;});
	
		$(listItem).append(bookmarkLink);
		$('#pageTools').append(listItem);
	}
}

function canBookmark() {
	// since the bookmark javascript logic is very browser-specific, check if we can do it for the 
	// user's browser first before enabling the link.
	return $.browser.msie;
}
function bookmark(title, url) {
	if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	} 
}