Nav = Class.create({
	
	inputs : [
		{id:"search_de", msg:"eingabe hier", func:"setSearch"},
		{id:"search_en", msg:"type here", func:"setSearch"},
		{id:"goto_de", msg:"seitennummer", func:"setPage"},
		{id:"goto_en", msg:"page number", func:"setPage"}
	],
	
	initialize:function()
	{
		// watch input fields
		for(var i=0; i<this.inputs.length; i++)
		{
			if($(this.inputs[i].id)) $(this.inputs[i].id).observe('click',this.onInput.bindAsEventListener(this,this.inputs[i]));
		}
		
		// catch enter key
		Event.observe(document, 'keypress', this.onEnter.bindAsEventListener(this) );
		
		// set filter action
		$('filter_de').observe('click',this.onFilter.bindAsEventListener(this));
		$('filter_en').observe('click',this.onFilter.bindAsEventListener(this));
		
		// open filter nav if filter present
		if(PARAMS.filter) this.onFilter();
	},
	
	onInput:function(event,config)
	{
		Event.stop(event);
		
		// switch element for input field
		event.target.style.display = "none";
		var input = $('input_'+config.id);
		Element.addClassName(input,"shown");
		input.value = config.msg.toUpperCase();
		input.observe('focus',this.onInputFocus.bindAsEventListener(this));
		input.observe('blur',this.onInputBlur.bindAsEventListener(this,config));
	},
	
	onInputFocus:function(event)
	{
		event.target.value = "";
	},
	
	onInputBlur:function(event,config)
	{
		Element.removeClassName(event.target,"shown");
		$(config.id).style.display = "";
	},
	
	onEnter:function(event)
	{
		if(event.keyCode != Event.KEY_RETURN) return;
		
		// do action
		for(var i=0; i<this.inputs.length; i++)
		{
			var conf = this.inputs[i];
			if (event.target.id == "input_"+conf.id) this[conf.func](event.target.value);
		}
	},
	
	onFilter : function(event)
	{
		if(event) Event.stop(event);
		
		if($('filters').style.display)
		{
			$('filters').style.display = "";
			$('filter_de').addClassName('hilited');
			$('filter_en').addClassName('hilited');
		}
		else
		{
			$('filters').style.display = "none";
			$('filter_de').removeClassName('hilited');
			$('filter_en').removeClassName('hilited');
		}
	},
	
	// ----
	
	setSearch:function(str)
	{
		str = str.replace(/\//g,"");
		window.location.href = HOST+"search-"+str;
	},
	
	setPage:function(page)
	{
		if(page.match(/[^\d]/)) return;
		page = Number(page);
		if(page>PAGE_TOTAL || page<0) return;
		
		// set page portion of url
		var url = "";
		var h = $H(PARAMS);
		h.each(function(pair){
			if(pair.key == "from") return;
			else if(pair.key == "to") return;
			url += pair.value+'/';
		},this);
		
		var from = (page-1)*PAGE_SIZE;
		var to = from + PAGE_SIZE -1;
		
		window.location.href = HOST + url + from+"-"+to;
	}
});
