
window.addEvent("domready", function() {
	
	
	if($('quicksearch_content')) {
		var quickSearchVisibility = new Object();
		
		quickSearchVisibility['displayStates'] = new Object();
		quickSearchVisibility['displayStates']['true'] = 'Close';
		quickSearchVisibility['displayStates']['false'] = 'Open';
		
		quickSearchVisibility.fx = new Fx.Slide('quicksearch_content');
		quickSearchVisibility.fx.addEvent('onComplete', function() {
			var state = quickSearchVisibility['displayStates'][quickSearchVisibility.fx.open];
			$$('.hideshow a')[0].set('html', state + ' quick search');
		});
		
		$$('.hideshow a').addEvent('click', function(clickEvent) {
			clickEvent.stop();
			quickSearchVisibility.fx.toggle();
		});
		
		
		var quickSearchForms = new Object();
		
		quickSearchForms['currentActive'] = 'hire';
		
		quickSearchForms['positions'] = new Object();
		quickSearchForms['positions']['hire'] = 0;
		quickSearchForms['positions']['sale'] = -850;
		
		quickSearchForms.fx = new Fx.Tween('search_forms', {
			'duration': 1200,
			'transition': Fx.Transitions.Sine.easeOut,
			'property': 'marginLeft',
			'link': 'cancel'
		});
	}
	
	$$('.menu .type a').addEvent('click', function(clickEvent) {
		clickEvent.stop();
		quickSearchForms.fx.start(quickSearchForms['positions'][this.get('class')]);
		
		activeAnchor = $$('.menu .' + quickSearchForms['currentActive'])[0];
		activeAnchor.getParent().removeClass('active');
		activeAnchor.getElement('img').src = activeAnchor.getElement('img').src.replace(/_.\.gif/, '_0.gif');
		
		quickSearchForms['currentActive'] = this.get('class');
		activeAnchor = $$('.menu .' + quickSearchForms['currentActive'])[0];
		activeAnchor.getParent().addClass('active');
		activeAnchor.getElement('img').src = activeAnchor.getElement('img').src.replace(/_.\.gif/, '_1.gif');
	});
	
	
	
	
	if ($$("div.desc_more").length > 0) {
		var moreDescription = new Fx.Slide($$("div.desc_more")[0]).hide();
		$$("a.desc_more").addEvents({
			"click": function(e) {
				e.stop();
				moreDescription.toggle();
			}
		});
	}
	
	
	
	$$(".navigation li a", ".quicksearch .menu li a", ".button a").each(function(item) {
		if(item.getElement("img")) {
			item.normalImg	= new Asset.image(item.getElement("img").src.replace(/_.\.gif/, "_0.gif"));
			item.hoverImg	= new Asset.image(item.getElement("img").src.replace(/_.\.gif/, "_1.gif"));
			item.getParent().addEvents({
				"mouseover": function() {
					if (!this.hasClass('active')) {
						this.addClass("hover");
						this.getElement("img").src = this.getElement("a").hoverImg.src;
					}
				},
				"mouseout": function() {
					if (!this.hasClass('active')) {
						this.removeClass("hover");
						this.getElement("img").src = this.getElement("a").normalImg.src;
					}
				}
			});
		}
	});
	
	
	$$("input.rollover").addEvents({
		"mouseover": function() { this.src = this.src.replace(/_.\.gif/, "_1.gif"); },
		"mouseout": function() { this.src = this.src.replace(/_.\.gif/, "_0.gif"); }
	});
	
	
	
	$$(".home ul").each(function(item) {
		if(item.getElement("ul")) {
			
			item.subMenu	= new Fx.Slide(item.getElement("ul"), {'duration': 200}).hide();
			item.addEvents({
				"mouseenter": function() {
					this.subMenu.cancel();
					this.subMenu.slideIn();
				},
				"mouseleave": function() {
					this.subMenu.cancel();
					this.subMenu.slideOut();
				}
			});
		}
	});
	
	
	
	
	$$("#hire_state").addEvent("change", function(changeEvent) {
		var state			= changeEvent.target[changeEvent.target.selectedIndex].value.toLowerCase().replace(/\s/g, "-");
		if(state)
			$("hire_map").src	= $("hire_map").src.replace(/_(.*)\-small\.gif/, "_" + state + "-small.gif");
		
	});
	
	
});
