
function jpstart(){
	 jQuery("#first").html('<img alt="Content Loading" src="../loading.gif" />');
}

function jpfinish(){
	 jQuery("#first").remove();
}

$(function(){
	 $("#second").jParse({
		  ajaxOpts: {url: "http://www.motoblog.it/rss2.xml"},
		  elementTag: ["title", "link", "description", "slash:comments", "comments"],
		  output: ' <div class="feed-entry"><h4><a href="jpet01">jpet00</a></h4><p><a href="jpet4">jpet03 Comment(s)</a><p>jpet02</p></p></div>',
		  precallback: jpstart,
		  callback: jpfinish
	 });
});



$(function() {

var tabContainers = $("div.tabs > div");
tabContainers.hide().filter(":first").show();
$("div.tabs ul.tabNavigation a").click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$("div.tabs ul.tabNavigation a").removeClass("selected");
				$(this).addClass("selected");
				return false;
			}).filter(":first").click();


 Date.format = "yyyy/mm/dd";
 $("#race_datepicker").datePicker({
	createButton:false,
	clickInput:true
 });
});



var timeout			= 500;
var closetimer	 = 0;
var ddmenuitem		= 0;

function jsddm_open()
{ jsddm_canceltimer();
  jsddm_close();
  ddmenuitem = $(this).find("ul").eq(0).css("visibility", "visible");}

function jsddm_close()
{ if(ddmenuitem) ddmenuitem.css("visibility", "hidden");}

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{ if(closetimer)
  { window.clearTimeout(closetimer);
	 closetimer = null;}}

$(document).ready(function()
{ $("#jsddm > li").bind("mouseover", jsddm_open);
  $("#jsddm > li").bind("mouseout",  jsddm_timer);

});

document.onclick = jsddm_close;




 var map=null;
  var lastVideos = null;
  var lastVideos2 = null;
  var lasBounds = null;
  var lastCenter = null;
  var geocoder=null;

	 function load() {
		if (GBrowserIsCompatible()) {
		  map = new GMap2(document.getElementById("mapvelox"));
		  map.addControl(new GLargeMapControl());
	 map.addControl(new GMapTypeControl());
		  map.addControl(new GOverviewMapControl());
				 map.addControl(new google.maps.LocalSearch(
				{
				  // resultList : document.getElementById("results")
				}),
				new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0,-30)));

		  //map.setCenter(new GLatLng(41.87194, 12.56738), 5);
		  map.setCenter(new GLatLng(45.577042,9.166718), 11);
		  map.enableScrollWheelZoom();


updateVideos();

  GEvent.addListener(map, "moveend", updateVideos);
  GEvent.addListener(map, "zoomend", updateZoom);

GSearch.setOnLoadCallback(load);

}

}
 function updateVideos() {
var bounds = map.getBounds();
			var center = bounds.getCenter();
		var span	= bounds.toSpan();

		if (lastCenter) {
		  var deltaX  = Math.abs(center.lng() - lastCenter.lng());
		  var deltaY  = Math.abs(center.lat() - lastCenter.lat());

		  var boundsX = span.lng();
		  var boundsY = span.lat();

		  if ((deltaX < 0.4*boundsX) && (deltaY < 0.4*boundsY)) {
			 return;
		  }
		}

		if (lastVideos2) {
		  map.removeOverlay(lastVideos2);
		}

		var bbox = formatBbox(bounds);
		var Videos = new GGeoXml("http://www.videomap.it/kml/control.php?" + bbox);
		map.addOverlay(Videos);

		lastVideos2 = lastVideos;
		lastVideos = Videos;

		lastCenter = center;
		lastBounds = bounds;

  }

function updateZoom(bounds) {
	 lastCenter = null;
	 updateVideos();
  }



  function formatBbox(bounds) {
	 var tipo = document.getElementById("controllo");
	 var sw = bounds.getSouthWest();
	 var ne = bounds.getNorthEast();
	 return "yinf=" + sw.lng() + "&" + "xinf=" + sw.lat() + "&" + "ysup=" + ne.lng() + "&" + "xsup="+ ne.lat()+ "&" + "control="+ tipo.value;
  }

