function checkForShortname()
{
	if(hasShortName())
	{
		activateButton();
	}
	else
	{
		deactivateButton();
	}
}

function activateButton()
{
	$('#submitButton').addClass('active');
}

function deactivateButton()
{
	$('#submitButton').removeClass('active');
}

function hasShortName()
{
	var shortnames = 'q,google,iut,get,dl,download,winget,windl,windownload,img,gimg,gimgs,googleimg,googleimages,maps,gmap,gmaps,googlemaps,gearth,tw,twit,twitter,su,stumble,stumbleupon,ri,red,reddit,digg,y,yah,yahoo,yt,youtube,del,delicious,del.icio.us,deltag,delicioustag,del.icio.ustag,vimeo,vim,flickr,fli,wikipedia,wiki,w,imdb,amazon,amaz,bol,hyves,facebook,vandale,myspace,urbandictionary,ud,marktplaats,mp,ebay,ebaynl,speurders,thepiratebay,piratebay,tpb';

	shortnames = shortnames.split(',');
	
	var value = $('#q').val();
	
	var words	= value.split(' ');

	if(jQuery.inArray(words[0], shortnames) == -1 && jQuery.inArray(value, shortnames) == -1)
	{
		return false;
	}
	else
	{
		return true;
	}

}



$(document).ready(function() {

	initShortNameLinks();

	jQuery.each(jQuery.browser, function(i) {
	  if($.browser.mozilla){
	     $("#firefoxPlugin").show();
	  }
	});

 });


function initShortNameLinks()
{
	$('#shortnames dl dt').each(function (i) {
		$(this).bind('click', function(event) {
			useShortName(this.innerHTML);
			});
	});
	
	$('#shortnames dl dd').each(function (i) {
		$(this).bind('click', function(event) {
			useShortName($(this).prev().text());
			});
	});
}

function useShortName(shortname)
{
	var currentValue = $('#q').val();
		
	if(hasShortName())
	{		
		// replace shortname with chosen one
		var words	= currentValue.split(' ');
		
		words[0]	= shortname;
		
		$('#q').val(words.join(' '));
		
		if(words.length > 1 && words[1] != '')
		{
			// query was provided, submit form
			$('#searchForm').submit();
		}
		else
		{
			// activate button
			activateButton();

			// focus on input
			$('#q').focus();
		}

	}
	else
	{
		// prepend chosen shortname
		$('#q').val(shortname + ' ' + currentValue);
		
		if(jQuery.trim(currentValue) != '')
		{
			// query was provided, submit form
			$('#searchForm').submit();
		}
		else
		{
			// activate button
			activateButton();

			// focus on input
			$('#q').focus();
		}
	}

}
