
var Lancome = Lancome ? Lancome : new Object()

Lancome.Search = new Class({

	initialize: function(properties){
		
		var containerElement
		
		if(properties && properties.containerElement){
			containerElement = properties.containerElement
		}else{
			containerElement = $('search')
		}
		
		if(!containerElement){
			return
		}
		
		this.formElement = $(document).getElement('form')
		this.inputElement = containerElement.getElement('input')
		this.firstFocus = false
		
		if(properties && properties.actionURL){
			this.actionURL = properties.actionURL
		}else{
			if($chk(absolutUrl)){ // Prevent JS error on IE6
				this.actionURL = absolutUrl + '/' + webBoxRelativePath + '/../search/results.aspx?' + persistentUrl	
			}
		}
		
		this.inputElement.addEvent('focus', this.handleFocus.bind(this))
		containerElement.getElement('a').addEvent('click', this.goSearch.bind(this))
	},
	
	goSearch: function(){
		console.log('goSearch')
		
		if(this.inputElement.value != null && this.inputElement.value != '' && this.firstFocus){
			
			//location.href = absolutUrl + '/' + webBoxRelativePath + '/../search/results.aspx?search=' + this.inputElement.value + '&' + persistentUrl
			
			this.formElement.action = this.actionURL
			this.formElement.submit()
		}
	},
	
	handleFocus: function(){
		this.firstFocus = true
		this.formElement.action = this.actionURL
		this.inputElement.value = ''
	}
	
})

var searchForm
var absolutUrl
var webBoxRelativePath
var persistentUrl

window.addEvent('domready',function(){
	searchForm = new Lancome.Search()
})