      function trackIsLoaded() {
          if (currentTrack.loadedCorrectly()) {
      	    //alert("Trip is loaded.");
      	  	map.addOverlay(currentTrack);
          	currentTrack.gotoDefaultViewport(map);
  	  	  } else {
		  	alert("Unable to load trip route.");
  	  	  }
      }

	function renderTripList(tripList) {
		var tripListDiv = document.getElementById("news-box");
		var content = "";
		for (tripItem in tripList)
		{
			content = renderTripListItem(tripList[tripItem]) + content; //desc
			//content = content + renderTripListItem(tripList[tripItem]); //asc
		}
		tripListDiv.innerHTML = content;
	}

	//TODO: Trip repository and search engine - Fetched from various services
	function renderTripListItem(tripItem) {
		var content = "<div class=\"tripItem\">\n" +
			"<h3><a href=\"javascript:highlightTrip(" + tripItem[0] + ");\">" +
			tripItem[1] + "</a></h3>\n" +
			"<p>" + tripItem[3] + "</p>" +
			"<p>" + tripItem[4] + "</p>" +
			"<p>" +
			jsmsgs_indexTripLastUpdate +
			tripItem[5] + "</p>" +
			"<p class=\"more\"><a href=\"detail.jsf?id=" + tripItem[0] + "\">" +
			jsmsgs_indexTripDetail +
			"</a></p>\n" +
			"</div>";
		return content;
	}

	function highlightTrip(tripId) {
		if (tripId > 6) {
			alert("This trip is currently under construction. Plaese check back later");
			return;
		}
		// Show trip route
		//var trackHiglightFile = kmlRepository + tripList[tripId][2] + "-route.kmz";
		//alert(trackHiglightFile);
		//currentTrack = new google.maps.GeoXml(trackHiglightFile, trackIsLoaded);

		highlightTripPhotos(tripId);
	}



	function highlightTripPhotos(tripId) {
		// Load pic from PicasaWeb highlight
		var highlightImages = $(".highlight_image");
		//highlightImages.remove();
		//highlightImages.append('<span class="Loader"></span>');

		var feed  = tripList[tripId][6];
		var highlightPhotoFeed = new google.feeds.Feed(feed);

		highlightPhotoFeed.setNumEntries(5);
		highlightPhotoFeed.load(function(result) {
			if (!result.error) {
				//alert("PicaWeb pictures fetched.");
				var highlightImages = $(".highlight_image");
				//var container = document.getElementById("gallery");
				//TODO: from second picture
				for (var i = 0; i < result.feed.entries.length; i++) {
					var entry = result.feed.entries[i];
					var image = $(highlightImages.get(i));
					//image.replaceWith(placePhotoEl(entry));
					updateHighligtPhoto(entry, image, tripId);
					//image.find('.Loader').replaceWith('<span>' + i + "/" + result.feed.entries.length + "</span>");
					//placePhotoEl(entry).appendTo( container ).find('.Loader').remove();
				}

				//Handling the first larger photo text and overall trip info

				//hi-res
				var hImage = $('.highlight_image > img:first');
				var url = hImage.attr('src');
				url = url.replace('s288', 's400');
				hImage.attr('src', url);
				$('#higlight_desc1').text(result.feed.entries[0].title);
				//var tripDescritptionSentences = result.feed.description.split(".");
				//$('#highlight_text').html('<b>' + tripDescritptionSentences.shift() + '</b><br/>' + tripDescritptionSentences.join('.'));
				$('#highlight_text').html('<b>' + result.feed.description + '</b><br/>');
				$('#higlight_click_here').attr('href', 'detail.jsf?id=' + tripList[tripId][0]);
				$('#tripName').text(tripList[tripId][1]);

			} else {
				alert("Error fetching highlight photos from PicasaWeb");
			}
		});
	}

	// Update Image
	function updateHighligtPhoto( entry, containerImage, tripId ) {
		// new Image from gallery
		var picasaImg = $(entry.content).find('img');

		//hi-res
		//var picasaImg = $(entry.content).find('media:content');
		var currentImage = $(containerImage).find('img');
		//alert(picasaImg.attr('src'));
		currentImage.attr('src', picasaImg.attr('src'));
		currentImage.attr('alt', entry.title);
		containerImage.attr('href', 'detail.jsf?id=' + tripId);

		var description = $(containerImage).find('.highlight_desc');
		description.text(entry.title);
	}

	function placePhotoEl( entry ) {

		var link, img;
		img = $(entry.content).find('img');
		img.attr( 'alt', entry.title );
		link = $('<a></a>').append( img );
		link.attr( 'href', entry.link );
		return link;
	}

