SearchTypes = Class.create();

SearchTypes.prototype = {

    initialize: function( objConfig )
	{
		this.sFieldId		= objConfig.inputTypeId;
		this.sRelName		= objConfig.relName;
		this.currentValue	= objConfig.defValue;
		this.sContainerName = objConfig.sContainerName;
		Event.observe( document,'dom:loaded', this.init.bindAsEventListener(this) );
	},
	
	init: function()
	{
		if( !$(this.sFieldId) ){
			alert('Input field not identify');
		} else {
			this.setCathers();
		}
	},
	
	setCathers:function()
	{
		var objLinks = $(this.sContainerName).getElementsBySelector('a[rel="'+this.sRelName+'"]');
		if( objLinks )
		{
			for(var i=0;i< objLinks.length;i++ )
			{
				objLinks[i].onclick = function()
				{
					return false;
				}
				Event.observe(objLinks[i],'click',this.setValueType.bindAsEventListener(this) );
			}
		}
	},
	
	setValueType:function(objEvent)
	{
		var objLi = Event.findElement(objEvent,'li');
		if( objLi )
		{
			$(this.currentValue + '_current').hide();
			$(objLi.id + '_current').show();
			objLi.hide();
			$(this.currentValue).show();
			this.currentValue = objLi.id;
			$(this.sFieldId).value = $(this.currentValue).down('a').name;
			
			
			this.setGlobalVars($(this.currentValue).down('a').name);
		}
	},
	setGlobalVars:function(type)
	{
		if(typeof SearchTypesEngines != "undefined")
		{
			if (CurrentTypeEngine == 'live')
			{
				if (type == 'news')
				{
					$('adv_country_div').style.display = 'none';
					$('adv_lang_div').style.display = 'none';
				}
				else
				{
				    $('adv_country_div').style.display = '';
				    $('adv_lang_div').style.display = '';
				}
			}



			if ($('adv_dimensions_div') && typeof(CurrentTypeEngine) != "undefined" && CurrentTypeEngine == 'yahoo') {
				if (type == 'images') {
					$('adv_dimensions_div').style.display = '';
				}
				else
				{
					$('adv_dimensions_div').style.display = 'none';
				}

				if (type == 'news' && $('news_cat_div'))
				{
					$('news_cat_div').style.display = '';
				}
				else if ($('news_cat_div'))
				{
					$('news_cat_div').style.display = 'none';
				}
			}
			if(typeof CurrentTypeEngine != "undefined")
			{
				CurrentTypeEngine = SearchTypesEngines[type];
				if(CurrentTypeEngine == 'yahoo')
				{
					if($('s_form'))
					{
						var inputCountry = document.createElement('input');
						inputCountry.type = 'hidden';
						inputCountry.name = 'country';	
						inputCountry.id = 'yahoo_search_country';
						$('s_form').appendChild(inputCountry);
						
						var inputLanguage = document.createElement('input');
						inputLanguage.type = 'hidden';
						inputLanguage.name = 'language';	
						inputLanguage.id = 'yahoo_search_language';
						$('s_form').appendChild(inputLanguage);
						
						var inputDimension = document.createElement('input');
						inputDimension.type = 'hidden';
						inputDimension.name = 'dimension';	
						inputDimension.id = 'yahoo_search_dimension';
						$('s_form').appendChild(inputDimension);
						
						var inputDomain = document.createElement('input');
						inputDomain.type = 'hidden';
						inputDomain.name = 'domain';	
						inputDomain.id = 'yahoo_search_domain';
						$('s_form').appendChild(inputDomain);
						
					}
					
				}
				else
				{
					if($('yahoo_search_country'))
					{
						$('yahoo_search_country').remove();
					}
					if($('yahoo_search_language'))
					{
						$('yahoo_search_language').remove();
					}
					if($('yahoo_search_dimension'))
					{
						$('yahoo_search_dimension').remove();
					}
					if($('yahoo_search_domain'))
					{
						$('yahoo_search_domain').remove();
					}
				}
			}
		}
		if(typeof SearchAdvancedObj != "undefined")
		{
			SearchAdvancedObj.clearAdvancedTermsCatcher();
			SearchAdvancedObj.setAdvancedTermsCatcher();
			SearchAdvancedObj.setAdvancedFormItem($('adv_search_terms_link'));
		}
		
	}
	
}
	
