var popUp = new Class({
	Implements: Options,
	options: {
		toolbar:0,
		scrollbars:1,
		statusbar:0,
		menubar:0,
		resizable:0,
		width:500,
		height:600
	},
	initialize: function(url, options) {
		this.setOptions(options);
		day = new Date();
		id = day.getTime();
		this.popUpWindow = window.open(url, id , this.flattenOptions());
	},
	flattenOptions: function() {
		var ret = 'toolbar=' + this.options.toolbar;
		ret += ',scrollbars=' + this.options.scrollbars;
		ret += ',statusbar=' + this.options.statusbar;
		ret += ',menubar=' + this.options.menubar;
		ret += ',resizeable=' + this.options.resizable;
		ret += ',width=' + this.options.width;
		ret += ',height=' + this.options.height;
		return ret;
	}
});
window.addEvent("domready", function() {
	/**
	 * listingTools setup
	 */
	$$('.listingTools').each(function(tip) {
		var content = tip.get('title').split('::');
		tip.store('tip:title', content[0]);
		tip.store('tip:text', content[1]);
	});
	new Tips('.listingTools', {
		className: 'tooltip',
		fixed: true
	});
	/**
	 * location Autocompleter
	 */
	if(Browser.Features.xhr) {
		var type = location.href.replace(/^.*type=([^&]*)&.*$/,'$1');
		type = (type==location.href)?'':type;
		var hidden = new Element('input', {
			'type':'hidden',
			'name':'type',
			'value':type
		}).inject($('qForm'),'top');
		$('q').store('prev',$('q').value);
		$('q').addEvent('keydown',function(){
			if (this.value != this.retrieve('prev'))
				hidden.set('value','text-'+this.value);
			this.store('prev',this.value);
		});
		new Autocompleter.Request.JSON($('q'), siteAddress+'q', {
			'indicatorClass': 'autocompleter-loading',
			'minLength': 2,
			'delay': 100,
			'filterSubset': true,
			onSelection: function(element, selected) {
				hidden.value = selected.getProperty('type');
			},
			onRequest: function() {
				this.update([{value:'searching..'}]);
			}
		});
	}
	/**
	 * privacy pop up
	 */
	if($('footer-privacy')) {
		$('footer-privacy').addEvent("click", function() {
			new popUp(siteAddress+'privacy');
		});
	}
	/**
	 * weather fader for non-location pages
	 */
	if($('weatherBox')) {
		var weatherBoxs = $('weatherBox').getElements('div');
		if(weatherBoxs.length) {
			weatherBoxs.setStyle('opacity', 0);
			var firstWeatherBox = weatherBoxs[0];
			firstWeatherBox.setStyle('opacity', 1);
			firstWeatherBox.setStyle('display', 'block');
			var currentWeatherBox = firstWeatherBox;
			var fadeFunction = function() {
				new Fx.Tween(currentWeatherBox, {
					property: 'opacity',
					onComplete: function() {
						currentWeatherBox.setStyle('display', 'none');
						currentWeatherBox = currentWeatherBox.getNext() ? currentWeatherBox.getNext() : firstWeatherBox ;
						currentWeatherBox.setStyle('display', 'block');
						new Fx.Tween(currentWeatherBox, {
							property: 'opacity'
						}).start(0,1);
					}
				}).start(1,0);
			}
			fadeFunction.periodical(5000);
		}
	}
});