var LoadMap = function(site_id, form_cat)
{
	if($('category-map-wrapper')){
		var req = new Request.HTML({ 
			method: 'get',
			data: { "site_id" : site_id, "form_cat" : form_cat },
			url: $('js-root-path').value + '/inc/category.map.php',
			update: $('category-map-wrapper')
		}).send();
	}
}


if($('form_zip')) { 
	$('form_zip').addEvent('focus', function(e) {
		if(this.value==this.defaultValue) this.value='';
	});
}
if($('sbtZip')) { 
	$('sbtZip').addEvent('click', function(e) {
		if($('form_zip').value==$('form_zip').defaultValue || $('form_zip').value==''){
			alert('Please enter your zip code');
			return false;
		}
	});
}
$$('#category_list p').each(function(el) { 
	el.addEvent('click', function(e) {
		i=0;
		$('return_bus_id').value='';
		$$('#category_list p').each(function(el2) {
			var classname = (i%2) ? 'even' : 'odd';
			el2.className = classname;
			i++;
		});
		el.className = 'on';
		LoadMap(this.getProperty('data-site-id'), this.getProperty('data-form-cat'));
	}.bind(el));	
});


var PrintMap = function(id, city_id) 
{
	var map = window.open('inc/category.list.map.php?id=' + id + '&city_id=' + city_id);
	map.onload = function() { map.print(); }
}
var PrintMapLink = function(el, id, city_id) 
{
	var print = new Element('img', {
		'id': 'btnPrint',
		'class': 'mochaPrintButton',
		'title': 'Print',
		'alt': 'Print',
		'src': '../assets/img/elements/print.gif'
	}).inject($(el + '_closeButton'), 'before');
	var link = new Element('a', {
		'id': 'lnkPrint',
		'title': 'Print',
		'alt': 'Print',
		'href': '#',
		'text': 'Print City Guide',
		'styles': {
			'position': 'absolute',
			'right': '40px',
			'width': '85px',
			'fontSize': '9px',
			'color': '#000',
			'paddingTop': '3px'
		}
	}).inject($(el + '_closeButton'), 'before');
	$('btnPrint').addEvent('click', function(e){
		new Event(e).stop();
		PrintMap(id, city_id);
	});
	$('lnkPrint').addEvent('click', function(e){
		new Event(e).stop();
		PrintMap(id, city_id);
	});
}

var MapAll = function(site_id, city_id)
{
	var site_id = (site_id) ? site_id : 0;
	var city_id = (city_id) ? city_id : 0;
	new MUI.Window({
		id: 'modalMapAll',
		title: 'View all Listings on Map',
		loadMethod: 'iframe',
		contentURL: '../inc/category.list.map.php?id=' + site_id + '&city_id=' + city_id,
		width: 640,
		height: 600,
		onContentLoaded: function(){
			PrintMapLink('modalMapAll', site_id, city_id);
		}
	});
}


var CategoryListBusItem = function()
{
	if(!$('links|bus_id|')) { 
		$$('#|bus_id| .listingurl').each(function(el) { 
			el.setProperty('onclick','return false');
			el.setProperty('href','#');
			el.style.cursor = 'default';
		});
	}

	$$('.category_list_bus_item a').each(function(el) { 
		el.addEvent('click', function(e) {
			if($('right')){
				$('right').style.display = 'none';
				$('middle').style.width = '740px';
			}
		});
	});
}

var Loading = function()
{
	var img = new Element('img', { src: '../assets/img/elements/loading3.gif', alt: 'Please wait...', title: 'Please wait...'  });
	img.setStyles({ float: 'none', marginTop: '10px', marginLeft: '325px', border: '0' });
	img.addEvent('click', function(e) {	AddBulletedList(el); });

	$('middle').set('text','');
	img.inject($('middle'));
}
