			 	
	jQuery(document).ready(function() {
	
	/* -- Load Scroller ------------------------------------------------- */
 		jQuery('.mapBox_list ul').jScrollPane({showArrows:true, scrollbarWidth:15, scrollbarMargin:10});		
			
	/* -- Processor Functions ------------------------------------------- */
		jQuery('.mapBox_map').html(ajaxRun({func : 'GetMap', area: jQuery('.mapBox_map').attr('id')}));
			
	/* -- Remove from list ---------------------------------------------- */
				
		jQuery('.mapBox_list ul li').live('mouseenter', function() {
			jQuery(this).addClass('selected');
			jQuery(this).prepend("<img src='/modules/RentOfficeSpace/img/remove.png' class='mapBox_list-removefromlist' />");
		});
		
		jQuery('.mapBox_list ul li').live('mouseleave', function() {
			jQuery(this).removeClass('selected');
			jQuery('.mapBox_list-removefromlist').remove();
		});
		
		jQuery('.mapBox_list-removefromlist').live('click', function() {
			jQuery(this).parent().remove();
			
			jQuery('[listname="' + jQuery(this).parent().attr('name') + '"]').removeClass('tag_remove').addClass('tag_add').text('Add');
			
			jQuery('.mapBox_list ul').jScrollPane({showArrows:true, scrollbarWidth:15, scrollbarMargin:10});
		});
									
		jQuery('.area_name').live('click', function() {
			if(	jQuery(this).attr('getmap') != '' ) {
				jQuery('.mapBox_breadcrumb ul').append('<li class="bc_bt" breadcrumb="' + jQuery(this).attr('getmap') + '"><strong>' + jQuery(this).attr('alt') + '</strong></li>');
				jQuery('.mapBox_map').html(ajaxRun({func : 'GetMap', area: jQuery(this).attr('getmap')})); 
			}
		});
		
		jQuery('[breadcrumb]').live('click', function() {
			jQuery('.mapBox_map').html(ajaxRun({func : 'GetMap', area: jQuery(this).attr('breadcrumb')}));
			jQuery(this).nextAll().remove();
		});		
		
	/* -- Add Functions ---------------------------------------- */
	
		jQuery('.tag_selector').live('click', function() {
			if( jQuery(this).hasClass('tag_add') ) {
				jQuery('.mapBox_list ul').append('<li name="'+ jQuery(this).attr('listname') +'">'+ jQuery(this).attr('listname') +'</li>');
				jQuery(this).removeClass('tag_add').addClass('tag_remove').text('Remove');
							
			} else if( jQuery(this).hasClass('tag_remove') ) {
				jQuery(".mapBox_list ul li[name^='" + jQuery(this).attr('listname') + "']").remove();
				jQuery(this).removeClass('tag_remove').addClass('tag_add').text('Add');
				
			}
				
			/* -- Load Scroller ------------------------------------------------- */
			jQuery('.mapBox_list ul').jScrollPane({showArrows:true, scrollbarWidth:15, scrollbarMargin:10});	
				
		});			
	
	/* -- Map highlight Functions ------------------------------------- */
		
		jQuery('.nz_map').maphilight({fade: true, groupBy: 'group', stroke: false, fill: true, fillColor: 'FFFFFF', fillOpacity: 0.5});		
		jQuery('.auckland_map').maphilight({fade: true, groupBy: 'group', stroke: false, fill: true, fillColor: 'FFFFFF', fillOpacity: 0.5});		
		jQuery('.westauckland_map').maphilight({fade: true, groupBy: 'group', stroke: false, fill: true, fillColor: 'FFFFFF', fillOpacity: 0.5});
		jQuery('.southauckland_map').maphilight({fade: true, groupBy: 'group', stroke: false, fill: true, fillColor: 'FFFFFF', fillOpacity: 0.5});
		jQuery('.northshore_map').maphilight({fade: true, groupBy: 'group', stroke: false, fill: true, fillColor: 'FFFFFF', fillOpacity: 0.5});
		jQuery('.CBDauckland_map').maphilight({fade: true, groupBy: 'group', stroke: false, fill: true, fillColor: 'FFFFFF', fillOpacity: 0.5});
		
		
	/* -- Emailer Functions ---------------------------------------------- */
		
	jQuery(function (jQuery) {
	var OSX = {
		container: null,
		init: function () {
			jQuery('.osx').click(function (e) {
									
				e.preventDefault();	

				jQuery('#osx-modal-content').modal({
					overlayId: 'osx-overlay',
					containerId: 'osx-container',
					closeHTML: null,
					minHeight: 80,
					opacity: 65, 
					position: ['0',],
					overlayClose: true,
					onOpen: OSX.open,
					onClose: OSX.close
				});
			});
		},
		open: function (d) {
		
		if (jQuery('.mapBox_list ul li').length) {
			jQuery('.email_list ul.areas').html(jQuery('.mapBox_list ul').html());
			}
			
			if (jQuery('.mapBox_type_left input[type=checkbox]:checked').length) {
				jQuery('.email_list ul.styles').empty();
				jQuery('.mapBox_type_left input:checked').each(function() {
    				jQuery('.email_list ul.styles').append('<li>' + jQuery(this).val() + '</li>');
 				 });
			}
			
			if (jQuery('.mapBox_type_right input[type=checkbox]:checked').length) {
				jQuery('.email_list ul.sizes').empty();
				jQuery('.mapBox_type_right input:checked').each(function() {
    				jQuery('.email_list ul.sizes').append('<li>' + jQuery(this).val() + '</li>');
 				 });
			}		
		
			var self = this;
			self.container = d.container[0];
			d.overlay.fadeIn('slow', function () {
				jQuery('#osx-modal-content', self.container).show();
				var title = jQuery('#osx-modal-title', self.container);
				title.show();
				d.container.slideDown('slow', function () {
					setTimeout(function () {
						var h = jQuery('#osx-modal-data', self.container).height()
							+ title.height()
							+ 20; // padding
						d.container.animate(
							{height: h}, 
							200,
							function () {
								jQuery('div.close', self.container).show();
								jQuery('#osx-modal-data', self.container).show();
							}
						);
					}, 300);
				});
			});
						
		},
		close: function (d) {
			
			jQuery('.email_list ul.areas').html('<li><strong>No Areas Seleted</strong></li>');
			jQuery('.email_list ul.styles').html('<li><strong>No Styles Seleted</strong></li>');
			jQuery('.email_list ul.sizes').html('<li><strong>No Sizes Seleted</strong></li>');
			
			var self = this; // this = SimpleModal object
			d.container.animate(
				{top:'-' + (d.container.height() + 20)},
				500,
				function () {
					self.close(); // or jQuery.modal.close();
				}
			);
				
		}
	};

	OSX.init();

});
	
	
	jQuery('.email_form input[type=text]').focus(function(){   
		if(jQuery(this).val() == jQuery(this).attr('defaultValue')) {
      		jQuery(this).val('');
    	}
  	});
  
  	jQuery('.email_form input[type=text]').blur(function(){
    	if(jQuery(this).val() == '') {
      		jQuery(this).val(jQuery(this).attr('defaultValue'));
    	} 
 	});
	
	
	jQuery('#send_email').click(function() {
		
		name = jQuery('#e_name').val();
		company = jQuery('#e_company').val();
		phone = jQuery('#e_phone').val();
		email = jQuery('#e_email').val();
		staff = jQuery('#e_staff').val();
		selection = '<p><strong>Areas</strong></p>' + jQuery('.email_list ul.areas').html() + '<p><strong>Styles</strong></p>' + jQuery('.email_list ul.styles').html() + '<p><strong>Sizes</strong></p>' + jQuery('.email_list ul.sizes').html();
		
		jQuery('#status').html(ajaxRun({func : 'Map_sendEmail', name: name, company: company, phone: phone, email: email, staff: staff, selection: selection}));

	});
		
		
});	
	
/// Functions ////////////////////////////////////////////////////////////

	function ajaxRun(datas){
            return jQuery.ajax({
            url: '/modules/RentOfficeSpace/functions/processor.php',      //URL or the php script
            data: datas,
            type: 'POST',
            async: false,
            cache: false,
            timeout: 30000
            }).responseText;
        }
	
	
