﻿///<reference path="~/scripts/jquery.intellisense.js" />
///<reference path="~/scripts/true_core.js" />

//<![CDATA[

if (!window.Legacy) {
    Type.registerNamespace("Legacy");
}

if (!window.Legacy.Search) {
    var legacy_searchPath = '';
	
// ---------------------------------------------------------------------
// Legacy.Search
// ---------------------------------------------------------------------
	Legacy.Search = function(p_el) {
	    Legacy.Search.constructBase(this, [p_el]);
	    this._button = $(".js-button", this.element);
	    this._input = $(".js-input", this.element);
	    this._button.click(Function.createDelegate(this._click, this));
	    this._input.focus(Function.createDelegate(this._textFocus, this)).blur(Function.createDelegate(this._textBlur, this));
	    this._textFocus();
	    this._textBlur();
	};

	Legacy.Search.prototype = {
	    dispose: function() {
	        this.categories = [];
	        this.currentCategory = null;
	        Legacy.Gallery.callBaseMethod(this, 'dispose');
	    },
	    _click: function(e) {
	        e.preventDefault();
	        e.stopPropagation();
	        if (e.target == this._button.get(0) && this._input.val() != '') {
	            location.href = legacy_searchPath + "search.aspx?s=" + escape(this._input.val());
	        }
	        return false;
	    },
	    handle_keydown: function(e) {
	        if (e.keyCode == 13) {
	            e.preventDefault();
	            e.stopPropagation();
	            this._button.trigger("click");
	            return false;
	        }
	    },
	    _textFocus: function(e) {
	        this._input.addClass('filled');
	        if (e) e.stopPropagation();
	    },
	    _textBlur: function(e) {
	        if (this._input.val() == '') {
	            this._input.removeClass('filled');
	        }
	        if (e) e.stopPropagation();
	    }
	}

	//True.EventDispatcher.decorate(Legacy.Search.prototype);

	Legacy.Search.register("Legacy.Search", True.Control);	
}

//]]>