function in_object(obj, value) {
	for(var i = 0; i < obj.length; i++) {
		if(obj[i] == value)
			return true;
	}
	return false;
}

function readyToSearchTag() {
	var tag = $('#inp_searchKeywords').val();
	var link = null;
	$('#footer_keywords p.f_content a').each(function(idx) {
		if($(this).text() == tag) {
			link = $(this).attr('href');
			return false;
		}
	});
	if(link != null) {
		var a = document.createElement('a');
		a.href = link;
		a.title = 'Go';
		a.id = 'goSearchKeywords';
		var img = document.createElement('img');
		img.src = 'v/img/footer_okbtn.jpg';
		img.alt = 'Go';
		img.className = 'floatRight';
		a.appendChild(img);
		$('#goSearchKeywords').remove();
		$('#footer_keywords div.ft_keywords form').append(a);
		$('#goSearchKeywords img').hover(function() {
			$(this).attr('src', 'v/img/footer_okbtn_over.jpg');
		}, function() {
			$(this).attr('src', 'v/img/footer_okbtn.jpg');
		});
	}
}

function deleteLinkKw() {
	if(typeof(document.getElementById('goSearchKeywords').alt) == 'undefined') {
		var img = document.createElement('img');
		img.id = 'goSearchKeywords';
		img.src = 'v/img/footer_okbtn_disabled.jpg';
		img.alt = 'Go';
		img.className = 'floatRight';
		$('#goSearchKeywords').remove();
		$('#footer_keywords div.ft_keywords form').append(img);
	}
}

CONTINUE_RESURSIV = false;
function checkKeyword() {
	if(in_object(availableTags, $('#inp_searchKeywords').val())) {
		CONTINUE_RECURSIV = false;
		readyToSearchTag();
	} else {
		deleteLinkKw();
	}
}

$(window).load(function() {
	$('#inp_searchKeywords').autocomplete({
			source: availableTags,
			select: function() {
				setTimeout(function() {
					readyToSearchTag();
				}, 20);
			}
	}).keypress(function() {
		setTimeout(function() {
			checkKeyword();
		}, 20);
	});
});
