﻿var App = {
	start: function() {
		App.VietTyping.initialize();
		App.SearchOptions.initialize();
	}
};

App.VietTyping = {
	_el: null,
	
	initialize: function() {
		this._el = $E("img.vietTyping", "top-search-box");
		if ($defined(this._el)) {
			this._el.addEvent("click", this._toggleOnOff.bind(this));
			
			var on = Cookie.get("AVIM_on_off");
			if (on && on.toInt())
				this._toggleOnOff();
		}
	},
	
	_toggleOnOff: function() {
		if (this._el.hasClass("on")) {
			AVIMObj.setMethod(-1);
			
			this._el.title = "Bật bộ gõ tiếng Việt";
		}
		else {
			AVIMObj.setMethod(0);
			
			this._el.title = "Tắt bộ gõ tiếng Việt";
		}
		
		this._el.toggleClass("on");
	}
};

App.SearchOptions = {
	initialize: function() {
		if ($("top-topic-search-option").getProperty("checked"))
			this._changeToTopicSearchLayout();
		else
			this._changeToUserSearchLayout();
		
		$("top-topic-search-option").addEvent("click", this._changeToTopicSearchLayout);
		$("top-user-search-option").addEvent("click", this._changeToUserSearchLayout);
	},
	
	_changeToTopicSearchLayout: function() {
		$$("#top-search-box input.query", "#top-search-box select.category").removeClass("user");
	},
	
	_changeToUserSearchLayout: function() {
		$$("#top-search-box input.query", "#top-search-box select.category").addClass("user");
	}
};
