/**
 * @author hooriza (ajaxUI team)
 */

(function(className) {

	SPS[className] = $Class({

		$init : function(sEl) {
			
			SPS[className]._inst = this;
			
			var oEl = $(sEl);

			var o = this._o = {
				wrap : oEl,
				form : SPS.getParentForm(oEl) || oEl.getElementsByTagName('form')[0],
				inputbox : $$('.inputbox input', oEl)[0],
				button : $$('.btnbox_l .schbtn a', oEl)[0]
			};
			
			SPS.selectbox.touchAll('select_d', oEl);
			
			$Fn(function(oEvent) {
				if (oEvent.key().keyCode ==  13)
					o.button.onclick();
			}).attach(o.inputbox, 'keydown');
			
			if (o.form) o.form.onsubmit = function() { return false; }
			
			if (o.inputbox.value.length) {
				o.inputbox.focus();
				o.inputbox.select();
			}
			
		},
		
		pop : function() {
			
			var o = this._o;
			SPS.layer.show(o.wrap);

			var self = this;
			SPS.layer.oBlind.onclick = function() { self.unpop(); };
			
			var oInput = $$('div.inputbox input', o.wrap)[0];
			oInput.focus();
			oInput.select();
			
			SPS.selectbox.touchAll(); // IE bug-_-
			
		},
		
		unpop : function() {
			
			var o = this._o;
			
			SPS.layer.hide();
			$Element(o.wrap).show();
			
			SPS.layer.oBlind.onclick = null;
			o.wrap.style.position = 'static';
			
			SPS.selectbox.touchAll(); // IE bug-_-
			
		},
		
		search : function() {
		
			var o = this._o;
			if (!SPS.validator.validate(o.wrap))
				return false;
			
			o.form.submit();
		
		}
		
	});

})('cm_search02');
