createClass(
	'Header.Search',
	function(options){
		var me 			= this;
		var defOptions 	= { timeout	: 2000 };
		this.options 	= $.extend(defOptions, options);
		this.options.hSectionsList.mouseout( function(ev){ me.switchToDefault(this, ev) } );
		this.options.hSectionsList.mouseover( function(ev){ me.stopSwitchToDefault(this, ev) } );
		this.options.hCurrentSection.click( function (){ me.options.hSectionsList.toggle(); return false; });
		this.options.hSearchButton.click( function(ev){ me.sendForm(this, ev); } );
		$( '.jQc_alt' ).blur( me.blurHandler ).focus( me.focusHandler );
	},
	{
		timer			: null,
		options			: null,//timeout
		switchToDefault					: function(){
			var me = this;
			if(this.timer){
				clearTimeout(this.timer);
			}
			this.timer = setTimeout(function(){return me.switchToDefault_timerCallback()}, this.options.timeout);			
		},
		switchToDefault_timerCallback	: function(){
			this.options.hSectionsList.fadeOut('fast');
		},
		stopSwitchToDefault				: function(){
			if(this.timer){
				clearTimeout(this.timer);
			}			
		},
		sendForm: 			function( sender, ev ){
			switch( this.options.params.selectedSection ){
				case 'members'	:
					$tmp = $('.jQc_alt', this.options.hFormMembers );
					if( $tmp.val() != $tmp.attr('alt') ){  
						this.options.hFormMembers.get(0).submit();
					}
					break;
				default			:
					var $tmp = $('.jQc_alt', this.options.hFormGoogle );
					if( $tmp.val() != $tmp.attr('alt') ){
						this.options.hFormGoogle.get(0).submit();
					}
			}
			return false;
		},
		selectSection: function ( sender, selectedType ){
			
			this.options.params.selectedSection = selectedType;
			this.options.hSectionsList.hide();
			$('span', this.options.hCurrentSection ).html( $(sender).html() );
			
			switch( selectedType ){
				case 'all'		:
				case 'magazine'	:
				case 'community':
					if( _shp[ selectedType ] != undefined ){
						this.options.hFormGoogle.attr('action', _shp[ selectedType ].target );
						$( 'input[@name=cx]', this.options.hFormGoogle ).val( _shp[ selectedType ].cx );
						$( 'input[@name=cof]', this.options.hFormGoogle ).val( _shp[ selectedType ].cof );
						this.options.hFormMembers.hide();
						this.options.hFormGoogle.show();
						$('.pbg', this.options.hContainer ).show();
					} 
					break;
				case 'members'	:
					this.options.hFormGoogle.hide();
					this.options.hFormMembers.show();
					$('.pbg', this.options.hContainer ).hide();
					break;
			}
			return false;
		},
		focusHandler: 		function () {
			if( $(this).val() == $(this).attr('alt') ) {
				$(this).removeClass('empty').val('');
			}
		},
		blurHandler: 		function() {
			if( $(this).val() == '' ) {
				$(this).addClass('empty').val( $(this).attr('alt') );
			}
		}
	}
);
$(function(o){
	window.headerSearch = new Header.Search({
		hContainer			: $('#topsearch'),
		hSectionsList		: $('.jQ_sh_sections'),
		hCurrentSection		: $('#jQi_sh_target'),
		hSearchButton		: $('#jQi_sh_search'),
		hFormGoogle			: $('#cse-search-box'),
		hFormMembers		: $('#member-search-box'),
		params				: _shp
	});
});
