jQuery().ready(function(){
	
	// simple accordion for textads
	jQuery('#textads').accordion({
		header: 'div.title',
		active: false,
		alwaysOpen: false,
		animated: false,
		autoHeight: false
	});
	
	//------------- map related -------------------//
	// Allows ff/linux to have the greyed out bg	
	jQuery.blockUI.defaults.applyPlatformOpacityRules = false;

	// Get all the mlnbrs for plotting
	var hidfields = jQuery("input[name='hidmlnbr']");
	var hidmlnbrs = "";
	
	if(hidfields.size() > 0){
		hidfields.each(function(i){
			hidmlnbrs += hidfields[i].value + ",";
		});
		hidmlnbrs = hidmlnbrs.replace(/,$/, '');
	} else {
		hidmlnbrs = 'all';
	}
	
	// Create the map
	jQuery('#main_map_area').jmap('init', { 'mapType':'map', 'mapCenter': [40.275000, -76.884855], 'mapZoom': 9 });

	//Populate the map with points
	jQuery.get("/cpml/getCoordinates.jsp", 
				{mlnbrs: hidmlnbrs},
				function(response){
					coord_arr = eval(response);
					for(var i = 0; i < coord_arr.length; i++){
						jQuery('#main_map_area').jmap('AddMarker', {
							'pointLatLng': [coord_arr[i]['lat'], coord_arr[i]['lon']],
							'pointHTML': ''
							}, function(marker, options){
								    var mlnbr = coord_arr[i]['mlnbr'];
									GEvent.addListener(marker, 'click',
										function(){
											   jQuery.get("/cpml/getOneListing.jsp", {'mlnbr': mlnbr}, function(data){
											       jQuery.blockUI(
											    		   {
											    			message: data,
											    			centerY: false,
											    			centerX: false,
											    			css: { 
											    			   		top: '120px', 
											    			   		'margin-left': 'auto', 
											    			   		'margin-right': 'auto', width: '400px',
											    			   		cursor: 'default'
											    				 },
											    		    overlayCSS:{cursor: 'default'}
											    		   }
											       )
											       jQuery('.blockOverlay').attr('title','Click to go back').click(jQuery.unblockUI);
											       jQuery('#close_blockui').attr('title','Click to go back').click(jQuery.unblockUI);
											   })
									});
								})
					} // End for
				}); // End points
	
	
	//----------- Calendar widget --------------------//
	var dateFormat      = 'yy-mm-dd';
	var showOn          = 'both';
	var buttonImage     = '/cpml/jsgi/themes/cls/artwork/page/calendar.png';
	var buttonImageOnly = 'true';
	
	var options = {dateFormat:dateFormat, showOn:showOn, buttonImage:buttonImage, buttonImageOnly:buttonImageOnly};
	
	jQuery('#date_begin').datepicker(options);
	jQuery('#date_end').datepicker(options);
	
}); // End domready