Event.observe(window, 'load', function() {
	var geneSearchSuggestion = new GeneSearchSuggestion(
									'genomeFormName', 
									'geneSearchActionForm', 
									'genomeFormChromosomeId', 
									'genomeFormCytolocationName', 
									'featureId', 
									'genomeFormSelectType', 
									'geneSearchKeywordSuggestion', 
									'h3', 
									'Gene Search Keyword Suggestion Result', 
									'genome_list', 
									'./images/suggestionLoading.gif', 
									'./images/suggestionNext.gif', 
									'./images/suggestionPrev.gif', 
									'geneSearchKeywordSuggestion', 
									'post');
});

var GeneSearchSuggestion = Class.create();
Object.extend(GeneSearchSuggestion.prototype, Suggestion.prototype);
Object.extend(GeneSearchSuggestion.prototype, {
	// コンストラクタ (オーバーライド)
	initialize: function(inputId, formId, genomeFormChromosomeId, genomeFormCytolocationName, featureId, genomeFormSelectType, suggestionId, suggestionTitleTag, suggestionTitle, suggestionInsertionId, suggestionLoadingImg, suggestionNextImg, suggestionPreviousImg, actionName, requestMethod) {
		// ユーザー設定項目
		// キーワード推測を行うinputタグのid
		this.inputId = inputId;
		// キーワード推測を行うformタグのid
		this.formId = formId;
		// 染色体番号のinputタグのid
		this.genomeFormChromosomeId = genomeFormChromosomeId;
		// Cytolocationのinputタグのid
		this.genomeFormCytolocationName = genomeFormCytolocationName;
		// ゲノムの種類のinputタグのid
		this.featureId = featureId;
		// ゲノム検索を行うフォームの種類を判別するinputタグのid
		this.genomeFormSelectType = genomeFormSelectType;
		// 候補キーワードリストの外側を覆うid
		this.suggestionId = suggestionId;
		// 候補キーワードリストのタイトルのタグ (pタグは不可)
		this.suggestionTitleTag = suggestionTitleTag;
		// 候補キーワードリストのタイトル
		this.suggestionTitle = suggestionTitle;
		// 候補キーワードリストをDOMツリーに挿入する時のid
		this.suggestionInsertionId = suggestionInsertionId;
		// 候補キーワードリストのnow loading...画像ファイルのパス
		this.suggestionLoadingImg = suggestionLoadingImg;
		// 候補キーワードリストのnext...画像ファイルのパス
		this.suggestionNextImg = suggestionNextImg;
		// 候補キーワードリストのprevious...画像ファイルのパス
		this.suggestionPreviousImg = suggestionPreviousImg;
		// AJAXアクション名
		this.actionName = actionName;
		// リクエストを送信する方法
		this.requestMethod = requestMethod;
		
		this.processInitialize();
	},
	
	// パラメーターを作成します。 (オーバーライド)
	createParameter: function(inputString) {
		var genomeFormChromosomeId = $F(this.genomeFormChromosomeId);
		var genomeFormCytolocationName = encodeURIComponent($F(this.genomeFormCytolocationName));
		var genomeFormFeatureIds = new Array;
		var genomeFormFeatureIdoptions = $A(document.getElementsByName(this.featureId));
		genomeFormFeatureIdoptions.each(function(element){
			if (element.checked === true) {
				genomeFormFeatureIds.push(element.value);
			}
		});
		var genomeFormSelectType = $(this.genomeFormSelectType).value;
	
		var param = new String;
		param += "action=" + this.actionName;
		param += "&name=" + encodeURIComponent(inputString);
		param += "&chromosomeId=" + genomeFormChromosomeId;
		param += "&cytolocationName=" + genomeFormCytolocationName;
		genomeFormFeatureIds.each(function(element) {
			param += "&featureId=" + element;
		});
		param += "&selectType=" + genomeFormSelectType;
		
		return param;
	},
	
	// 候補キーワードリストの位置をブラウザごとに微調整を行います。 (オーバーライド)
	adjustSuggestion: function(left, top, width) {
		if (this.client.isWinOS && this.client.isIE) {
			left += 0; top -= 15; width -= 0;
			
		} else if (this.client.isWinOS && this.client.isFirefox) {
			left += 0; top -= 1; width -= 3;
			
		} else if (this.client.isWinOS && this.client.isSafari) {
			left += 1; top += 0; width -= 3;
			
		} else if (this.client.isWinOS && this.client.isOpera) {
			left += 0; top -= 1; width -= 3;
			
		} else if (this.client.isMacOS && this.client.isFirefox) {
			left += 0; top += 0; width -= 3;
			
		} else if (this.client.isMacOS && this.client.isSafari) {
			left += 1; top += 0; width -= 3;
			
		} else if (this.client.isLinuxOS && this.client.isFirefox) {
			left += 0; top += 0; width -= 3;
		}
		
		return '{left: ' + left + ', top: ' + top + ', width: '+ width +'}';
	}
});