// Get browser's name
	var ua = navigator.userAgent.toLowerCase();
	var displaySearchPlugin = false;
	if (ua.indexOf("firefox") != -1) {
		displaySearchPlugin = true;
	} else if (ua.indexOf("msie 7") != -1) {
		displaySearchPlugin = true;
	}
	var search_plugins_unsupported = 'Your browser doesn\'t support search plugins. Please try again with Firefox or Internet Explorer 7.';

		var browserName = 'your Browser';
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf("firefox") != -1) {
		browserName = 'Firefox';
	} else if (ua.indexOf("msie 7") != -1) {
		browserName = 'Internet Explorer';
	}
		
	var search_plugins_unsupported = 'Your browser doesn\'t support search plugins. Please try again with Firefox or Internet Explorer 7.';
	var button_text = 'Add dictionary search to '+browserName;
	
// Scrolldown function
	var g_ScrolledDown = false;
	function scrollDown(){
		
		if (this.startDelay == null) {
			this.startDelay = window.setTimeout('scrollDown();', 200);
		} else if (this.startDelay != null) {
			if (this.startDelay != 'done') {
				clearTimeout(this.startDelay);
				this.startDelay = 'done';
			}
			//var el = $('searchplugin');
			var el = document.getElementById('searchplugin');
			var topPos = parseInt(el.style.top);
			if (topPos < 25) {
				el.style.top = (topPos + 2) + 'px';
				this.timer = window.setTimeout('scrollDown();', 20);
			} else {
				clearTimeout(this.timer);
				g_ScrolledDown = true;
			}
		}
		
	}
	
scrollDown.timer = null;
scrollDown.startDelay = null;


// Scrollup function
function scrollUp(){
	//var el = $('searchplugin');
	var el = document.getElementById('searchplugin');
	var topPos = parseInt(el.style.top);
	if (topPos > -66) {
		el.style.top = (topPos - 2) + 'px';
		this.timer = window.setTimeout('scrollUp();', 20);
	 } else {
		if (this.timer) {
			clearTimeout(this.timer);
		}
		setCookie('hidesearchplugin', '1', 90, '/', 'spanishdict.com');
	 }
}
scrollDown.timer = null;

// Add search plugin function
function addSearchPlugin() {	
	if (window.external && ('AddSearchProvider' in window.external)) {
		// Firefox 2.0 and IE7
		var a = window.external.AddSearchProvider('http://www.spanishdict.com/toolbar_search.xml');
	} else if (window.sidebar && ('addSearchEngine' in window.sidebar)) {
		// Firefox 1.5
		window.sidebar.addSearchEngine(
		'http://www.spanishdict.com/plugin/spanishdict_dictionary_search.src',
		'http://www.spanishdict.com/images/spanishdict_logo.gif',
		'Spanishdict Dictionary Search',
		'Dictionary%20Search');
	} else {
		alert (search_plugins_unsupported);
	}
	
	if (g_ScrolledDown) {
		scrollUp();
	}

}

function display_addSearchPlugin_scrollDown() {
	if (displaySearchPlugin && getCookie('hidesearchplugin') != 1) {
		scrollDown();
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
 	}
}

addLoadEvent(display_addSearchPlugin_scrollDown);


function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

/////////////////////////////////////////////////////////////////////
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
	( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}