// JavaScript Document

var map; 					//my google map object
var mgr;
var markers_pointers	 = new Array();	//my markers
var focus_marker;			// the marker currently on focus
var showingGallery = false;
var current_marker_id = 0;
var property_img_path 	= ROOT_IMAGE_URL;	//the path to the property image 
var	site_img	= ROOT_URL+'/images/';
var cooliris_script_loc = ROOT_URL+"/class.cooliris.php";
var event_listeners 	= new Array();
var event_listeners_temp_holders 	= new Array();
var fb_profile = false;
var loadedFriendsList = false;
var user_owned_markers 	= new Array();
var user_related_markers = new Array();
var user_attendance_markers = new Array();
var user_invitation_markers = new Array();
var loadedFriendsListArray = new Array();
var justAddedMarker = false;
var skip_login = false;
var markerIcons= new Array();
var labels = new Array();

var optionalShown		= false;	//when the optional fields for new entry is shown
var current_active_marker = 0;
var mapTop = 0;
var listingsParams;
var markersZIndex = 0;
var leftPanel = 'listings_holder';
var canShowAds = false;


showLoadingImage();

//the initial setup
function initialize() {
	
	jQuery("#myFilterButton").click(function() {
		jQuery("#myFilterButton").attr('class','top_search_button_active');
		currToggleCode= 12;
		eval(currActiveMode);
	});	

	jQuery('#mySearchBox').keydown(function(event) {
										
		if(event.keyCode ==13){
			jQuery("#myFilterButton").attr('class','top_search_button_active');			
			currToggleCode =12;
			eval(currActiveMode);
		}
	});
	
	jQuery(".insert_form_button").mouseover(function(){
		jQuery(this).attr('class',"insert_form_button_hover")
	});

	jQuery(".insert_form_button").mouseout(function(){
		jQuery(this).attr('class',"insert_form_button")
	});

	jQuery(".top_search_button").mouseover(function(){
		jQuery(this).attr('class',"top_search_button_hover")
	});

	jQuery(".top_search_button").mouseout(function(){
		jQuery(this).attr('class',"top_search_button")
	});



	profile_imgs_click();	
	return;	
	

  if (GBrowserIsCompatible()) {

	
	try{
		/*				
		var opts = {
		 googleBarOptions : {
		   adsOptions : {
			 client :   'partner-pub-3487012947765658', // Your Google AdSense for Search (AFS) client id
			 channel : '2486803076'
		   },
			showOnLoad:true,
			linkTarget:G_GOOGLEBAR_LINK_TARGET_BLANK, 
			resultList:G_GOOGLEBAR_RESULT_LIST_SUPPRESS,
			suppressInitialResultSelection:true,
			suppressZoomToBounds:true,
			onIdleCallback:doIdleCallback, 
			onSearchCompleteCallback:doSearchCompleteCallback, 
			onGenerateMarkerHtmlCallback:doGenerateMarkerHtmlCallback,
			onMarkersSetCallback:doMarkersSetCallback		   
		   
		   
		 }
		};*/

		adjustMapDimension();
		map = new GMap2(document.getElementById("map_canvas"));		
		
		jQuery('iframe#track').attr('src', ROOT_URL+"/track/map-loaded");
		jQuery('iframe#track').load(function() 
		{
			//alert('done');
		});	
		map_not_loaded = false;
	}
	catch(exception){
		
		jQuery('iframe#track').attr('src', ROOT_URL+"/track/map-loading-failed");		
		jQuery('iframe#track').load(function() 
		{
			var answer = confirm("Sorry, Google Map is not functioning properly at the moment. Refresh the page?");
			if(answer ){
				window.location.reload();
			}
			return;					
		});			
		return;		
		//alert(exception);

	}



    map.addControl(new GLargeMapControl());	
	//map.addControl(new MyMenuControl());
	//map.addControl(new MySearchControl());	
	//map.addControl(new MyLegendControl());		
	//map.addControl(new MyFeedBackControl());		
	//map.enableGoogleBar();
	
	

    //map.addControl(new GOverviewMapControl());	

	map.setCenter(new GLatLng(DEFAULT_LAT, DEFAULT_LNG), DEFAULT_ZOOM);
	//map.enableGoogleBar();	
	map.enableDoubleClickZoom();
	map.enableScrollWheelZoom();	
	
	/*
	var publisher_id = "ca-pub-3487012947765658";
	
	var adsManagerOptions = {
	  maxAdsOnMap : 3,
	  style: G_ADSMANAGER_STYLE_ADUNIT,
	  //style: G_ADSMANAGER_STYLE_ICON,
	  
	  // The channel field is optional - replace this field with a channel number 
	  // for Google AdSense tracking
	  channel: '4698356979'  
	};
	
	adsManager = new GAdsManager(map, publisher_id, adsManagerOptions);
	adsManager.enable();*/

	
	//myPano = new GStreetviewPanorama(document.getElementById("street_view_canvas"));				

	//document.getElementById('radiusSelect').value ='25';
    //map.setMapType(G_NORMAL_MAP);	

	jQuery('iframe#track').attr('src', ROOT_URL+"/track/loading-markers");
	
	jQuery('iframe#track').load(function() 
	{
		//alert('done');
	});		

	//intercept_login();
	
  }
  
	jQuery(window).bind('resize', function() {
		resizeTimer = setTimeout(adjustMapDimension, 0);
	});  
	
	jQuery(window).unload(function() {

		jQuery('iframe#track').attr('src', ROOT_URL+"/track/exited-things-to-do-singapore");
		
		jQuery('iframe#track').load(function() 
		{
			//alert('done');
		});		

	});	

	setMapInitialPosition();
	setPlaceHolder();


}

function showLoadingImage(){
	//document.getElementById('sidebar').innerHTML = "<div style='width:300; text-align:center; margin-top:40px;'><img src='http://thingstodosingapore.com/images/loading.gif' width='24px' height='24px' /> <div style='margin-top:10px; font-size:18px; font-weight:400'>Please wait while items load...</div></div>";
}

function inviteFriends(){
	
		/*********************************************************Invitation Box***********************************************************************************/
		var invitation_holder = document.createElement('div');

		var comments_friends_title_holder = document.createElement('div');	
		jQuery(comments_friends_title_holder ).html('Your friends on Facebook');
		jQuery(comments_friends_title_holder ).attr('class', "invitation_friends_head");		

		var invite_friends_field = document.createElement('input');
		invite_friends_field.id ="invite_friends_field";
		

		var comment_insert_box = document.createElement('textarea');
		comment_insert_box.style.width = "500px";
		comment_insert_box.style.height = "50px";		
		comment_insert_box.id = "invite msg input" ;
		jQuery(comment_insert_box).keypress(
											function(){
													 checkWordNum('invite msg input')
											}
										)

		var comments_textbox_title_holder = document.createElement('div');	
		jQuery(comments_textbox_title_holder).html('Message to your friend');
		jQuery(comments_textbox_title_holder).attr('class', "invitation_message_head");		

		var comments_textbox_holder = document.createElement('div');	
		comments_textbox_holder.appendChild(comment_insert_box);			 

		var invite_send_button = document.createElement('button');
		jQuery(invite_send_button).html("Tell Your Friends Now!");
		jQuery(invite_send_button).click(
											function(){
												var friendsToBePoked = jQuery("#inviteBoxFriendsList").val();
												comment	= document.getElementById('invite msg input').value;												
												
											   jQuery.post(
												   'index.php', 
												   { 	
														marker_id:	current_active_marker,
														comment: comment, 
														user_id: fb_profile.id ,
														friendsList : friendsToBePoked,
														cmd: 'sendInvitations'
													}, 
													function(data) {
														
													  	eval(data);
													}
												);	
												
												TB_remove();

											}
										)		
		
		var counter = document.createElement('div');		
		counter.id = "chars_left_notice";
		
		var wordholder = document.createElement('strong');				
		wordholder.id = "invite msg input-counter";
		jQuery(wordholder).html(500);
		counter.appendChild(wordholder);				
		
		invitation_holder.appendChild(comments_friends_title_holder );				
		invitation_holder.appendChild(invite_friends_field);		
		invitation_holder.appendChild(comments_textbox_title_holder);				
		invitation_holder.appendChild(comments_textbox_holder);		
		
		invitation_holder.appendChild(counter);							
		invitation_holder.appendChild(invite_send_button);			

						
			
	return invitation_holder;
	
}

/* Inserts contents into the window box on the google map*/
function contentInInfo(id, newLoc, newAdd, file_name, thingtododetail, new_tags, url_alias, reference_url, contentInInfo, imageCount, youTube, member, hasGallery, markerStats){

		var content_table = document.createElement('table');
		var content_tb = document.createElement('tbody'); 
		var content_tr = document.createElement('tr');
		content_table.appendChild(content_tb);			
		content_tb.appendChild(content_tr);
		
		var content_td1 = document.createElement('td');
		content_td1.style.verticalAlign='top';
		content_td1.style.textAlign='center';	
		content_td1.style.paddingRight='2px';			
		
		/****************************************Marker Creator Details****************************************************/
		if(typeof member !="undefined"){
		
			var marker_creator_detail_holder = document.createElement('div');
			jQuery(marker_creator_detail_holder).attr("class", "content_in_info_detail");
			jQuery(marker_creator_detail_holder).css("margin-bottom", 20);		
			jQuery(marker_creator_detail_holder).css("padding-top", 5);					
			jQuery(marker_creator_detail_holder).css("padding-bottom", 5);					
			jQuery(marker_creator_detail_holder).css("padding-right", 5);					
			jQuery(marker_creator_detail_holder).css("padding-left", 5);	
			jQuery(marker_creator_detail_holder).css("font-size", 12);									
			jQuery(marker_creator_detail_holder).css("border", "1px solid #CCCCCC ");											
			jQuery(marker_creator_detail_holder).css("background-color", "FFCCCC");														
			jQuery(marker_creator_detail_holder).css("width", 170);					
			
			var marker_creator_intro = document.createElement('div');			
			jQuery(marker_creator_intro).html("created this at ");						
			jQuery(marker_creator_intro).css("width", 100);
			jQuery(marker_creator_intro).css("text-align", "left");			
			jQuery(marker_creator_intro).css("float", "left");			
			jQuery(marker_creator_intro).css("font-size", 12);						
			jQuery(marker_creator_intro).css("color", "#21759B");				
			
			var marker_creation_date= document.createElement('div');			
			jQuery(marker_creation_date).html(member.date_created);						
			jQuery(marker_creation_date).css("width", 100);
			jQuery(marker_creation_date).css("text-align", "left");			
			jQuery(marker_creation_date).css("font-size", 12);									
			jQuery(marker_creation_date).css("float", "left");			
			jQuery(marker_creation_date).css("color", "#555555");							
			
			
			var marker_creator_img = document.createElement('img');
			jQuery(marker_creator_img).attr("src", member.profile_image);
			jQuery(marker_creator_img).attr("width", 50);			
			jQuery(marker_creator_img).attr("height", 50);						
			jQuery(marker_creator_img).css("margin", 0);			
			jQuery(marker_creator_img).css("border", 0);						
			
			var marker_creator_link = document.createElement('a');
			jQuery(marker_creator_link).css("cursor","pointer");
			jQuery(marker_creator_link).attr("href","/index_member_profile.php?user_id="+member.user_id);
			jQuery(marker_creator_link).attr("target","_blank");
			jQuery(marker_creator_link).click(function(){
				if(typeof fb_profile.id !="undefined" ){
					return true;
				}
				else
				{
					fb_logmein();
					return false;							
				}						
			})
			
			/*
			if(typeof member.user_id != 'undefined' && member.user_id.length >0){
				//jQuery(marker_creator_link).attr("href", member.profile_link);

				//jQuery(marker_creator_link).attr("target", "_blank");				
			}*/
			/*jQuery(marker_creator_link).click(function(){
				if(typeof fb_profile.id !="undefined"){
					window.location = "/index_member_profile.php?user_id="+member.user_id					
				}
				else
				{
					fb_logmein();
				}													   
			});*/
			
			jQuery(marker_creator_link).append(marker_creator_img);			
			
			var marker_creator_link_div = document.createElement('div');					
			jQuery(marker_creator_link_div).css("width", 60);
			jQuery(marker_creator_link_div).css("float", "left");			
			jQuery(marker_creator_link_div).append(marker_creator_link);						
			

			var marker_creator_name = document.createElement('div');	
			jQuery(marker_creator_name ).html(member.user_name);	

			jQuery(marker_creator_name).css("color", "#333333");	
			jQuery(marker_creator_name).css("font-weight", "bold");						
			jQuery(marker_creator_name).css("width", 100);
			jQuery(marker_creator_name).css("float", "left");				
			jQuery(marker_creator_name).css("text-align", "left");						

			var marker_creator_clearing = document.createElement('div');
			jQuery(marker_creator_clearing).css("clear", "both");			

			var marker_creator_points = document.createElement('div');
			jQuery(marker_creator_detail_holder).append(marker_creator_link_div);
			jQuery(marker_creator_detail_holder).append(marker_creator_name);			
			jQuery(marker_creator_detail_holder).append(marker_creator_intro);
			jQuery(marker_creator_detail_holder).append(marker_creation_date);			
			
			jQuery(marker_creator_detail_holder).append(marker_creator_points);		
			jQuery(marker_creator_detail_holder).append(marker_creator_clearing);											

			
			jQuery(content_td1).append(marker_creator_detail_holder);					
		
		}

		
		/***************************************Vote display******************************************/				
		var vote_table = document.createElement('div');
		jQuery(vote_table).attr('class','voting_table');
		jQuery(vote_table ).css("margin-bottom", 20);		
		jQuery(vote_table ).css("padding-top", 5);					
		jQuery(vote_table ).css("padding-bottom", 5);					
		jQuery(vote_table ).css("padding-right", 5);					
		jQuery(vote_table ).css("padding-left", 5);	
		jQuery(vote_table ).css("font-size", 12);			
		jQuery(vote_table ).css("border", "1px solid #CCCCCC ");											
		jQuery(vote_table ).css("width", 170);	


		var vote_tb = document.createElement('div'); 
		var vote_tr = document.createElement('div');
		vote_table.appendChild(vote_tb);			
		vote_tb.appendChild(vote_tr);		

		var vote_td0 	= document.createElement('div');

		jQuery(vote_td0).attr('colspan',2);
		jQuery(vote_td0).css('text-align','center');		
		vote_td0.innerHTML = 'Cast Your Vote! ';
		vote_td0.style.fontSize = '12px';
		//vote_td0.style.fontStyle = 'oblique';		
		//vote_td0.style.color = 'red';				
		//vote_td0.style.fontWeight = 'bold';
				
		vote_tr.appendChild(vote_td0);		

		/***************************************Vote for******************************************/								
		
		var vote_tr2 = document.createElement('div');
		vote_tb.appendChild(vote_tr2);				
		

		var vote_td1 	= document.createElement('div');
		var vote_td1_voters	= document.createElement('div');		
		jQuery(vote_td1_voters).attr('id','vote_td1_voters');						


		jQuery(vote_td1).attr('class','vote_holder');		
		var vote_up 	= document.createElement('img');
		vote_up.src		= site_img+'thumbsup.png';
		jQuery(vote_up).css("border", "none");				
		vote_up.style.cursor = 'pointer';
		vote_td1.appendChild(vote_up);			
		vote_tr2.appendChild(vote_td1);			

		var vote_td1count 	= document.createElement('div');		
		vote_td1.appendChild(vote_td1count);					
		jQuery(vote_td1count).attr('class','vote_countholder_for');	
		jQuery(vote_td1count).attr('id','forcount');			
		jQuery(vote_td1count).html(markerStats.voteForCount);		
		
		
	  	GEvent.addDomListener(vote_up, 'mouseover', function() {

			vote_up.src=site_img+'thumbsup_in.png';
			//jQuery(vote_up).css("border", "none");
			//document.getElementById('tool_tip').innerHTML = "Vote <b>FOR</b> this thing to do!";
			//move_toggle_box('tool_tip');
	  	});
		
	  	GEvent.addDomListener(vote_up, 'mouseout', function() {
			vote_up.src=site_img+'thumbsup.png';
			//fix_toggle_box();		
			//toggle_insert_box('tool_tip')	
	  	});		
		
	  	GEvent.addDomListener(vote_up, 'click', function() {
			//xajax_castVote(id ,1 , newLoc);
			
			if(typeof fb_profile.id != 'undefined'){
				
				
				jQuery('#forcount').fadeOut('slow', function(){
					var count = jQuery('#forcount').html();
					count = parseInt(count);
					jQuery('#forcount').html(count+1);
					jQuery('#forcount').fadeIn('slow', function(){
						
					});
				});		
				
				
				var curr_vote = document.createElement('div');								
				jQuery(curr_vote).attr('align','center');							
				var friend_headshot = document.createElement('img');					
				jQuery(friend_headshot  ).css("margin-left", 0);		
				jQuery(friend_headshot  ).css("margin-right", 4);		
				jQuery(friend_headshot  ).css("margin-bottom", 4);							
				jQuery(friend_headshot  ).css("float", "left");						
				jQuery(friend_headshot  ).attr("id","friend_headshot"+fb_profile.id);
				jQuery(friend_headshot  ).css("border", '1px solid #ff0000');													
				
				jQuery(friend_headshot).attr('src', "http://graph.facebook.com/"+fb_profile.id+"/picture");			
				jQuery(friend_headshot).attr('alt', fb_profile.name);		
				jQuery(friend_headshot).attr('member_id', fb_profile.id);							
				var friendLink = document.createElement('a');	
				jQuery(friendLink ).attr("id",fb_profile.name+"_link");										
				jQuery(friendLink ).attr("title",fb_profile.name);										
				jQuery(friendLink ).css("cursor","pointer");					
				
				var curr_user_id = fb_profile.id;
				jQuery(friend_headshot).bind('click',function(){																							  
						window.location = "http://facebook.com";
				});
				jQuery(friend_headshot).css('height','50');					
				jQuery(friend_headshot).css('width','50');										
				jQuery(friend_headshot).css('margin-top','3');
				
				friendLink.appendChild(friend_headshot);	
				curr_vote.appendChild(friendLink);						

				jQuery("#vote_td1_voters").prepend(curr_vote);						
	
				
				jQuery.post("index.php",
							{
								id : id ,
								for_against : 1,
								name : newLoc,
								user_id : fb_profile.id,
								cmd : 'castVote'
							},
							function(data){
								eval(data);
							}
				);
			}
			else{
				fb_logmein();
			}
			
	  	});		

		jQuery(vote_td1).append(vote_td1_voters	);
		
		/***************************************Vote against******************************************/						
		var vote_td2 	= document.createElement('div');
		var vote_td2_voters	= document.createElement('div');		
		jQuery(vote_td2_voters).attr('id','vote_td2_voters');						

		jQuery(vote_td2).attr('class','vote_holder');	

	
		vote_tr2.appendChild(vote_td2);					
		
		var vote_down 	= document.createElement('img');	
		vote_td2.appendChild(vote_down);	
					
		vote_down.src		= site_img+'thumbsdown.png';
		jQuery(vote_down).css("border", "none");		
		vote_down.style.cursor = 'pointer';		
		vote_td2.appendChild(vote_down);

		var vote_td2count 	= document.createElement('div');		
		vote_td2.appendChild(vote_td2count);					
		jQuery(vote_td2count).attr('class','vote_countholder_against');			
		jQuery(vote_td2count).attr('id','againstcount');					
		jQuery(vote_td2count).html(markerStats.voteAgainstCount);				

		
	  	GEvent.addDomListener(vote_down, 'mouseover', function() {
															
			vote_down.src=site_img+'thumbsdown_in.png';
			//document.getElementById('tool_tip').innerHTML = "Vote <b>AGAINST</b> this thing to do!";
			//move_toggle_box('tool_tip');
	  	});
		
	  	GEvent.addDomListener(vote_down, 'mouseout', function() {
			vote_down.src=site_img+'thumbsdown.png';
			//fix_toggle_box();		
			//toggle_insert_box('tool_tip')	
	  	});			
		
	  	GEvent.addDomListener(vote_down, 'click', function() {
		
			
			//xajax_castVote(id ,0 , newLoc);
			if(typeof fb_profile.id != 'undefined'){
				
				
				jQuery('#againstcount').fadeOut('slow', function(){
					var count = jQuery('#againstcount').html();
					count = parseInt(count);					
					jQuery('#againstcount').html(count+1);
					jQuery('#againstcount').fadeIn('slow', function(){
						
					});
				});
				
				var curr_vote = document.createElement('div');								
				jQuery(curr_vote).attr('align','center');							
				var friend_headshot = document.createElement('img');					
				jQuery(friend_headshot  ).css("margin-left", 0);		
				jQuery(friend_headshot  ).css("margin-right", 4);		
				jQuery(friend_headshot  ).css("margin-bottom", 4);							
				jQuery(friend_headshot  ).css("float", "left");						
				jQuery(friend_headshot  ).attr("id","friend_headshot"+fb_profile.id);
				jQuery(friend_headshot  ).css("border", '1px solid #ff0000');													
				
				jQuery(friend_headshot).attr('src', "http://graph.facebook.com/"+fb_profile.id+"/picture");			
				jQuery(friend_headshot).attr('alt', fb_profile.name);		
				jQuery(friend_headshot).attr('member_id', fb_profile.id);	
				
				var friendLink = document.createElement('a');	
				jQuery(friendLink ).attr("id",fb_profile.name+"_link");										
				jQuery(friendLink ).attr("title",fb_profile.name);										
				jQuery(friendLink ).css("cursor","pointer");					
				
				var curr_user_id = fb_profile.id;
				jQuery(friend_headshot).bind('click',function(){																							  
						window.location = "http://facebook.com";
				});
				jQuery(friend_headshot).css('height','50');					
				jQuery(friend_headshot).css('width','50');										
				jQuery(friend_headshot).css('margin-top','3');
				
				friendLink.appendChild(friend_headshot);	
				curr_vote.appendChild(friendLink);						

				jQuery("#vote_td2_voters").prepend(curr_vote);						
				jQuery.post("index.php",
							{
								id : id ,
								for_against : 0,
								name : newLoc,
								user_id : fb_profile.id,							
								cmd : 'castVote'							
							},
							function(data){
								eval(data);
							}
				);
			}
			else{
				fb_logmein();				
			}

			
	  	});				

		jQuery(vote_td2).append(vote_td2_voters	);
		var vote_td3 = document.createElement('div');
		jQuery(vote_td3 ).css('clear', 'both');
		vote_tr2.appendChild(vote_td3);				
		
		/*************************************Vote Results going***************************************************/

		if(typeof member.votes != 'undefined' && member.votes.length >0 && typeof member.votes[0].user_id !="undefined" && member.votes[0].user_id.length ){

			var voters_holder = document.createElement('div');								
			jQuery(voters_holder).css('margin-top',"10px");
			for(x = 0 ; x < member.votes.length; x++){
				if(typeof member.votes[x].user_id !="undefined" && member.votes[x].user_id.length > 0){

					var curr_vote = document.createElement('div');								
					jQuery(curr_vote).attr('align','center');							
					var friend_headshot = document.createElement('img');					
					jQuery(friend_headshot  ).css("margin-left", 0);		
					jQuery(friend_headshot  ).css("margin-right", 4);		
					jQuery(friend_headshot  ).css("margin-bottom", 4);							
					jQuery(friend_headshot  ).css("float", "left");						
					jQuery(friend_headshot  ).attr("id","friend_headshot"+member.votes[x].user_id);
					if(member.votes[x].is_friend){
						jQuery(friend_headshot  ).css("border", '1px solid #ff0000');													
					}
					else{
						jQuery(friend_headshot  ).css("border", '1px solid #ffffff');													
					}
					
					jQuery(friend_headshot).attr('src', "http://graph.facebook.com/"+member.votes[x].user_id+"/picture");			
					jQuery(friend_headshot).attr('alt', member.votes[x].user_name);		
					jQuery(friend_headshot).attr('member_id', member.votes[x].user_id);							
					var friendLink = document.createElement('a');	
					jQuery(friendLink ).attr("id",member.votes[x].user_name+"_link");										
					jQuery(friendLink ).attr("title",member.votes[x].user_name);										
					jQuery(friendLink ).css("cursor","pointer");					
					
					var curr_user_id = member.votes[x].user_id;
					jQuery(friend_headshot).bind('click',function(){																							  

						if(typeof fb_profile.id !="undefined" ){
							
							window.location = "/index_member_profile.php?user_id="+jQuery(this).attr('member_id');
						}
						else
						{
							fb_logmein();
							return false;							
						}
					});
					jQuery(friend_headshot).css('height','50');					
					jQuery(friend_headshot).css('width','50');										
					jQuery(friend_headshot).css('margin-top','3');
					
					friendLink.appendChild(friend_headshot);	
					curr_vote.appendChild(friendLink);						

					//var voteImage = document.createElement('img');
					if(member.votes[x].vote){
						jQuery(vote_td1_voters).append(curr_vote);						

					}
					else{
						jQuery(vote_td2_voters).append(curr_vote);						
					}

					/*
					jQuery(voteImage).css('border','none');
					jQuery(voteImage).css('height','20');					
					jQuery(voteImage).css('width','20');					

					curr_vote.appendChild(friendLink );	
					curr_vote.appendChild(voteImage );						
					
					var vote_td3 = document.createElement('div');
					jQuery(vote_td3 ).css('clear', 'both');
					curr_vote.appendChild(vote_td3);		
					
					voters_holder.appendChild(curr_vote );						
					*/

				}
			}
				
			vote_tr2.appendChild(voters_holder);		

		}


		
		
		var vote_td3 = document.createElement('div');
		jQuery(vote_td3 ).css('clear', 'both');
		vote_tr2.appendChild(vote_td3);		
		
		content_td1.appendChild(vote_table);


		/***************************************picture file display******************************************/
		if(file_name.length > 0){
			
			var gallery_detail_holder = document.createElement('div');
			jQuery(gallery_detail_holder ).attr("class", "content_in_info_detail");
			jQuery(gallery_detail_holder ).css("margin-bottom", 20);		
			jQuery(gallery_detail_holder ).css("padding-top", 5);					
			jQuery(gallery_detail_holder ).css("padding-bottom", 5);					
			jQuery(gallery_detail_holder ).css("padding-right", 5);					
			jQuery(gallery_detail_holder ).css("padding-left", 5);	
			jQuery(gallery_detail_holder ).css("font-size", 12);			
			jQuery(gallery_detail_holder ).css("border", "1px solid #CCCCCC ");											
			jQuery(gallery_detail_holder ).css("width", 170);						
			
			
			var gallery_header= document.createElement('div');
			jQuery(gallery_header).html("photo gallery");
			jQuery(gallery_header).css('margin-bottom',5);			
			
			gallery_detail_holder.appendChild(gallery_header);					
			



			if(	(typeof member.user_id !="undefined" &&  member.user_id == fb_profile.id) || fb_profile.id == '590788071' || fb_profile.id == '100000083895611' ){

				var gallery_header_edit= document.createElement('a');

				jQuery(gallery_header_edit).html(' (edit)');
				jQuery(gallery_header_edit).css('font-weight','bold');								

				
				jQuery(gallery_header).append(gallery_header_edit);


				
				jQuery(gallery_header_edit).click(function(){
																								
									window.open(
													"/addmorephotos.php?marker_id="+id,
													'Edit Photos in Gallery',
													'width=1024,height=600,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no'
												) ;
									return false;														   
								});


			}

			
			var content_img = document.createElement('img');
			
			if(	typeof member.fb_event_id  !="undefined" &&  member.fb_event_id && member.fb_event_id !='false'){
				content_img.src= "https://graph.facebook.com/"+member.fb_event_id +"/picture?type=large";
			}
			else{
				content_img.src= property_img_path+file_name;			
			}



			
			
			content_img.style.border = "none";
			content_img.alt="Image for Things to do "+COUNTRY_NAME 
			
			GEvent.addDomListener(content_img, 'mouseover', function() {
				content_img.style.cursor = "pointer";
			});			
			GEvent.addDomListener(content_img, 'mouseout', function() {
				content_img.style.cursor = "arrow";
			});						


			//alert(content_img.width);
			//alert(content_img.height);		
			if(content_img.width !=0){		
				content_img.height =content_img.height / content_img.width * 170;
				content_img.width = 170;
			}
			else{
				content_img.width = 170;			
			}
			
			jQuery(content_img).css("margin", 0);				

			if(hasGallery){
				/*Gary 8th May 2010*/

				var thick_box_a = document.createElement('a');			
				thick_box_a.className = "thickbox";
				thick_box_a.href= property_img_path+file_name;
				thick_box_a.rel=file_name;
				thick_box_a.appendChild(content_img);					

				gallery_detail_holder.appendChild(thick_box_a);		
				jQuery(thick_box_a).click(function(event) {
					if(typeof fb_profile.id == 'undefined'){
						fb_logmein();
						return false;
					}				
																 
					if(event.preventDefault) event.preventDefault();
					this.blur();				
	
					// get caption: either title or name attribute
					var caption = this.title || this.name || newLoc;
					// get rel attribute for image groups
					//var group = this.rel || false;				
	
					jQuery.post("index.php",
									{
										marker_id : id,
										cmd: 'showMarkerGallery'
									},
									function(data){
										jQuery("#TB_window").remove();
										jQuery("body").append("<div id='TB_window'></div>");
										showingGallery = true;
										
										eval(data);
										//tb_show(caption, this.href, group);				
									}
										
								)
	
					
					return false;
				});		
			}
			else{
				/*Gary 12th Nov 2010*/

				gallery_detail_holder.appendChild(content_img);		
				jQuery(thick_box_a).click(function(event) {
												   
					if(typeof fb_profile.id == 'undefined'){
						fb_logmein();
						return false;
					}												   

																 
					if(event.preventDefault) event.preventDefault();
					this.blur();				
	
					// get caption: either title or name attribute
					var caption = this.title || this.name || newLoc;
					// get rel attribute for image groups
					//var group = this.rel || false;				
	
					jQuery.post("index.php",
									{
										marker_id : id,
										cmd: 'showMarkerGallery'
									},
									function(data){
										jQuery("#TB_window").remove();
										jQuery("body").append("<div id='TB_window'></div>");
										showingGallery = true;
										
										eval(data);
										//tb_show(caption, this.href, group);				
									}
										
								)
	
					
					return false;
				});						
			}
			
			var imageCounter = document.createElement('div');			
			imageCounter.style.marginTop ='5px';	
			imageCounter.style.marginBottom='10px';				
			imageCounter.innerHTML = imageCount;
			gallery_detail_holder.appendChild(imageCounter);					
			content_td1.appendChild(gallery_detail_holder);								
			
						
			
			
		}
		
		content_tr.appendChild(content_td1);				

		var breakln1 = document.createElement('br');
		var breakln2 = document.createElement('br');			
		
		
		
		
		/*************************************Friends going***************************************************/

		if(typeof member.friends_going != 'undefined' && member.friends_going.length >0 && typeof member.friends_going[0].user_id !="undefined" && member.friends_going[0].user_id.length ){

			var friends_holder = document.createElement('div');
			jQuery(friends_holder ).attr("class", "content_in_info_detail");
			jQuery(friends_holder ).css("margin-bottom", 20);		
			jQuery(friends_holder ).css("padding-top", 5);					
			jQuery(friends_holder ).css("padding-bottom", 5);					
			jQuery(friends_holder ).css("padding-right", 0);					
			jQuery(friends_holder ).css("padding-left", 0);	
			jQuery(friends_holder ).css("font-size", 12);			
			jQuery(friends_holder ).css("border", "1px solid #CCCCCC ");											
			jQuery(friends_holder ).css("width", 180);						


			var gallery_header1= document.createElement('div');
			jQuery(gallery_header1).html(member.total_attending+" attending");
			jQuery(gallery_header1).css('font-weight','bold');								
			jQuery(gallery_header1).css('margin-bottom',5);					
			friends_holder.appendChild(gallery_header1);					


			var gallery_header2= document.createElement('div');
			jQuery(gallery_header2).html("see the of crowd below...");

			jQuery(gallery_header2).css('margin-bottom',0);			
			friends_holder.appendChild(gallery_header2);					
			
			
			var friends_gallery = document.createElement('div');		
			friends_holder.appendChild(friends_gallery );								
			for(x = 0 ; x < member.friends_going.length; x++){
				if(typeof member.friends_going[x].user_id !="undefined" && member.friends_going[x].user_id.length > 0){
					var friend_headshot = document.createElement('img');					
					jQuery(friend_headshot  ).css("margin-left", 4);		
					jQuery(friend_headshot  ).css("margin-right", 4);		
					jQuery(friend_headshot  ).css("margin-bottom", 5);							
					jQuery(friend_headshot  ).css("float", "left");						
					jQuery(friend_headshot  ).attr("id","friend_headshot"+member.friends_going[x].user_id);
					if(member.friends_going[x].is_friend){
						jQuery(friend_headshot  ).css("border", '1px solid #ff0000');													
					}
					else{
						jQuery(friend_headshot  ).css("border", '1px solid #ffffff');													
					}
					
					jQuery(friend_headshot).attr('src', "http://graph.facebook.com/"+member.friends_going[x].user_id+"/picture");			
					jQuery(friend_headshot).attr('alt', member.friends_going[x].user_name);		
					jQuery(friend_headshot).attr('member_id', member.friends_going[x].user_id);							
					var friendLink = document.createElement('a');	
					jQuery(friendLink ).attr("id",member.friends_going[x].user_name+"_link");										
					jQuery(friendLink ).attr("title",member.friends_going[x].user_name);										
					jQuery(friendLink ).css("cursor","pointer");					
					jQuery(friendLink ).attr("href","/index_member_profile.php?user_id="+member.friends_going[x].user_id);
					jQuery(friendLink ).attr("target","_blank");
					
					jQuery(friendLink).click(function(){
						if(typeof fb_profile.id !="undefined" ){
							return true;
						}
						else
						{
							fb_logmein();
							return false;							
						}						
					})
					
					var curr_user_id = member.friends_going[x].user_id;
					/*
					jQuery(friend_headshot).bind('click',function(){																							  



					});
					*/
					friendLink.appendChild(friend_headshot);													
					friends_gallery.appendChild(friendLink );									
				}
			}
			
			var friends_gallery_clear = document.createElement('div');				
			jQuery(friends_gallery_clear  ).css("clear", "both");									
			friends_gallery.appendChild(friends_gallery_clear);										
				
			content_td1.appendChild(friends_holder);								
			
		}

		


		/***************************************Content detail display******************************************/		


		var content_td2 = document.createElement('td');
		content_td2.style.verticalAlign='top';		
		jQuery(content_td2).css('padding-left','20px');
		jQuery(content_td2).css('width','522px');		

		
		content_tr.appendChild(content_td2);	
		content_table.cellPadding = '4px'
		//content_table.width = '450px';




		if(	typeof member !="undefined" && 
		   	typeof member.fb_event_id  != "undefined" && 
			member.fb_event_id != 'false'  &&
		 	typeof user_attendance_markers[id]=="undefined" 		
		   ){
			
			var attend_button= document.createElement('div');
			jQuery(attend_button).attr('class', 'content_attend_button' );

			jQuery(attend_button).mouseover(function(){
				jQuery(this).attr('class', 'content_attend_button_hover' );												 
										});
			jQuery(attend_button).mouseout(function(){
				jQuery(this).attr('class', 'content_attend_button' );												
										});		

			
			jQuery(attend_button).html('Attend Event');		

			jQuery(attend_button).click(function(){

				if(typeof fb_profile.id !='undefined' && fb_profile.id){
					jQuery.post("/index.php",
								{
									cmd: "rSVPToEvent",
									fb_event_id : member.fb_event_id ,
									marker_id : id,
									user_id :  fb_profile.id 
								},
								function(data){

									eval(data);
								}
							)						
					jQuery("#TB_window").remove();
					jQuery("body").append("<div id='TB_window'></div>");
					showingGallery = true;	
					var display = inviteFriends();
					TB_show("Recommend to Your Friends", "#TB_inline?height=400&width=800&inlineId=marker_details_temp_holder&modal=true", undefined,display);					
					jQuery("#invite_friends_field" ).autoSuggest(loadedFriendsList.data, {selectedItemProp: "name", searchObjProps: "name", selectedValuesProp: "id", inputId : "inviteBoxFriendsList"});	
				}
				else{
					fb_logmein();
				}
			});
			
			var content_attending_holder= document.createElement('div');			
			jQuery(content_attending_holder).attr('class', 'content_attending_holder' );			
			jQuery(content_attending_holder).append(attend_button);									
			jQuery(content_td2).append(content_attending_holder);						
			

			
		}
		else if(typeof member !="undefined" && 
		   	typeof member.fb_event_id  != "undefined" && 
			member.fb_event_id != 'false' ){

			
			var attend_button= document.createElement('div');
			jQuery(attend_button).attr('class', 'content_attend_button' );
			jQuery(attend_button).html('Invite Friends');		

			jQuery(attend_button).click(function(){

				if(typeof fb_profile.id !='undefined' && fb_profile.id){
					jQuery("#TB_window").remove();
					jQuery("body").append("<div id='TB_window'></div>");
					showingGallery = true;	
					var display = inviteFriends();
					TB_show("Recommend to Your Friends", "#TB_inline?height=400&width=800&inlineId=marker_details_temp_holder&modal=true", undefined,display);					
					jQuery("#invite_friends_field" ).autoSuggest(loadedFriendsList.data, {selectedItemProp: "name", searchObjProps: "name", selectedValuesProp: "id", inputId : "inviteBoxFriendsList"});	
				}
				else{
					fb_logmein();
				}
			});
			
			var content_attending_holder= document.createElement('div');			
			jQuery(content_attending_holder).attr('class', 'content_attending_holder' );			
			jQuery(content_attending_holder).append(attend_button);									
			jQuery(content_td2).append(content_attending_holder);						
		}
		

		var attend_button= document.createElement('div');

		jQuery(attend_button).attr('class', 'content_attend_button_box' );
		jQuery(attend_button).html('Recommend to friend');

		jQuery(attend_button).mouseover(function(){
			jQuery(this).attr('class', 'content_attend_button_box_hover' );												 
									});
		jQuery(attend_button).mouseout(function(){
			jQuery(this).attr('class', 'content_attend_button_box' );												
									});		

		jQuery(attend_button).click(function(){
			
			if(typeof fb_profile.id !='undefined' && fb_profile.id){

				jQuery("#TB_window").remove();
				jQuery("body").append("<div id='TB_window'></div>");
				showingGallery = true;	
				var display = inviteFriends();
				TB_show("Recommend to Your Friends", "#TB_inline?height=400&width=800&inlineId=marker_details_temp_holder&modal=true", undefined,display);					
				jQuery("#invite_friends_field" ).autoSuggest(loadedFriendsList.data, {selectedItemProp: "name", searchObjProps: "name", selectedValuesProp: "id", inputId : "inviteBoxFriendsList"});	
			}
			else{
				fb_logmein();
			}
		});
		
		jQuery(content_td2).append(attend_button);		


		
		/*Read More Buttom*/
		if(reference_url && reference_url.length !=0 ){

			var content_in_info_readmore = document.createElement('div');						
			jQuery(content_in_info_readmore).attr('class', 'content_in_info_readmore');								
			jQuery(content_td2).append(content_in_info_readmore);					
	
			var readmore = document.createElement('div');						
			jQuery(readmore ).attr('class','content_in_info_readmore_a');
			jQuery(readmore ).html('Read More');
			jQuery(readmore ).attr('href', reference_url);
			jQuery(readmore ).click(function(){
									window.open(jQuery(this).attr('href'));
								});


			jQuery(content_in_info_readmore).append(readmore );								
		}	


	



		var content_in_info_header = document.createElement('div');
		jQuery(content_in_info_header).attr('class', 'content_in_info_header');
		jQuery(content_in_info_header).html(newLoc);		
		jQuery(content_td2).append(content_in_info_header);			
		
	



		var content_sep = document.createElement('div');			
		jQuery(content_sep).css('clear', 'both');
		jQuery(content_sep).css('height', 10);		
		jQuery(content_td2).append(content_sep);						


		var content_in_info_address = document.createElement('div');			
		jQuery(content_in_info_address).attr('class', 'content_in_info_address');					
		jQuery(content_in_info_address).html(newAdd);

		jQuery(content_td2).append(content_in_info_address);		
		
		if(member.time_happen.length>0){		
			var content_in_info_time= document.createElement('div');			
			jQuery(content_in_info_time).attr('class', 'content_in_info_time');					
			jQuery(content_in_info_time).html(member.time_happen);

			jQuery(content_td2).append(content_in_info_time);				
		}

		var my_hr = document.createElement('hr');			
		jQuery(content_td2).append(my_hr);								
		
		if(thingtododetail.length > 0){
			var content_in_info_detail = document.createElement('div');						
			jQuery(content_in_info_detail).attr('class', 'content_in_info_detail');								
			jQuery(content_in_info_detail).html(thingtododetail);
			jQuery(content_in_info_detail).css('overflow-x','hidden');				
			jQuery(content_td2).append(content_in_info_detail);						
			
		}		

		if(false){
			var tag_label= document.createElement('b');						
			jQuery(tag_label).html('Tags :');
			var tag_span = document.createElement('span');									
			jQuery(tag_span ).html(new_tags);											
			jQuery(tag_span).css('font-size',12);
			jQuery(tag_span).css('font-style','italic');		
	
			var tag_div= document.createElement('div');
			jQuery(tag_div).css('width',300);
			jQuery(tag_div).css('text-align','left');
			jQuery(tag_div).css('margin-top',10);		
			jQuery(tag_div).append(tag_label );										
			jQuery(tag_div).append(tag_span );											
			jQuery(content_td2).append(tag_div);							
		}

		
		/***************************************Permalink******************************************/					

		
		var perma_div = document.createElement('div');
		//content_td3.innerHTML = '<a href="javascript:showComments()">View Comments</a>';
		perma_div.style.textAlign = 'left';
		perma_div.style.fontSize = '12px';		
		perma_div.style.marginTop = '20px'		
		content_td2.appendChild(perma_div);		

		
		var url_span = document.createElement('span');
		url_span.innerHTML = 'permalink : ';
		jQuery(url_span).css('width','100%');
		url_span.style.fontWeight = 'bold';
		//url_span
		perma_div.appendChild(url_span);								
		
		var perma_input = document.createElement('input');
		jQuery(perma_input).css('width','80%');		
		jQuery(perma_input).css('border','1px solid #AAAAAA');				
		perma_input.type = 'text';
		curr_loc = "" ;
		//alert(newLoc);
		for(var x = 0 ; x < newLoc.length ; x++){
			if(newLoc.charAt(x) ==' '){
				//alert('a : '+newLoc.charAt(x));
				curr_loc += '-';
			}
			else{
				//alert('b : '+newLoc.charAt(x));
				curr_loc += newLoc.charAt(x);
			}
		}
		
		//perma_input.value = 'http://thingstodosingapore.com/see-things/'+curr_loc;		
		//alert(url_alias);
		perma_input.value = ROOT_URL+'/see-things/'+url_alias;		
		perma_div.appendChild(perma_input);						

		
		//return 	content_table;
		
		/*********************************************************Comments Box***********************************************************************************/
		var comments_details_holder = document.createElement('div');
		
		var comments_details_desc = document.createElement('div');		
		jQuery(comments_details_desc).html("Tell your friends on Facebook");
		jQuery(comments_details_desc).attr('id', 'comment_at_friends_header');		
		jQuery(comments_details_desc).attr('class', 'comment_at_friends_header');				
		
		var comment_at_friends = document.createElement('input');
		comment_at_friends.id ="comment_at_friends";
		
		var comment_fields_spacer= document.createElement('br');		
		jQuery(comment_fields_spacer).attr('id', 'comment_fields_spacer');


		var comment_insert_box_header = document.createElement('div');		
		jQuery(comment_insert_box_header).attr('class','comment_insert_box_header');				
		jQuery(comment_insert_box_header).html("What they need to know!");

		var comment_insert_box = document.createElement('textarea');
		jQuery(comment_insert_box ).css('border','1px solid #AAAAAA');		
		jQuery(comment_insert_box).css('width', '98%');
		comment_insert_box.style.height = "100px";		
		comment_insert_box.id = "comment_input" ;
		
		/*
		jQuery(comment_insert_box).keypress(
											function(){
													 checkWordNum('comment_input')
											}
										)*/
		
		
		
		var comments_textbox_holder = document.createElement('div');	
		comments_textbox_holder.appendChild(comment_insert_box);			 

		var comment_fields_spacer2= document.createElement('br');		

		var comment_insert_button_holder = document.createElement('div');	
		jQuery(comment_insert_button_holder ).attr('align', 'center');

		var comment_fields_spacer3= document.createElement('br');	
		var comment_insert_button = document.createElement('button');
		jQuery(comment_insert_button_holder ).append(comment_insert_button );

		
		jQuery(comment_insert_button).attr('id', "insertCommentButt");		
		jQuery(comment_insert_button).attr('class', 'insertCommentButt');				
		jQuery(comment_insert_button).html("Share on Facebook Now!");
		jQuery(comment_insert_button).click(
											function(){
											 	insertComment();
											}
										)		



		var counter = document.createElement('div');	
		jQuery(counter ).css('text-align','right');
		counter.id = "chars_left_notice";
		jQuery(counter).css('font-size','13');						

		
		var wordholder = document.createElement('strong');				
		wordholder.id = "comment_input-counter";
		jQuery(wordholder).html(500);
		counter.appendChild(wordholder);				

		var wordholder_desc = document.createElement('strong');				
		jQuery(wordholder_desc ).html(' Characters left');
		counter.appendChild(wordholder_desc );				


		
		var existingComments = document.createElement('div');						
		existingComments.id = "comment_details";

		comments_details_holder.appendChild(comments_details_desc);	
		comments_details_holder.appendChild(comment_at_friends);			
		comments_details_holder.appendChild(comment_fields_spacer);	
		
		comments_details_holder.appendChild(comment_insert_box_header);			
		comments_details_holder.appendChild(comments_textbox_holder);	
		comments_details_holder.appendChild(comment_fields_spacer2);
		
		//comments_details_holder.appendChild(counter);		
		//comments_details_holder.appendChild(comment_fields_spacer3);		
		comments_details_holder.appendChild(comment_insert_button_holder );			

		comments_details_holder.appendChild(existingComments);	
		
		jQuery(comments_details_holder).attr('class','comments_details_holder');												

		
		showCommentBox(id);
		
		/****************************************************************Google Tabs********************************************************************/
		
		var tabsuperholders = document.createElement('div');
		tabsuperholders.id = "tabs";
		var tabs = document.createElement('ul');
		

		var subtab1 = document.createElement('li');		
		var href1 = document.createElement('a');				
		href1.href = "#fragment-2";
		href1.innerHTML = "Details";
		subtab1.appendChild(href1);		
		tabs.appendChild(subtab1);		
			
		var content1= document.createElement('div');
		content1.id = "fragment-2";
		content1.appendChild(content_table);							
		content_td2.appendChild(comments_details_holder);		
		
		var content2 = document.createElement('div');		
		content2.id = "fragment-1";		
		
		var content2Map = document.createElement('div');
		content2Map.id = "embeddedMap";				
		jQuery(content2Map).attr("class","content_embedded_map");
		jQuery(content2).append(content2Map );

		var subtab2 = document.createElement('li');		
		var href2 = document.createElement('a');				
		href2.href = "#fragment-1";
		href2.id = "tab-fragment-1";		
		href2.innerHTML = "See Location on Map";
		subtab2.appendChild(href2);		
		tabs.appendChild(subtab2);		
		
		tabsuperholders.appendChild(tabs);							
		tabsuperholders.appendChild(content1);							
		tabsuperholders.appendChild(content2);	


		/****************************************************************You Tube********************************************************************/
		if(	youTube){
			
			var subtab3 = document.createElement('li');		
			var href3  = document.createElement('a');						
			href3.innerHTML = "Video";		
			href3.href = "#fragment-3";		
			subtab3.appendChild(href3);		
			tabs.appendChild(subtab3);						
			
			var content3 = document.createElement('div');		
			content3.id = "fragment-3";		
			content3.style.textAlign = 'center';
			content3.innerHTML = youTube;			
			
			tabsuperholders.appendChild(content3);						
		}
		
		var clearer = document.createElement('div');		
		clearer.style.clear = "both";
		clearer.appendChild(tabsuperholders);	
		return clearer;

}




//removing marker from the interface and database
function removeMarker(id){

	var choice = confirm('Do you really want to delete this entry?');
	if(choice ){
		map.closeInfoWindow();
		map.removeOverlay(markers_pointers[id]);
		//var side_entry = document.getElementById('side_entry_'+id);
		//var side_bar = document.getElementById('sidebar');
		//side_bar.removeChild(side_entry );
		xajax_removeMarker(id);
	}
	
}

//function triggered on event place search
function searchLocations() {
	//adjustSideBars('sidebar_search_result');
 var address = document.getElementById('mySearchBox').value;
 var geocoder = new GClientGeocoder();
 geocoder.getLatLng(address, function(latlng) {
   if (!latlng) {
	 alert("Address : "+address + ' not found');
   } else {
	 searchLocationsNear(latlng);
   }
 }); 
}	


//function triggered on event place page load
function getLocationsMostVoted() {
	showLoadingImage();

  markers_pointers	 = new Array();
  var latestUrl = '/index.php?cmd=voted';

  GDownloadUrl(latestUrl, function(data) {


	var xml = GXml.parse(data);
	//var sidebar = document.getElementById('sidebar');
	//sidebar.innerHTML = '';

	var markers = xml.documentElement.getElementsByTagName('marker');
	//map.clearOverlays();

	var bounds = new GLatLngBounds();

	default_marker = null;
	for (var i = 0; i < markers.length; i++) {

		var id = markers[i].getAttribute('id');
		var url_alias = markers[i].getAttribute('url_alias');		
		var cluster = markers[i].getAttribute('cluster');	
	
	  //var marker = createMarker(point, name, address);
	  var marker = addMarkerCatCord(id, parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng')), map, url_alias);

	  //var sidebarEntry = createSidebarEntry(id,marker, name, address, distance, file_name);
	  //var sidebarEntry = createSidebarEntry(id,marker, name, address, distance, file_name);
	  //sidebar.appendChild(sidebarEntry);

	   bounds.extend(point);
	}
	//map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
	//map.setCenter(default_marker.getPoint(), 19);
			
	//GEvent.trigger(default_marker, 'click');		
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

  });
}	

//function triggered on event place page load
function getLocationsMostGossiped() {
	showLoadingImage();

  markers_pointers	 = new Array();
  var latestUrl = '/index.php?cmd=gossiped';

  GDownloadUrl(latestUrl, function(data) {


	var xml = GXml.parse(data);
	//var sidebar = document.getElementById('sidebar');
	//sidebar.innerHTML = '';	

	var markers = xml.documentElement.getElementsByTagName('marker');
	//map.clearOverlays();

	var bounds = new GLatLngBounds();

	default_marker = null;
	for (var i = 0; i < markers.length; i++) {

		var id = markers[i].getAttribute('id');
		var url_alias = markers[i].getAttribute('url_alias');		
		var cluster = markers[i].getAttribute('cluster');	
	
	  //var marker = createMarker(point, name, address);
	  var marker = addMarkerCatCord(id, parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng')), map, url_alias);

	  //var sidebarEntry = createSidebarEntry(id,marker, name, address, distance, file_name);
	  //var sidebarEntry = createSidebarEntry(id,marker, name, address, distance, file_name);
	  //sidebar.appendChild(sidebarEntry);

	   bounds.extend(point);
	}
	//map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
	//map.setCenter(default_marker.getPoint(), 19);
			
	//GEvent.trigger(default_marker, 'click');		
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

  });
}	




/*Deprecated*/
function createMarker(point, name, address) {
  var marker = new GMarker(point);
  var html = '<b>' + name + '</b> <br/>' + address;
  GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowHtml(html, { 
				onOpenFn: function() { 
					temp_disable_listeners();
				} ,
				onCloseFn :function() { 
					reinstate_listeners();
				} 
		  }
		);
  });
  return marker;
}	

/*Inserts entry into the side bar*/
function createSidebarEntry(id, marker, name, address, distance, file_name) {
  var div = document.createElement('div');
  var html = "<table width=100%><tr><td width='50px' style='vertical-align:top'><img src='"+property_img_path+file_name+"' width='50px' height='50px'></td><td align='left'>";
  //html += '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address;
  html += '<b>' + name + '</b> <br/>' + address;
  html += "</td></tr></table>";
  div.innerHTML = html;
  div.style.padding = '4px';
  div.style.width = '90%';	  
  
  div.style.cursor = 'pointer';
  div.style.marginBottom = '5px'; 
  GEvent.addDomListener(div, 'click', function() {
  
	map.panTo( marker.getPoint());	

	var myIcon = marker.getIcon();
	resetMarkersImage();
	marker.setImage(ROOT_URL+'/images/selected_marker.png');
	//marker.setImage("http://thingstodosingapore.com/property_img/"+file_name);


	//document.getElementById('map_canvas').scrollIntoView(true);			
	GEvent.trigger(marker, 'click');
	map.setZoom(19)	;

	
  });
  
  GEvent.addDomListener(div, 'mouseover', function() {
	document.getElementById('tool_tip').innerHTML = "View this entry on the map?";
	move_toggle_box('tool_tip');
  });
  GEvent.addDomListener(div, 'mouseout', function() {
	fix_toggle_box();		
	toggle_insert_box('tool_tip')		
  });	  	  

  var sub_div = document.createElement('div');
  sub_div.style.textAlign="right";
  sub_div.style.fontSize='10px';
  
/*	  To be activated when useer rights have been built in
  var sub_del_icon = document.createElement('img');
  sub_del_icon.src='http://thingstodosingapore.com/images/delete.gif';
  sub_del_icon.style.cursor="pointer";
  sub_del_icon.style.width='20px';

  GEvent.addDomListener(sub_del_icon, 'mouseover', function() {
	super_div.style.backgroundColor = '#FFFFCC';
	document.getElementById('tool_tip').innerHTML = "Delete Entry?";
	move_toggle_box('tool_tip');
  });
  GEvent.addDomListener(sub_del_icon, 'mouseout', function() {
	super_div.style.backgroundColor = '#fff';
	fix_toggle_box();		
	toggle_insert_box('tool_tip')		
  });	
  GEvent.addDomListener(sub_del_icon, 'click', function() {
	removeMarker(id);
  });	  

  sub_div.appendChild(sub_del_icon);	
	*/


  var super_div = document.createElement('div');
  super_div.appendChild(div);
  super_div.appendChild(sub_div);	  
  super_div.setAttribute('id', 'side_entry_'+id); 	  
  
  GEvent.addDomListener(super_div, 'mouseover', function() {
	super_div.style.backgroundColor = '#FFFFCC';
  });
  GEvent.addDomListener(super_div, 'mouseout', function() {
	super_div.style.backgroundColor = '#fff';
  });	  
  
  return super_div;
}

/*Resets the images of markers*/
function resetMarkersImage(){

	for(x in markers_pointers){
		markers_pointers[x].setImage( markerIcons[x]);		
	}
}

//checks num of words in the detail box	
function checkWordNum(textbox_name){

	if(!textbox_name){
		textbox_name = 'thingtododetail';
	}

	//alert(document.getElementById('thingtododetail').value.length);
	if(document.getElementById(textbox_name ).value.length > 500){
		document.getElementById(textbox_name ).value = 	document.getElementById(textbox_name ).value.substr(0, 499) ;
	}
	document.getElementById(textbox_name+"-counter" ).innerHTML = 500 - document.getElementById(textbox_name ).value.length;		
}		

function return_msg(msg){
	alert(msg);
}

//loads the youtube box and the video
function startPlayYoutTube(id){
	//xajax_getYoutTube(id);

	jQuery.post("/index.php" , 
				{
					cmd : "getYouTube",
					id : id
				},
				function(data){
					eval(data);		
				}
			);
}

//remove the youtube box and the video
function displayYouTube(youtube){
	document.getElementById('show you tube').style.top = '100px';
	document.getElementById('show you tube').style.left = '300px';
	document.getElementById('show you tube').style.display = 'block';	
	document.getElementById('youtubecontent').innerHTML = youtube;
}

function stopYoutube(){
	document.getElementById('youtubecontent').innerHTML = "";	
}

//Shows the voting result
function displayPeoplesChoice(){
	document.getElementById('Peoples choice').style.top = '100px';
	document.getElementById('Peoples choice').style.left = '300px';
	document.getElementById('peoples choice content').innerHTML = '<br>Your vote has been casted<br><a href="'+DEFAULT_TWITTER_ACOUNT_URL+'" target="_blank">Check it out now!</a>';
	document.getElementById('peoples choice content').style.TextAlign = 'center';
}

//shows the optional field box in insert location dialogue box
function toggleOptionalFields(){
	if(!optionalShown){
		optionalShown = true;
		document.getElementById('optional fields').style.display = 'block';
	}
	else{
		optionalShown = false;	
		document.getElementById('optional fields').style.display = 'none';		
	}
}

//shows the insert dialogue box
function showCommentBox(id){
	

	//document.getElementById('comment input').focus();

	//xajax_getComments(id);

	 jQuery.post(
		   'index.php', 
		   { 	
		   		id:	id,
				cmd: 'getComments'
			}, 
			function(data) {

				  eval(data);
			}
	);

	/*
	//document.getElementById('mini_show_map').style.left = "-4060px";
	//document.getElementById('mini_show_map').style.top	= "540px";		
	box_name = 'show comments';
	document.getElementById(box_name).style.left = "250px";
	document.getElementById(box_name).style.top	= "80px";

	document.getElementById(box_name).style.display	= "block";	
	*/
	
	current_active_marker = id;
}

//shows the insert dialogue box
function insertComment(){
	if(typeof fb_profile.id == "undefined"){
		fb_logmein();
		return;
	}
	
	jQuery("#comment_input-counter").html(500);
	jQuery("#insertCommentButt").attr("disabled", "true");
	jQuery("#insertCommentButt").html("Submitting... Please Wait.");	
	var friendsToBePoked = jQuery("#commentBoxFriendsList").val();

	if(!viewer_id){
		//showNeedSignIn();
		//return;
		//when not working properly use the default ID ThingsToDoSingapore
		viewer_id = FACEBOOK_DEFAULT_USER_ID; 
	}

	comment	= document.getElementById('comment_input').value;
	
	//xajax_insertComment(current_active_marker , comment, viewer_id);
	
   jQuery.post(
	   'index.php', 
	   { 	
	   		marker_id:	current_active_marker,
	   		comment: comment, 
			user_id: viewer_id ,
			friendsList : friendsToBePoked,
			cmd: 'insertComment'
		}, 
		function(data) {
		
		  	eval(data);
		}
	);	
	jQuery('#insertCommentButt').removeAttr("disabled");
	jQuery('#insertCommentButt').html("insert your comment");	
	jQuery('#comment_input').val("");		
	

   var table = document.createElement('table');   
   jQuery('#comment_details').prepend(table);
   jQuery(table).attr('width','100%');
   
   
   var hr = document.createElement('hr');
   jQuery('#comment_details').prepend(hr );


   
   var tbody = document.createElement('tbody');      
   jQuery(table).append(tbody);   
   var tr = document.createElement('tr');         
   jQuery(tbody).append(tr);   
   
   var td1 = document.createElement('td');            
   jQuery(tr).append(td1);   
   jQuery(td1).attr('valign','top');
   jQuery(td1).attr('align','center');      
   jQuery(td1).attr('width','10%');         
   jQuery(td1).css('padding-right','10px');            
   
   var a = document.createElement('a');               
   jQuery(td1).append(a);      
   jQuery(a).attr('href',"/index_member_profile.php?user_id="+fb_profile.id);
   jQuery(a).attr('target',"_blank");   
   
   var img	 = document.createElement('img');                  
   jQuery(a).append(img);         
   jQuery(img).attr('height',"35");      
   jQuery(img).attr('alt',fb_profile.name);         
   jQuery(img).attr('src','http://graph.facebook.com/'+fb_profile.id+'/picture');            
   
   var td2 = document.createElement('td');               
   jQuery(tr).append(td2);      
   jQuery(td2).attr('valign','top');   
   
   var div1 = document.createElement('div');               
   jQuery(td2).append(div1);         
   jQuery(div1).attr('class','comments_in_info_detail');      
   jQuery(div1).html(comment);   
   
   var div2 = document.createElement('div');                  
   jQuery(td2).append(div2);         
   jQuery(div2).attr('align','right');         
   jQuery(div2).css('font-size','10px');            	
   jQuery(div2).html('1 second ago');   
   
	jQuery('#no_comments').hide();
	jQuery('#no_comments_hr').hide();	

}


var tagpanel_shown = false


//displays a route
function displayRoute(markersArray){
	return;
	//alert('here');
	var listRoute = new Array();

    var directionOptions = new Object(); 
	directionOptions.getPolyline = true; 
	directionOptions.getSteps = false; 
	directionOptions.preserveViewport = true; 
	directionOptions.locale = "en_US"; 

	gdirections = new GDirections(map);	
	GEvent.addListener(gdirections, "load", function(){alert('success');});
    GEvent.addListener(gdirections, "error", handleDirectionErrors);	
	gdirections.load("from: " + "City Hall" + " to: " + "Boon Lay", { "locale": "sg"});
		
}

function handleDirectionErrors(){
   if (gdirections.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdirections.getStatus().code);
   else if (gdirections.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdirections.getStatus().code);
   
   else if (gdirections.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdirections.getStatus().code);

//   else if (gdirections.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdirections.getStatus().code);
	 
   else if (gdirections.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdirections.getStatus().code);

   else if (gdirections.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + gdirections.getStatus().code);
	
   else alert("An unknown error occurred.");
   
}

//gets the radius within which to get markers for
function getMapRadius(){
	/*
  var curr_bound= map.getBounds();
  var sw = curr_bound.getSouthWest() ;

  west = sw.lat();
  south = sw.lng();

  var ne = curr_bound.getNorthEast() ;

  east = ne.lat();
  north = ne.lng();  
  
  lng = (south - north )/2;
  lat = (east - west )/2
  */
  
	var curr_bound= map.getBounds();
  	var southWest = curr_bound.getSouthWest();
  	var northEast = curr_bound.getNorthEast();
  	//var lngSpan = northEast.lng() - southWest.lng();
  	var latSpan = northEast.lat() - southWest.lat();
  	var lngSpan = northEast.lng() - southWest.lng();	

	if(lngSpan < latSpan){
		var radius = lngSpan /2;		
	}
	else{
		var radius = latSpan /2;				
	}

	//radius = Math.sqrt( lng * lng  + lat *lat );
	//alert('all within '+(radius*100)+' radius');
  	return radius*80 ;
}

//adds a marker to the map given cordinates as a cluster opener
function addClusterCord(id, point1, point2, map, custom_icon ){

	var bounds = new GLatLngBounds();		
   	bounds.extend(point1);
   	bounds.extend(point2);   
	  
	var marker = new GMarker(bounds.getCenter() , {});	

	
	GEvent.addListener(marker, 'click', function() {
		if(map.getBoundsZoomLevel(bounds) > 18){
			map.setCenter(bounds.getCenter(), 18);			
		}
		else{
			map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)-1);			
		}

	});	
	
	GEvent.addListener(marker, 'mouseover', function() {
		clearLabels();
		num = custom_icon*1;
		var label = new ELabel(bounds.getCenter(), '<div class="myLabels">There are '+num +' suggestions here.<br>Click to Zoom in<\/div>', null, new GSize(-100,-50), 90);
		labels.push(label );
      	map.addOverlay(label);	
	});		
	
	GEvent.addListener(marker, 'mouseout', function() {
		clearLabels();
	});			
	
	map.addOverlay(marker);
	


	marker.setImage(ROOT_URL+'/images/numbered/marker'+custom_icon+'.png');				
	return marker;
}

function clean_listeners(){
	while(curr_listener = event_listeners.pop()){
		GEvent.removeListener(curr_listener );
	}
}

function icon_factory(marker_id, markerIcon){
	//user_owned_markers 	
	
	if(typeof markerIcon!='undefined' && markerIcon.length>0){
		markerIcons[marker_id]= markerIcon;
		return markerIcon;		
	}

	if(typeof user_owned_markers[marker_id]!="undefined"){
		if(typeof user_related_markers[marker_id]=="undefined"){
			return ROOT_URL+'/images/unselected_marker_owned.png'; 
		}
		else{
			switch(user_related_markers[marker_id]){
				case "read" :	return ROOT_URL+'/images/read_marker_owned.png';
				case "replied" :	return ROOT_URL+'/images/replied_marker_owned.png';			
				case "mentioned" :	return ROOT_URL+'/images/mentioned_marker_owned.png';							
				
				default :		return ROOT_URL+'/images/unselected_marker_owned.png';
			}			
		}	

	}
	else if(typeof user_attendance_markers[marker_id] !="undefined"){
		if(typeof user_related_markers[marker_id]=="undefined"){
			return ROOT_URL+'/images/unselected_marker_attending.png';			
		}
		else{

			switch(user_related_markers[marker_id]){
				case "read" :	return ROOT_URL+'/images/read_marker_attending.png';			
				case "replied" :	return ROOT_URL+'/images/replied_marker_attending.png';			
				case "mentioned" :	return ROOT_URL+'/images/mentioned_marker_attending.png';							
				default :		return ROOT_URL+'/images/unselected_marker_attending.png';							
			}
		}

	}
	else if(typeof user_invitation_markers[marker_id] !="undefined"){
		if(typeof user_related_markers[marker_id]=="undefined"){
			return ROOT_URL+'/images/unselected_marker_invited.png';			
		}
		else{

			switch(user_related_markers[marker_id]){
				case "read" :	return ROOT_URL+'/images/read_marker_invited.png';			
				case "replied" :	return ROOT_URL+'/images/replied_marker_invited.png';			
				case "mentioned" :	return ROOT_URL+'/images/mentioned_marker_invited.png';							
				default :		return ROOT_URL+'/images/unselected_marker_invited.png';							
			}
		}

	}	
	
	else{
		
		if(typeof user_related_markers[marker_id]=="undefined"){
			return ROOT_URL+'/images/unselected_marker.png';			
		}
		else{

			switch(user_related_markers[marker_id]){
				case "read" :	return ROOT_URL+'/images/read_marker.png';			
				case "replied" :	return ROOT_URL+'/images/replied_marker.png';			
				case "mentioned" :	return ROOT_URL+'/images/mentioned_marker.png';							
				default :		return ROOT_URL+'/images/unselected_marker.png';							
			}
		}		
		
	

	}
	//user_related_markers
}



function intercept_login(){
	//when there are not initial locations to load

	/*
	if(!viewer_id && !skip_login){
		//alert("You need to login");
		//jQuery("#map_canvas").hide();				
		var div0 = document.createElement('div');

		var div11 = document.createElement('div');
		jQuery(div11).width(220);
		jQuery(div11).css('float', 'left');
		jQuery(div0).append(div11 );
		
		var div11a = document.createElement('div');
		jQuery(div11a).width(120);
		jQuery(div11a).css('margin-top', 18);			
		jQuery(div11a).css('float', 'left');
		jQuery(div0).append(div11a );		
		
		var bypass = document.createElement('a');
		jQuery(bypass).html('or skip login');
		jQuery(div11a ).append(bypass);				
		jQuery(div11a ).css('cursor', 'pointer');						
		jQuery(div11a ).css('color', '#5B74A8');								
		
		
		
		jQuery(div11a ).bind(	'click', 
							function(){
								skip_login = true;
								check_login = false;
								intercept_login();
								showLoginButton();
							}
						);		
		
		

		var div12 = document.createElement('div');
		jQuery(div12).width(420);
		jQuery(div12).height(25);		
		jQuery(div12).css('float', 'right');
		jQuery(div12).css('font-size', 20);		
		//jQuery(div12).css('line-height', 25);				
		jQuery(div12).css('text-align', 'right');				
		jQuery(div12).css('margin-top', 15);						
		//jQuery(div12).css('font-weight', 'bold');				
		jQuery(div12).css('font-family', '"lucida grande",tahoma,verdana,arial,sans-serif');						
		jQuery(div12).html(jQuery('#members_count').html());
		jQuery(div0).append(div12 );


		var div13 = document.createElement('div');
		jQuery(div13).css('clear', 'both');

		jQuery(div0).append(div13 );

		var butt = document.createElement('img');
		butt.style.marginBottom = "0px";
		butt.style.marginRight = "0px";
		butt.style.marginLeft = "0px";
		butt.style.marginTop = "10px";		
		
		butt.style.border = "none";		
		jQuery(butt).attr('src', "http://thingstodosingapore.com/images/facebook.png");
		jQuery(butt).css('cursor','pointer');
	
		jQuery(butt).bind(	'click', 
							function(){
								//alert('logme in');
								fb_logmein();
												
							}
						);		
		jQuery(div11 ).append(butt);
		

		
		
		var div2 = document.createElement('div');
		jQuery(div0).append(div2 );
		jQuery(div2).html(jQuery("#login_teaser").html());
		

		TB_show("Find out what they are saying about Things To Do in Singapore", "#TB_inline?height=450&width=760&inlineId=marker_details_temp_holder&modal=true", undefined, div0 );							
	}
	else */
	//when there are initial locations to load
	if((typeof load_time_org_id != 'undefined' && load_time_org_id  ) && load_time_org_lat && load_time_org_lng){
		if(jQuery("#TB_window")){
			jQuery("#TB_window").remove();
		}
        //jQuery("#TB_window").remove();
        //jQuery("body").append("<div id='TB_window'></div>");		
		jQuery("#home-search").hide();		
		jQuery("#map_canvas").show();				

		//searchLocationsNearTag(load_time_org_id, load_time_org_lat, load_time_org_lng);

		getLocationsCategoryLanding(load_time_org_id, load_time_org_lat, load_time_org_lng, load_time_cat);
	}	
	else if(typeof show_by_date  != 'undefined' && show_by_date ){

		if(jQuery("#"+choosen_period)){

			jQuery("#"+choosen_period).attr('class','dateholder_selected');				

		}
		markers_pointers	 = [];  
		update_main_selector_count();		
		getLocationsByDate() ;
	}
	else{
		jQuery("#home-search").hide();		
		jQuery("#map_canvas").show();			
		TB_remove();
		getLocationsLatest();	
	}	
}




// ==== Remove the old Elabels when the user asks for the results to be cleared ====
function doIdleCallback() {
  alert('idle');
//map.clearOverlays();
}

// ==== Remove the old ELabels when a new search is performed ====
function doSearchCompleteCallback(search) {
  alert('search complee');		  
//map.clearOverlays();
}

// ==== Scan through the markers and GlocanLresults, creating ELabels ====
function doMarkersSetCallback(info) 
{
  alert('markers call back');		  		  
for (var i=0; i<info.length; i++) {
  var title = info[i].result.titleNoFormatting;
  var marker = info[i].marker;
  var label = new ELabel(marker.getLatLng(), '<div style="background-color:#ccccff;border:2px solid black;white-space:nowrap">'+title+'<\/div>', null, new GSize(3,-23), 75); 
  map.addOverlay(label);
  marker.Elabel = label; // === remember which Elabel beongs to this marker
}
}

// ==== hide the Elabel when the info Window opens ====
function doGenerateMarkerHtmlCallback(marker,html,result) {
  alert('generate marker html');		  		  		  
if (hiddenElabel) {
  hiddenElabel.show();
  hiddenElabel = 0;
}
marker.Elabel.hide();
hiddenElabel = marker.Elabel; // remember which ELabel is hidden
return html; // return the unmodified html object
}



function adjustMapDimension(){
	var new_width = jQuery('#main-column').width()- jQuery('#'+leftPanel).width();
	jQuery('#hold_sticky_map_canvas').width(new_width+"px" );					
	jQuery('#map_canvas').width(new_width+"px" );			
	var new_height= jQuery(window).height();	
	jQuery('#map_canvas').height(new_height+"px" );			
}

function showPreLoadListings(){
	//map.clearOverlays();	
	jQuery('#listings_holder_ul').empty();

	var div_loading  = document.createElement('div');
	jQuery(div_loading ).attr('align','center');	
	jQuery(div_loading ).css('padding-bottom','150');
	jQuery(div_loading ).css('padding-top','50');	
	
	var loadingImg  = document.createElement('img');	
	jQuery(loadingImg  ).attr('src','/images/loading.gif');
	jQuery(div_loading ).append(loadingImg  );

	var loadingBr = document.createElement('br');	
	jQuery(div_loading ).append(loadingBr);	
	jQuery(div_loading ).append('Loading. Please wait.');		
	jQuery('#listings_holder_ul').append(div_loading );		
	jQuery('#showMore').hide();	

	if(jQuery(document).scrollTop()>mapOffSetTop){
		jQuery(document).scrollTop(mapOffSetTop) ;
	}
}

function generateNewListings(data){
	jQuery('#showMore').show();	
	jQuery('#listings_holder_ul').empty();
	jQuery('#map_pusher').animate({height:0},0);
	
	var data = data.data;
	for(x=0; x < data.length; x++){
		var listing_div = document.createElement('li');
		

		var div_img = document.createElement('div');				
		jQuery(listing_div).append(div_img);
		jQuery(div_img ).css('width','45px');
		jQuery(div_img ).css('float','left');
		
		//jQuery(div_img).attr('id','listings_entry_'+data[x].id);			
		//jQuery(div_name).attr('class','listings_entry_name');				

		var img = document.createElement('img');				
		var img_a = document.createElement('a');	
		jQuery(img_a).attr("href","/index_member_profile.php?user_id="+data[x].user_id);
		jQuery(img_a).attr("target","_blank");
		
		jQuery(div_img).append(img_a);
		jQuery(img_a).append(img);		
		jQuery(img_a).attr('title', data[x].user_name);		
		jQuery(img).attr('src', data[x].profile_img);
		jQuery(img).attr('width', '40');		
		jQuery(img).attr('height', '40');		
		jQuery(img).attr('member_id', data[x].user_id);			
		/*
		jQuery(img).click(function(){
			if(typeof fb_profile.id == "undefined"){
				fb_logmein();
			}
			else{
				window.location = "/index_member_profile.php?user_id="+jQuery(this).attr("member_id")
			}
		});*/
		
		//jQuery(img).attr('id','listings_entry_'+data[x].id);
		//jQuery(img).attr('class','listings_entry_name');						

		var div_details= document.createElement('div');		
		jQuery(div_details).attr('class','listings_entry_listing');						
		jQuery(listing_div).append(div_details );

		var div_name = document.createElement('div');				

		jQuery(div_name).attr('id','listings_entry_'+data[x].id);				
		jQuery(div_name).attr('marker_id', data[x].id);		
		jQuery(div_details).append(div_name );		
		jQuery(listing_div).attr('class','listings_entry');		
		jQuery(div_name).html(data[x].name);
		jQuery(div_name).attr('class','listings_entry_name');				

		var div_excerpt = document.createElement('div');				
		jQuery(div_excerpt).attr('marker_id', data[x].id);		
		jQuery(div_excerpt).attr('id','listings_excerpt_'+data[x].id);				
		jQuery(div_details).append(div_excerpt);		

		jQuery(div_excerpt).html(data[x].excerpt);
		jQuery(div_excerpt).attr('class','listings_entry_excerpt');				



		jQuery('#listings_holder_ul').append(listing_div);
		
		if(data[x].start_time.length>0 ){
			var div_time = document.createElement('div');		
			
			if(data[x].attend>0){
				crowd_ext = ", crowd "+data[x].attend+" people";
			}
			else{
				crowd_ext = "";				
			}
			jQuery(div_time).html("Happening on "+data[x].start_time+crowd_ext );			
			jQuery(div_time).html("Happening on "+data[x].start_time);
			jQuery(div_time).attr('class','listings_entry_time');				
			jQuery(div_details).append(div_time);
			
		}
		else{
			var div_time = document.createElement('div');			
			jQuery(div_time).html("created on "+data[x].posted_time);
			jQuery(div_time).attr('class','listings_entry_time');				
			jQuery(div_details).append(div_time);			
		}		

		if(data[x].friends>0){
			var div_friends = document.createElement('div');			
			jQuery(div_friends).html("friends "+data[x].friends);
			jQuery(div_friends).attr('class','listings_entry_friends');				
			jQuery(div_details).append(div_friends);			
			
		}


		if(data[x].attend>0){
			var div_attend = document.createElement('div');			
			jQuery(div_attend).html("crowd "+data[x].attend);
			jQuery(div_attend).attr('class','listings_entry_crowd');				
			jQuery(div_details).append(div_attend);			
			
		}



		jQuery(div_details).attr('marker_id', data[x].id);
		jQuery(div_details).attr('markerIcon', data[x].markerIcon);		
		jQuery(div_details).attr('lat', data[x].lat);		
		jQuery(div_details).attr('lng', data[x].lng);				
		jQuery(div_details).attr('url_alias', data[x].url_alias);						
		
		jQuery(listing_div).mouseover(function(){
			jQuery(this).attr('class', 'listings_entry_hover');
		});
		jQuery(listing_div).mouseout(function(){
			jQuery(this).attr('class', 'listings_entry');
		});		

		jQuery(div_name).click(function(){
										   
			var curr_id = jQuery(this).attr('marker_id');
	   		tb_showMarkerContent(curr_id );
			/*										   	
			if(typeof markers_pointers[jQuery(this).attr('marker_id')]!="undefined"){
				map.removeOverlay(markers_pointers[jQuery(this).attr('marker_id')]); 
				
				var new_marker = addMarkerCatCord(jQuery(this).attr('marker_id'), jQuery(this).attr('lat'), jQuery(this).attr('lng'), map, jQuery(this).attr('url_alias'), jQuery(this).attr('markerIcon'));
				markers_pointers[jQuery(this).attr('marker_id')] = new_marker ;
				GEvent.trigger(new_marker , 'click');					
			}
			else{
				var new_marker = addMarkerCatCord(jQuery(this).attr('marker_id'), jQuery(this).attr('lat'), jQuery(this).attr('lng'), map, jQuery(this).attr('url_alias'), jQuery(this).attr('markerIcon'));
				markers_pointers[jQuery(this).attr('marker_id')] = new_marker ;				
				GEvent.trigger(new_marker , 'click');									
			}
			*/
		});		
		
		jQuery(div_excerpt).click(function(){
										   
			var curr_id = jQuery(this).attr('marker_id');
	   		tb_showMarkerContent(curr_id );
			/*										   	
			if(typeof markers_pointers[jQuery(this).attr('marker_id')]!="undefined"){
				map.removeOverlay(markers_pointers[jQuery(this).attr('marker_id')]); 
				
				var new_marker = addMarkerCatCord(jQuery(this).attr('marker_id'), jQuery(this).attr('lat'), jQuery(this).attr('lng'), map, jQuery(this).attr('url_alias'), jQuery(this).attr('markerIcon'));
				markers_pointers[jQuery(this).attr('marker_id')] = new_marker ;
				GEvent.trigger(new_marker , 'click');					
			}
			else{
				var new_marker = addMarkerCatCord(jQuery(this).attr('marker_id'), jQuery(this).attr('lat'), jQuery(this).attr('lng'), map, jQuery(this).attr('url_alias'), jQuery(this).attr('markerIcon'));
				markers_pointers[jQuery(this).attr('marker_id')] = new_marker ;				
				GEvent.trigger(new_marker , 'click');									
			}
			*/
		});				
		

		var attend_button_sep= document.createElement('div');
		jQuery(attend_button_sep).attr('class', 'attend_button_sep' );
		jQuery(div_details).append(attend_button_sep);				


		
		var attend_button= document.createElement('div');
		jQuery(attend_button).attr('marker_id', data[x].id);		
		jQuery(attend_button).attr('class', 'content_attend_button' );
		jQuery(attend_button).html('Recommend to your friends on facebook');

		jQuery(attend_button).mouseover(function(){
			jQuery(this).attr('class', 'content_attend_button_hover' );												 
									});
		jQuery(attend_button).mouseout(function(){
			jQuery(this).attr('class', 'content_attend_button' );												
									});		

		jQuery(attend_button).click(function(){
			
			if(typeof fb_profile.id !='undefined' && fb_profile.id){
				current_marker_id = jQuery(this).attr('marker_id');											 				
				jQuery("#TB_window").remove();
				jQuery("body").append("<div id='TB_window'></div>");
				showingGallery = true;	
				var display = inviteFriends();
				TB_show("Recommend to Your Friends", "#TB_inline?height=400&width=800&inlineId=marker_details_temp_holder&modal=true", undefined,display);					
				jQuery("#invite_friends_field" ).autoSuggest(loadedFriendsList.data, {selectedItemProp: "name", searchObjProps: "name", selectedValuesProp: "id", inputId : "inviteBoxFriendsList"});	
			}
			else{
				fb_logmein();
			}
		});
		
		jQuery(div_details).append(attend_button);				
	}

	activateMoreButton();

	if(data.length<ITEMS_PER_LISTINGS){
		jQuery('#showMore').hide();
	}

}

function activateMoreButton(){
	jQuery('#showMore').attr('class','listings_entry_more');
	jQuery('#showMore').mouseover(function(){
		jQuery(this).attr('class', 'listings_entry_more_hover');
	});
	jQuery('#showMore').mouseout(function(){
		jQuery(this).attr('class', 'listings_entry_more');
	});			
	
	jQuery('#showMore').click(function(){
		var loadingImg = document.createElement('img');
		jQuery(loadingImg).attr('src','/images/loading.gif');
	   	jQuery('#showMore').empty();	   
	   	jQuery('#showMore').append(loadingImg);	   		
		getMoreListings();
		
		jQuery('#showMore').unbind('click');
		jQuery('#showMore').unbind('mouseover');
		jQuery('#showMore').unbind('mouseout');		
		jQuery('#showMore').attr('class', 'listings_entry_more');		
	});				
}

function getMoreListings(){
	listingsParams.offset += 1;
  
	jQuery.getJSON('index.php', 
				  listingsParams
				  ,
				   
					function(data) {
						activateMoreButton();
					   jQuery('#showMore').html('More');						
						generateMoreListings(data);
			});

	jQuery('iframe#track').attr('src', ROOT_URL+"/track/get-more-listings");

	jQuery('iframe#track').load(function() 
	{
		//alert('done');
	});	
	
	
}
function generateMoreListings(data){

	var data = data.data;
	for(x=0; x < data.length; x++){
		var listing_div = document.createElement('li');
		

		var div_img = document.createElement('div');				
		jQuery(listing_div).append(div_img);
		jQuery(div_img ).css('width','45px');
		jQuery(div_img ).css('float','left');
		
		//jQuery(div_img).attr('id','listings_entry_'+data[x].id);			
		//jQuery(div_name).attr('class','listings_entry_name');				

		var img = document.createElement('img');				
		var img_a = document.createElement('a');		
		jQuery(img_a).attr("href","/index_member_profile.php?user_id="+data[x].user_id);
		jQuery(img_a).attr("target","_blank");
		
		jQuery(div_img).append(img_a);
		jQuery(img_a).append(img);		
		jQuery(img_a).attr('title', data[x].user_name);		
		jQuery(img).attr('src', data[x].profile_img);
		jQuery(img).attr('width', '40');		
		jQuery(img).attr('height', '40');		
		jQuery(img).attr('member_id', data[x].user_id);			
		
		/*
		jQuery(img).click(function(){
			if(typeof fb_profile.id == "undefined"){
				fb_logmein();
			}
			else{
				window.location = "/index_member_profile.php?user_id="+jQuery(this).attr("member_id")
			}
		});*/
		
		//jQuery(img).attr('id','listings_entry_'+data[x].id);
		//jQuery(img).attr('class','listings_entry_name');						

		var div_details= document.createElement('div');		
		jQuery(div_details).attr('class','listings_entry_listing');						
		jQuery(listing_div).append(div_details );

		var div_name = document.createElement('div');				

		jQuery(div_name).attr('id','listings_entry_'+data[x].id);				
		jQuery(div_details).append(div_name );		
		jQuery(listing_div).attr('class','listings_entry');		
		jQuery(div_name).html(data[x].name);
		jQuery(div_name).attr('class','listings_entry_name');		
		
		var div_excerpt = document.createElement('div');				

		jQuery(div_excerpt).attr('id','listings_excerpt_'+data[x].id);				
		jQuery(div_details).append(div_excerpt);		

		jQuery(div_excerpt).html(data[x].excerpt);
		jQuery(div_excerpt).attr('class','listings_entry_excerpt');				
		
		
		jQuery('#listings_holder_ul').append(listing_div);
		
		if(data[x].start_time.length>0 ){
			var div_time = document.createElement('div');		
			
			if(data[x].attend>0){
				crowd_ext = ", crowd "+data[x].attend+" people";
			}
			else{
				crowd_ext = "";				
			}
			jQuery(div_time).html("Happening on "+data[x].start_time+crowd_ext );			
			jQuery(div_time).html("Happening on "+data[x].start_time);
			jQuery(div_time).attr('class','listings_entry_time');				
			jQuery(div_details).append(div_time);
			
		}
		else{
			var div_time = document.createElement('div');			
			jQuery(div_time).html("created on "+data[x].posted_time);
			jQuery(div_time).attr('class','listings_entry_time');				
			jQuery(div_details).append(div_time);			
		}		

		if(data[x].friends>0){
			var div_friends = document.createElement('div');			
			jQuery(div_friends).html("friends "+data[x].friends);
			jQuery(div_friends).attr('class','listings_entry_friends');				
			jQuery(div_details).append(div_friends);			
			
		}


		if(data[x].attend>0){
			var div_attend = document.createElement('div');			
			jQuery(div_attend).html("crowd "+data[x].attend);
			jQuery(div_attend).attr('class','listings_entry_crowd');				
			jQuery(div_details).append(div_attend);			
			
		}


		jQuery(div_details).attr('marker_id', data[x].id);
		jQuery(div_details).attr('markerIcon', data[x].markerIcon);				
		jQuery(div_details).attr('lat', data[x].lat);		
		jQuery(div_details).attr('lng', data[x].lng);				
		jQuery(div_details).attr('url_alias', data[x].url_alias);						
		
		jQuery(listing_div).mouseover(function(){
			jQuery(this).attr('class', 'listings_entry_hover');
		});
		jQuery(listing_div).mouseout(function(){
			jQuery(this).attr('class', 'listings_entry');
		});		

		jQuery(div_details).click(function(){
			var curr_id = jQuery(this).attr('marker_id');
	   		tb_showMarkerContent(curr_id );										   
			/*										   	
			if(typeof markers_pointers[jQuery(this).attr('marker_id')]!="undefined"){
				map.removeOverlay(markers_pointers[jQuery(this).attr('marker_id')]); 

				var new_marker = addMarkerCatCord(jQuery(this).attr('marker_id'), jQuery(this).attr('lat'), jQuery(this).attr('lng'), map, jQuery(this).attr('url_alias'), jQuery(this).attr('markerIcon'));
				markers_pointers[jQuery(this).attr('marker_id')]= new_marker;
				GEvent.trigger(new_marker , 'click');					
			}
			else{
				var new_marker = addMarkerCatCord(jQuery(this).attr('marker_id'), jQuery(this).attr('lat'), jQuery(this).attr('lng'), map, jQuery(this).attr('url_alias'), jQuery(this).attr('markerIcon'));
				markers_pointers[jQuery(this).attr('marker_id')]= new_marker;				
				GEvent.trigger(new_marker , 'click');									
			}
			*/
		});		

		var attend_button_sep= document.createElement('div');
		jQuery(attend_button_sep).attr('class', 'attend_button_sep' );
		jQuery(div_details).append(attend_button_sep);				

		var attend_button= document.createElement('div');
		jQuery(attend_button).attr('marker_id', data[x].id);		
		jQuery(attend_button).attr('class', 'content_attend_button' );
		jQuery(attend_button).html('Recommend to your friend on facebook');

		jQuery(attend_button).mouseover(function(){
			jQuery(this).attr('class', 'content_attend_button_hover' );												 
									});
		jQuery(attend_button).mouseout(function(){
			jQuery(this).attr('class', 'content_attend_button' );												
									});		

		jQuery(attend_button).click(function(){
			
			if(typeof fb_profile.id !='undefined' && fb_profile.id){
				current_marker_id = jQuery(this).attr('marker_id');											 				
				jQuery("#TB_window").remove();
				jQuery("body").append("<div id='TB_window'></div>");
				showingGallery = true;	
				var display = inviteFriends();
				TB_show("Recommend to Your Friends", "#TB_inline?height=400&width=800&inlineId=marker_details_temp_holder&modal=true", undefined,display);					
				jQuery("#invite_friends_field" ).autoSuggest(loadedFriendsList.data, {selectedItemProp: "name", searchObjProps: "name", selectedValuesProp: "id", inputId : "inviteBoxFriendsList"});	
			}
			else{
				fb_logmein();
			}
		});
		
		jQuery(div_details).append(attend_button);				
		
	}
	
	if(data.length<ITEMS_PER_LISTINGS){
		jQuery('#showMore').hide();
	}
	

}

function profile_imgs_click(){


	for(x =0; x< jQuery("#side_login_teasers img").length; x++){
		var img= jQuery("#side_login_teasers img")[x];


		jQuery(img).click(function(){
			if(typeof fb_profile.id == "undefined"){
				fb_logmein();
			}
			else{
				window.location = "/index_member_profile.php?user_id="+jQuery(this).attr("member_id")
			}
		});
	}


}

function clearLabels(){
	for(x= 0 ; x < labels.length; x++){
		if(typeof labels[x] !='undefined'){													 
			map.removeOverlay(labels[x]);
		}													  		
	}
	labels= new Array();
}

function showTopAdBanner(){
	if(canShowAds ){
		jQuery('#banner_holder').css('z-index', '1021');
		jQuery('#banner_holder').css('position', 'absolute');	
		jQuery('#banner_holder').css('top', jQuery(document).scrollTop());		
		jQuery('#banner_holder').attr('align', 'center');			
		jQuery('#banner_holder').css('width', jQuery(window).width());				
		jQuery('#banner_holder').css('display', 'block');		
	}
	
}

function floatTopBanner(){
	if(canShowAds ){	
		jQuery('#banner_holder').css('top', jQuery(document).scrollTop());			
		jQuery('#banner_holder').css('width', jQuery(window).width());					
	}
}

function hideTopAdBanner(){
	jQuery('#banner_holder').css('top', '0');			
	jQuery('#banner_holder').css('display', 'none');				
}

function showBottomAdBanner(){
	if(canShowAds ){
		jQuery('#banner_holder2').css('z-index', '1021');
		jQuery('#banner_holder2').css('position', 'absolute');	
		jQuery('#banner_holder2').css('top', jQuery(document).scrollTop()+jQuery(window).height()-90);		
		jQuery('#banner_holder2').attr('align', 'center');			
		jQuery('#banner_holder2').css('width', jQuery(window).width());				
		jQuery('#banner_holder2').css('display', 'block');		
	}
	
}

function floatBottomBanner(){
	if(canShowAds ){		
		jQuery('#banner_holder2').css('top', jQuery(document).scrollTop()+jQuery(window).height()-90);		
		jQuery('#banner_holder2').css('width', jQuery(window).width());						
	}
}

function hideBottomAdBanner(){
	jQuery('#banner_holder2').css('top', '0');			
	jQuery('#banner_holder2').css('display', 'none');					
}
