google.load("maps", "2.x");

viewer_id = null;
user_id = null; 
owner_name = "";
owner_id = null;
pageview = "canvas";
pagelevel = 1;
pageCountry = 22;
pageState = 5;
pageCity = 0;
var mymarkers = null;
var bounds = null;
var surface = null;
var browsepage = 0;
var brwsmarker = [ 
	{ "lat" : 33.9391, "lon"  : 67.71, "id" : 67, "name" : "Afghanistan" }, 
	{ "lat" : 41.1533, "lon"  : 20.1683, "id" : 68, "name" : "Albania"}, 
	{ "lat" : 28.0339, "lon"  : 1.65963, "id" : 69 , "name" : "Algeria"},
	{ "lat" : 40.9754, "lon"  : -0.443657, "id" : 70, "name" : "Andorra"}, 
	{ "lat" : -11.2027, "lon"  : 17.8739, "id" : 71, "name" : "Angola" },
	{ "lat" : 18.2206, "lon"  : -63.0686, "id" : 941, "name" : "Anguilla"},
	{ "lat" : 17.086, "lon"  : -61.7894, "id" : 72, "name" : "Antigua" }, 
	{ "lat" : -38.4161, "lon"  : -63.6167, "id" : 73, "name" : "Argentina" }, 
	{ "lat" : 40.0691, "lon"  : 45.0382, "id" : 74, "name" : "Armenia"}, 
	{ "lat" : 12.5211, "lon"  : -69.9683, "id" : 1170, "name" : "Aruba"}];
	
/********************************************************* init functions *********************************************************/	
// Call this function when the page has been loaded
function initialize() 
{	
	
	var req = opensocial.newDataRequest();
	req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER), "owner");
	req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), "viewer");
    if ( site == "hi5")
	{
		var fields = ["country", "state", "city"];
		req.add(req.newFetchPersonAppDataRequest(opensocial.DataRequest.PersonId.OWNER, fields), "returnData");
	}
	req.send(processInitialize);
}

function processInitialize(data)
{
	if ( site == "hi5")
		user_data = data.get("returnData").getData();
	
	var owner = data.get("owner").getData();
	
	if ( owner == null )
		alert("Myspace server is too busy right now. Please refresh the page or try again later.");
		
	owner_id = user_id = owner.getId();
	owner_name = owner.getDisplayName();
	
	var viewer = data.get("viewer").getData();
	if ( viewer != null )
	{
		viewer_id = viewer.getId();
		if ( owner_id == viewer_id )
			isOwner = true;	
		//else
		//	user_id = viewer_id;
	}
	
    //logic for viewer not being an owner in canvas view
	if ( !isOwner )
	{
        //temporarily remove install link since no support in fanbox
        if ( site == "fanbox")
            document.getElementById("rightstuff").innerHTML = "<div style='margin: 50px 10px; font-weight: bold;'>You are viewing "+owner_name+"'s places. Go to your own Where I've Traveled map to add locations.</div>";
      
        else
            document.getElementById("rightstuff").innerHTML = "<div style='margin: 50px 10px; font-weight: bold;'>You are viewing "+owner_name+"'s places. Please click <a target='_blank' href='"+appUrl+"'>here</a> to go to your own map to add locations.</div>";
        
	}

	gadgets.io.makeRequest(requestUrl+"checkuser.php?nocache="+Math.floor(Math.random()*5), processCheckUser,
		{'METHOD' : gadgets.io.MethodType.POST,'POST_DATA':"site="+site+"&uid="+owner_id});		
}

function processCheckUser(response) 
{
	data = response.data;
	
	if( typeof(data)=="undefined")
		alert("Myspace server is too busy right now. Please refresh the page or try again later.");
	 
	
	pos = data.indexOf(",");
	username = data.substring(0,pos);
	pageCity = parseInt(data.substring(pos+1));
	pageCity = Math.ceil(pageCity / 10);
	
	if ( isOwner )
	{
		if ( username != '' )
			printMapPage();
		else
			printAccountPage("","");
	}
	else
		printMapPage();
}

/********************************************************* end init functions *********************************************************/

/********************************************************* create account  / login functions *********************************************************/
function printAccountPage(msg1, msg2)
{	
	document.getElementById("content2").style.display="none";

	if ( isOwner )
	{
		document.getElementById("content1").innerHTML = 
			"<h1 style='padding:0px 20px;'>Welcome to Travature's Where I've Traveled Application (Version 2)</h1><br/><div style='font-size: 14px; color: #444; padding: 0px 20px;'>"+
				"A Travature account can help us display your travel preferences across multiple social networking sites and is needed to get started.<br/>"+
				"If you are an existing Travature user, don't worry, just login once and thats it. If you are a new user, please quickly register and you'll be ready to start showing off all of your travel exploits in just a few seconds.</div><br/>"+
				"<div style='float: left; line-height: 40px; font-size: 12px; border: 2px solid #D9E6F7; padding: 20px; margin: 20px; vertical-align: top;'>"+
					"<table><tr colspan='2'><td style='font-size: 12px;'>"+
					"<b style='font-size: 14px;'>For existing Travature users</b></td></tr><tr colspan='2'><td>"+
					"<span class='error'>"+msg1 + "</span><br/></td></tr><tr><td>"+
	       			"username</td><td><input class='input' type='text' name='loginname' id='loginname' value='' onkeydown='if(event.keyCode==13)login();'/></td></tr><tr><td>"+
	       			"password</td><td><input class='input' type='password' name='password' id='loginpassword' value='' onkeydown='if(event.keyCode==13)login();'/></td></tr><tr><td colspan='2'>"+
	       			"<br/><br/><center><input id='loginButton' onClick='login()' class='button' type='button' name='submit' value='Login'/></center></td></tr></table>"+
				"</div><div style='float: left; line-height: 40px; font-size: 12px; border: 2px solid #D9E6F7; padding: 20px; margin: 20px; vertical-align: top;'>"+
					"<table><tr colspan='2'><td style='font-size: 12px;'>"+
	       			"<b style='font-size: 14px;'>To create a new Travature account</b></td></tr><tr colspan='2'><td>"+
					"<span class='error'>"+msg2 + "</span><br/></td></tr><tr><td>"+
	       			"username</td><td><input class='input' type='text' name='username' id='username' value='' onkeydown='if(event.keyCode==13)account();'/></td></tr><tr><td>"+
	       			"email address</td><td><input class='input' type='text' name='email' id='email' value='' onkeydown='if(event.keyCode==13)account();'/></td></tr><tr><td>"+
	       			"password</td><td><input class='input' type='password' name='password1' id='password1' value='' onkeydown='if(event.keyCode==13)account();'/></td></tr><tr><td>"+
	       			"password again</td><td><input class='input' type='password' name='password2' id='password2' value='' onkeydown='if(event.keyCode==13)account();'/></td></tr><tr><td colspan='2'>"+
	       			"<br/><br/><center><input id='createButton' onClick='account()' class='button' type='button' name='submit' value='Create Account'/></center></td></tr></table>"+
				"</div>";
		
		gadgets.window.adjustHeight();			      
	}
	else
		document.getElementById("user").innerHTML = "<h1>Welcome to Travature's Where I've Traveled Application</h1><br/>"+
			"Click <a target='_top _blank' href='"+appUrl+"'>here</a> to go to your Where I've Traveled Application page.";
}

function login()
{
	document.getElementById("loginButton").value = "Logging in...";
	
	var loginname = document.getElementById("loginname").value;
	var loginpassword = document.getElementById("loginpassword").value;
	
	if ( loginname == "" )
		printAccountPage("<font color='red'>Please enter login name.</font><br/>","");
	else if ( loginpassword == "" )
		printAccountPage("<font color='red'>Please enter password.</font><br/>","");
	else
		makeCachedRequest(requestUrl + "login.php", 
			function(response){processLogin(response, loginname);}, 
			{'METHOD' : gadgets.io.MethodType.POST, 
			 'POST_DATA':"site="+site+"&uid="+user_id+"&username="+loginname+'&password='+loginpassword, 
			 'CONTENT_TYPE':gadgets.io.ContentType.TEXT}, 
			refreshInterval
		);	 
}

function processLogin(response, loginname)
{
	if ( response.data == "OK" )
	{
		var title = "";
		var body = "";
		
		if (site == "hi5" || site == "fanbox") 
		{
			title = owner_name + " is showing off places traveled to using <a href='"+appUrl+"'>Where I've Traveled</a>.";
			body = "Click more to see where " + owner_name + " has traveled to.";
		}
				
		sendActivity(title, body, "");
		username = loginname;
		printMapPage();
	}	
	else
		printAccountPage(response.data, "");
}

function account()
{
	document.getElementById("createButton").value = "Creating account...";
	
	var name = document.getElementById("username").value;
	var email = document.getElementById("email").value;
	var password1 = document.getElementById("password1").value;
	var password2 = document.getElementById("password2").value;
	
	if ( name == "" )
		printAccountPage("","<font color='red'>Please enter user name.</font><br/>");
	else if ( email == "" )
		printAccountPage("","<font color='red'>Please enter email address.</font><br/>");
	else if ( password1 == "" )
		printAccountPage("","<font color='red'>Please enter password.</font><br/>");
	else if ( password2 == "" )	
		printAccountPage("","<font color='red'>Please retype pasword.</font><br/>");	
	else if ( password1 != password2 )	
		printAccountPage("","<font color='red'>Both passwords do not match.</font><br/>");
	else	
		makeCachedRequest(requestUrl + "account.php", 
			function(response){processAccount(response, name);}, 
			{'METHOD' : gadgets.io.MethodType.POST,
			 'POST_DATA':"site="+site+"&uid="+user_id+"&username="+name+'&email='+email+
			 '&password1='+password1+'&password2='+password2, 
			 'CONTENT_TYPE':gadgets.io.ContentType.TEXT
			},
			refreshInterval
		);
}

function processAccount(response, name)
{
	if (response.data == "OK") 
	{
		var title = "";
		var body = "";
		
		if (site == "hi5" || site == "fanbox") 
		{
			title = owner_name + " is showing off places traveled to using <a href='"+appUrl+"'>Where I've Traveled</a>.";
			body = "Click more to see where " + owner_name + " has traveled to.";
		}
	
		sendActivity(title, body, "");
		username = name;
		printMapPage();
	}	
	else
		printAccountPage("", response.data);
		
}
/********************************************************* end create account  / login functions *********************************************************/

/********************************************************* map page functions *********************************************************/
function printMapPage()
{
	document.getElementById("content1").style.display="none";
	document.getElementById("content2").style.display="block";
	
	if(isOwner)
	{
		document.getElementById("bottombar").style.display="block";
	
		if ( (site == "hi5") && user_data != null)
			convertMarkers();			
	}
	
	if ( site == "myspace")
	{
		//update username and myspace_id
		url = requestUrl + "checkuser.php?site="+site+"&username="+username+"&userid="+user_id;
		makeCachedRequest(url, function(){processPrintMapPage()}, null, refreshInterval);
		
	}
	else	
		processPrintMapPage(); 
}

function processPrintMapPage()
{
	map = new google.maps.Map2(document.getElementById("map"));
	//gadgets.window.adjustHeight(870);
	map.setCenter(new google.maps.LatLng(20,10), 1);		
	map.addControl(new google.maps.SmallMapControl());		
	map.addControl(new google.maps.MapTypeControl());
	map.setMapType(G_HYBRID_MAP);
	
	//Get Saved Markers
	url = requestUrl + "traveled2.php?site="+site+"&get=1&nocache="+Math.floor(Math.random()*5)+"&username="+username;
	makeCachedRequest(url, processGetMarkers, null, refreshInterval);
	
	gadgets.window.adjustHeight(); 
}


function displayMarkers()
{
	var markers = getPageSavedMarker();
	
	if ( markers != null )
	{	
		for ( var i = 0; i < markers.length; i ++ )
		{
			map.addOverlay(createMarker(markers[i].lat, markers[i].lon, markers[i].id));
			
			if ( isOwner )
			{
				//check if any browse checkboxes get checked
				for (var j=0; j <brwsmarker.length; j++)
				{
					if(markers[i].id == brwsmarker[j].id)
						document.browse[j].checked = true;
				}
			}	
		}			
	}
}

//given a id, locate the guide from the current list, if exist, check the box
function checkOrNot(id)
{
	for (var j=0; j <brwsmarker.length; j++)
	{
		if(id == brwsmarker[j].id)
			document.browse[j].checked = true;
	}
}

//get whatever saved markers we have for the user
//markers exist, moved to db
function convertMarkers()
{	
	var gids = "";
	owner_data = user_data[owner_id];

	//convert from serialized string to json object
	if(owner_data != null)
	{
		if ( owner_data["country"] != null )
		{
			//get country gid
			jsonmarker = gadgets.util.unescapeString(owner_data["country"]);
			var markers = eval('(' + jsonmarker + ')');
						
			//check for markers on this pagetype
			if(markers != null)
			{
				//loop through all markers
				for (var i=0; i < markers.length; i++)
				{
					gids += markers[i].id.toString()+",";
				}
			}
		}
		if ( owner_data["state"] != null )
		{
			//get state gid
			jsonmarker = gadgets.util.unescapeString(owner_data["state"]);
			markers = eval('(' + jsonmarker + ')');
						
			//check for markers on this pagetype
			if(markers != null)
			{
				//loop through all markers
				for (var i=0; i < markers.length; i++)
					gids += mymarkers[i].id.toString()+",";
			}
		}	
		
		if ( owner_data["city"] != null )
		{
			//get city gid
			jsonmarker = gadgets.util.unescapeString(owner_data["city"]);
			markers = eval('(' + jsonmarker + ')');
						
			//check for markers on this pagetype
			if(markers != null)
			{
				//loop through all markers
				for (var i=0; i < markers.length; i++)
					gids += mymarkers[i].id.toString()+",";
			}
		}	
		
		gids = gids.substring(0,gids.length);
		
		//send data to server to add to db
		makeCachedRequest(requestUrl+"places.php?site="+site+"&username="+username+"&gids="+gids, 
			function(){return;}, 
			null,
			refreshInterval
		);
		
		//remove all data now
		removeAll();
	}	
}

/********************************************************* end map page functions *********************************************************/

/********************************************************* add by typing functions *********************************************************/

//called when user types in new place
function search()
{
	var address = document.getElementById("address").value;
	makeCachedRequest(requestUrl+"traveled2.php?site="+site+"&level="+pagelevel+"&place="+address.replace(' ','_')+"&username="+username, 
		processSearch, 
		null,
		refreshInterval
	);  
}
	
function processSearch(response)
{
	if ( response.data == "duplicate" )
		alert("You have added this location already.");
	else if ( response.data == "not found")
		alert("Location not found.");
	else
	{
		
		var xml = GXml.parse(response["data"]);
		var places = xml.documentElement.getElementsByTagName("place");
		if( places.length != null )
		{
			//since now it is only getting the very first place, duplicate is checked in travled2.php
			
			//add to map
			map.addOverlay(createMarker(places[0].getAttribute("lt"), places[0].getAttribute("ln"), places[0].getAttribute("id")));
			
			//check against browse list
			checkOrNot(places[0].getAttribute("id"));
			
			var markers = getPageSavedMarker();
			var marker = new Object();
			marker.lat =  places[0].getAttribute("lt");
			marker.lon =  places[0].getAttribute("ln");
			marker.id = places[0].getAttribute("id");			
			markers[markers.length] = marker; 
						
			//send out notification
			doActivityStream();
			
            //if fanbox throw confirmation + invite window
            if ( site == "fanbox")
                ShowDialog();
            
			//reset address
			document.getElementById("address").value="";	
		}
	}
}

/********************************************************* end add by typing functions *********************************************************/
/********************************************************* add by clicking functions *********************************************************/

function browseplc(boxnum)
{
	if(document.browse[boxnum].checked == true)
	{
		//check against duplicate first	
		var markers = getPageSavedMarker();
		
		added = false;
		for ( var j = 0; j < markers.length; j ++ )
		{
			if ( markers[j].id == brwsmarker[boxnum].id )
			{
				added = true;
				break;
			}
		}
	
		if ( !added )
		{
			//add to map
			map.addOverlay(createMarker(brwsmarker[boxnum].lat, brwsmarker[boxnum].lon, brwsmarker[boxnum].id));

			var marker = new Object();
			marker.lat =  brwsmarker[boxnum].lat;
			marker.lon =  brwsmarker[boxnum].lon;
			marker.id = brwsmarker[boxnum].id;			
			markers[markers.length] = marker; 
			
			//add place to db
			makeCachedRequest(requestUrl+"traveled2.php?site="+site+"&gid="+brwsmarker[boxnum].id+"&username="+username, 
				function(response){return;}, 
				null,
				refreshInterval
			);
            
            //if fanbox throw confirmation + invite window
            if ( site == "fanbox")
                ShowDialog();
	
			//send out notification
			doActivityStream();
		}
	}
	else
		removeMarker(brwsmarker[boxnum].id);
}

//paginate browse boxes
function browsepgnt(next)
{
 	//paginate forward/backward
	if(next == 0)
		browsepage--;
	else
		browsepage = browsepage+1;
	
	//reset if before first page
	if(browsepage < 0)
		browsepage=0;
	
	//show previous if page 1 or more, otherwise hide	
	if(browsepage > 0)
		document.getElementById("back").style.display="inline";
	else
		document.getElementById("back").style.display="none";
	
	if ( pagetype == "country" )
		lastPage = pageCountry-1;
	else if ( pagetype == "state")
		lastPage = pageState-1;
	else
		lastPage = pageCity-1;		
		
	if (browsepage == lastPage)
		document.getElementById("more").style.display="none";
	else
		document.getElementById("more").style.display="inline";
	
	//get next 10 from server
	var response;
	gadgets.io.makeRequest(requestUrl+"places.php?site="+site+"&pg="+(browsepage*10)+"&type="+pagetype+"&nocache="+Math.floor(Math.random()*7),
		function(response) 
		{	
			var xml = GXml.parse(response["data"]);
	  		var places = xml.documentElement.getElementsByTagName("place");
		
			//double check not at end
			if( places.length != null)
			{
				var markers = getPageSavedMarker();
				
				for (var i=0; i < places.length; i++)
				{ 
			 		brwsmarker[i].lat = places[i].getAttribute("lt");
					brwsmarker[i].lon = places[i].getAttribute("ln");
					brwsmarker[i].id = places[i].getAttribute("id");
					brwsmarker[i].name = places[i].getAttribute("n");
					document.getElementById('plc'+i).innerHTML = brwsmarker[i].name;
					document.browse[i].disabled=false;
					document.browse[i].checked=false;
						
					for ( var j = 0; j < markers.length; j++ )
					{
						//alert(markers[j].id + " VS " + brwsmarker[i].id);
						if(markers[j].id == brwsmarker[i].id)
							document.browse[i].checked = true;
					}
			
			 	}
				
				for ( var i = 9; i >= places.length; i-- )
				{
					document.getElementById('plc'+i).innerHTML = " &nbsp; ";
					document.browse[i].disabled = true;
				}
			}
			else
			{
				browsepage = 0;
			}
			
		},{'HEADERS' : {"Cache-Control":"No Cache"}}
	); 
}



/********************************************************* end add by clicking functions *********************************************************/
/********************************************************* remove marker functions *********************************************************/

//remove a marker
function removeMarker(id)
{
	var markers = getPageSavedMarker();
	for (var i=0; i < markers.length; i++)
	{
		if(markers[i].id == id)
			markers.splice(i,1);
	}
	
	//uncheck current box if same id
	for ( var i = 0; i < brwsmarker.length; i ++ )
		if ( id == brwsmarker[i].id )
			document.browse[i].checked = false;
	
	//save changes in db
	makeCachedRequest(requestUrl+"traveled2.php?site="+site+"&remove=1&gid="+id+"&username="+username, 
		function(response){return;}, 
		null,
		refreshInterval
	);
	
	//refresh map
	map.clearOverlays();  //clear out the map
	displayMarkers(); //add new markers
}

//now used to remove all presistent data after  data have been moved to db
function removeAll()
{
	mymarkers = [];
	var req = opensocial.newDataRequest();
	req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER, "state", mymarkers), "stat1");
	req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER, "country", mymarkers), "stat2");
	req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER, "city", mymarkers), "stat3");
	//req.send(function(){alert("all markers removed");});
	req.send(function(){return;});
}
/********************************************************* end remove marker functions *********************************************************/


/********************************************************* other functions *********************************************************/

//changes page type
function changeType(pt)
{
	//change top bar
	var pelmnt = document.getElementById('topbar');
	var elChild = pelmnt.firstChild;
	while(elChild) 
	{
		if(elChild.nodeType==1) 
		{
			elChild.className="unsel";
		}
		elChild = elChild.nextSibling;
	}
	elmnt=document.getElementById(pt);
	elmnt.className="sel";
	
	pagetype = pt;
	//browsepage = 0;
	
	//redraw map for new page
	if(pt == "country" || pt == "state" || pt == "city")
	{
		if ( site != "orkut" && site != "fanbox")
			document.getElementById('gadsense').style.display = "block";
		document.getElementById('stuff').style.display = "block";
		document.getElementById('map').style.display = "block";
		document.getElementById("info").style.display="none";			
		map.clearOverlays();
				
		if (pt == "city")
		{
			pagelevel = 3;
			map.setCenter(new google.maps.LatLng(20,10), 1);
			if(isOwner)
			{
				document.getElementById("browsem").innerHTML = "Browse World Cities";
				document.getElementById("addnew").innerHTML = "Add another city";
				document.getElementById("bottombar").style.display="block";
			}
		}
		else if (pt == "state")
		{
			pagelevel = 2;
			map.setCenter(new google.maps.LatLng(37,-95), 3);
			if(isOwner)
			{
				document.getElementById("browsem").innerHTML = "Browse U.S. States";
				document.getElementById("addnew").innerHTML = "Add another state";
				document.getElementById("bottombar").style.display="block";
			}
		}
		else if (pt == "country")
		{
			pagelevel = 1;
			map.setCenter(new google.maps.LatLng(20,10), 1);
			if(isOwner)
			{
				document.getElementById("browsem").innerHTML = "Browse Countries";
				document.getElementById("addnew").innerHTML = "Add another country";
				document.getElementById("bottombar").style.display="block";
			}
		}
		
		displayMarkers();
		
		if ( isOwner )
		{		
			browsepage = -1;
			browsepgnt(1);
		}	
		
	}
	else if (pt == "settings")
	{
		opensocial.requestShareApp(opensocial.DataRequest.Group.VIEWER_FRIENDS, 
			opensocial.newMessage('Check out all of the places I have traveled to on My Where Ive Traveled map.  I think you should also get your own map going, to start showing off all of the cities, states and countries youve visited!'));			
	}
	else if (pt == "help")
	{
		if ( site != "orkut" && site != "fanbox")
			document.getElementById('gadsense').style.display = "none";
		document.getElementById('stuff').style.display = "none";
		document.getElementById('info').innerHTML=
			"<h2>How Do I add a newly visited City/State/Country to my map?</h2>"+
			"<p>At the bottom of the map their is an input box to add a new place. "+
			"The new marker should show up instantly.</p>"+
			"<h2>There is no place at the bottom of the map to add a marker.</h2>"+
			"<p>Make sure you are on your own version of the Where I've Traveled app. "+
			"If you are looking at a friends app then you won't be able to add any new places because thats his map."+
			" You just need to install and go to your own map!</p>"+
			"<h2>I got an error saying the place wasn't found when I tried to add a new marker.</h2>"+
			"<p>Make sure you spelled the place correctly.  If you are sure about your place it may be our bad. "+
			" We don't yet have every city in the world in our system yet (though every country and state should be)."+
			" If you think there is a city we missed let us know. In the future we'll be making a way for you to "+
			"add new cities yourself.</p>"+
			"<h2>I have more questions that this FAQ didn't answer.</h2>"+
			"<p>Thats cool, shoot us an email at <a href='mailto:"+site+"@travature.com'>"+site+"@travature.com</a> "+
			"and we'll get back to you as soon as possilbe.</p>"+
			"<h2>Who made this app and why?</h2>"+
			"<p>The groovy develpment team at <a href='http://www.travature.com' TARGET='_top'>Travature.com</a> "+
			"created this app because we are just a bunch of travelers like you that want to show off where we've "+
			"traveled.  Come pay us a visit and check out our online travel community where you can compare fares for flights, hotels, and car rentals, plus "+
			"get great packaged deals voted found by other travelers, review restaurants and hotels, and access completely free travel guides with videos and photos all shared by other like minded globe trotters.</p>";
		document.getElementById('info').style.display = "block";
	}
}

//create activity stream when you add a new place
function doActivityStream()
{
	var today=new Date();
	var title = owner_name + " just added a new " + pagetype +" visited ("+(today.getMonth()+1)+ "/"+ today.getDate() + "/" + today.getFullYear() + " )";
	var body = "Click more to check out the full travel map!";
	sendActivity(title,body);
}

function sendActivity(title, body)
{
	var params = {};
	params[opensocial.Activity.Field.TITLE] = title;
	params[opensocial.Activity.Field.BODY] = body;
	if ( site == 'hi5' || site == "fanbox" )
		params[opensocial.Activity.Field.STREAM_FAVICON_URL] = "http://www.travature.com/images/wheretraveledl.png";
		
	var activity = opensocial.newActivity( params );
	opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH);
}

/********************************************************* end other functions *********************************************************/

google.setOnLoadCallback(initialize);