var all_items = new Array();
var map;
var home_center;
var home_zoom;
var select_marker_api;
var marker_counter;
var geonames_marker_counter;
var geonames_center_lat;
var geonames_center_lng;
var global_media_url;
var global_pano_media_url;
var hotels_marker_counter;
var SIGNAL = 0;
var STREET_VIEW_ACTIVED = false;
function load_mabs_map(api, size, map_sat_hyb_ge, controlcm, controlcs, controlct, color){
    /*
        This function is hacked for the intialization of the apis:
            -> google needs the points to be added last
            -> multimap needs an original point to add. AutocenterAndZoom seems not to work 
            -> freeearth does not suppor setZoom
    */
    select_marker_api = api //neccesary for Nearest items in single_item_view to call select_item(id) 
    map = new Mapstraction('map',api);
	//map.debug = true;
    pan = true;
    
    if ((home_zoom != null) || (home_zoom != 0)){ zoom = home_zoom; }else{ zoom = size;}
    scale = true;
    map_type = true;
    
    if (controlcm == null || controlcm == 0){ pan = false; zoom = '';} else { pan = true;}
    if (controlcs == null || controlcs == 0){ scale = false; } else { scale = true; }
    if (controlct == null || controlct == 0){ map_type = false; } else { map_type = true; }
	if ((api == 'multimap')|| (api == 'mapquest')) {init_point = new LatLonPoint(0,0);map.setCenterAndZoom(init_point,2);}
	if ((size != null  ) && (zoom != '')){map.addControls({ pan: true, zoom: 'large', overview: false, scale: scale, map_type: map_type}); }
	else{map.addControls({ pan: pan , zoom: zoom , overview: false, scale: scale, map_type: map_type});}
	if ((api != 'multimap')||(api != 'mapquest') || (cover_center == null)){map.autoCenterAndZoom();}
	if ((api !='mapquest')&& (api != 'freeearth')){
	    if (map.getZoom() < 1){
            map.setZoom(1);	
    	}
    }
    
    load_mabs_items(api, color);
	if (api == 'google')
	{
	    map.maps[map.api].enableScrollWheelZoom();
	     // size is a number we must parse it 
	     size = parseInt(size);  
	     // else in item view we could'nt do zoom , because zoom is undefined
	     if (size > 0){
	         map.setZoom(size);
         }     
	     if (map_sat_hyb_ge == "m"){
               map.setMapType(Mapstraction.ROAD);
          }
        else if (map_sat_hyb_ge == "s"){
              map.setMapType(Mapstraction.SATELLITE);      
          }
        else if (map_sat_hyb_ge == "h"){
               map.setMapType(Mapstraction.HYBRID); 
          }
        else if (map_sat_hyb_ge == "ge"){
               // ########################################################
               // Mapstraction functions called directly 
               //#######################################################
               map.setMapType(Mapstraction.ROAD);
               map.maps[map.api].setMapType(G_SATELLITE_3D_MAP);
          }
        else{
               map.setMapType(Mapstraction.ROAD); 
               map.maps[map.api].addMapType(G_SATELLITE_3D_MAP);
          }
	}
    $("#pastearea").click( function(){
        this.focus();
        this.select();
    });
}

function load_mabs_items(api, color){
	all_items_length = all_items.length;
	marker_counter = all_items_length;
   
	for (i=0; i< all_items_length; i++)	{
		temp = all_items[i] //.pop();
		
		if (temp instanceof Marker){
			map.addMarkerWithData(temp);
		}
		else if (temp instanceof Polyline) 
		{
			if (api!= 'freeearth')	{
			    map.addPolyline(temp);
			 }
		}
        else if (temp instanceof Polygon){
			if (api!= 'freeearth'){
			    // DON'T EXIST ADDPOLYGON in Mapstraction 
			    map.addPolyline(temp); 
            }
		}
	}
	if (home_center != null) {map.setCenterAndZoom(home_center,home_zoom); }
	else {map.autoCenterAndZoom();}
}

function load_mabs_kml(api,size,url){
    load_mabs_map(api, size);
    map.removeAllMarkers();
    map.removeAllPolylines();
    GLog.write('remove all');
    map.addOverlay("http://tagzania2.cs/kmldata/user/txus");
}


// ==================== common function for all API calls =====================
//=============================================================================

function gebi(id) {return document.getElementById(id);}

function json(url, querystring){
  var jstag=document.createElement("script");
  jstag.setAttribute("type", "text/javascript");
  jstag.setAttribute("src", url+'?'+querystring);
  document.getElementsByTagName("head")[0].appendChild(jstag);
}

//========================= bubble action ============================================
function item_openbubble(id){
    map.markers[id].openBubble();
}      

function item_closebubble(){    
    map.maps[map.api].closeInfoWindow();
}    

//==============================================================

var SAVE_ICON_SIZE = ''; // only needed in search view

function select_item(id){
    iconUrl = $("#selected_item_icon").val();  
    icon_size = [40,40]
    icon_shadow_size = [33,45]
    icon_anchor = [12,33]
    map.markers[id].setIconSize([50,50]); //setIconSize(iconUrl, icon_size);
    map.markers[id].setShadowIcon(IconUrl, icon_shadow_size);
}      

function deselect_item(id){
    if (SAVE_ICON_SIZE != ''){
        iconSize= SAVE_ICON_SIZE;
    }
    //else{
        //iconSize = new Size(27, 33);
    //}    
    map.markers[id].setIconSize(iconSize);
}              


//======================= VISIBLE FUNCTIONS ================================

function marker_visible(count){ 
    SIGNAL = 0;
    GEvent.clearListeners(map.maps[map.api], "dragend");
    all_counter = map.markers.length - 1; 
    
    for(i=0; i< count ; i++){
        map.markers[i].show();
    }
    
    all_poly_counter = map.polylines.length; 
    for(i = 0; i < all_poly_counter ;i++){
        map.polylines[i].show();
    }
     
    for(i= all_counter; i >= count ; i--){
         map.removeMarker(map.markers[i]);
    }

    all_poly_counter = map.polylines.length; 
    for(i= 0; i < all_poly_counter ;i++){
       map.polylines[i].proprietary_polyline.show();
    }
    map.autoCenterAndZoom();
    GEvent.clearListeners(map.maps[map.api], "dblclick");
}



function marker_invisible(near){
    all_poly_counter = map.polylines.length; 
    for(i = 0; i < all_poly_counter ;i++){
       map.polylines[i].hide();
    }
    
    
    if (near == true){
        // only used in near views
        all_counter = map.markers.length - 1; 
        start = 0;
    }else{
        start = 1;
        all_counter = map.markers.length - 2;
    }
    
    for(i=start; i<= all_counter; i++){
        map.markers[i].hide();
    }
}





// ------------------------ SEARCH VIEW ITEM VISIBLE CONTROL

function search_marker_visible(tz_visible_counter, tz_search_polygon_counter ){ 
    GEvent.clearListeners(map.maps[map.api], "dragend");
    all_counter = map.markers.length; 
    item_counter = tz_visible_counter;
     
    all_counter = map.markers.length; 
    for(i = 0; i < all_counter ;i++){
        map.markers[i].hide();
     }
    
    for(i= 0; i < item_counter ;i++){
       map.markers[i].show();
    }
    
    all_poly_counter = map.polylines.length; 
    for(i= 0; i < all_poly_counter ;i++){
       map.polylines[i].proprietary_polyline.show();
    }
    
    center_points = map.markers.slice(0,item_counter);
    map.centerAndZoomOnMarkers( center_points );
}

Mapstraction.prototype.centerAndZoomOnMarkers = function(markers)
{
    var bounds = new GLatLngBounds(markers[0].proprietary_marker.getPoint(), markers[0].proprietary_marker.getPoint());
    var i;
    for (i=1; i<markers.length; i++) {
        bounds.extend(markers[i].proprietary_marker.getPoint());
    }
    var lat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2.0;
    var lng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2.0;
    if(bounds.getNorthEast().lng() < bounds.getSouthWest().lng()){
      lng += 180;
    }
    var center = new GLatLng(lat,lng)
    map.maps[map.api].setCenter(center, map.maps[map.api].getBoundsZoomLevel(bounds)-1);
}


function search_marker_invisible(tz_visible_counter, user_visible_counter, user_search_polygon_counter){
     all_counter = map.markers.length; 
     for(i = user_visible_counter; i < all_counter  ;i++){
        map.markers[i].hide();
     }
     
     all_poly_counter = map.polylines.length; 
          
     for(i = user_search_polygon_counter; i < all_poly_counter ;i++){
        map.polylines[i].hide();
     }
     
     total_counter = tz_visible_counter + user_visible_counter;
    center_points = map.markers.slice(tz_visible_counter,total_counter);
    map.centerAndZoomOnMarkers( center_points );
}


function search_geonames_visible( ){ 
    GEvent.clearListeners(map.maps[map.api], "dragend");
    all_counter = map.markers.length; 
    
    for(i= 0; i < all_counter ;i++){
       map.markers[i].show();
    }
    all_poly_counter = map.polylines.length; 
    for(i= 0; i < all_poly_counter ;i++){
       map.polylines[i].proprietary_polyline.show();
    }
    map.autoCenterAndZoom();
}


function search_hotels_visible(){ 
    GEvent.clearListeners(map.maps[map.api], "dragend");
    
    all_counter = map.markers.length; 
    item_counter = all_counter - geonames_marker_counter - hotels_marker_counter;
    
    for(i = 1; i < all_counter ;i++){
        map.markers[i].hide();
     }
     
    
    for(i= 0; i < item_counter ;i++){
        map.markers[i].show();
    }
    
    start_counter = all_counter - hotels_marker_counter;
    for(i= start_counter; i < all_counter ;i++){
        map.markers[i].show();
    }
    
    all_poly_counter = map.polylines.length; 
    for(i= 0; i < all_poly_counter ;i++){
       map.polylines[i].proprietary_polyline.hide();
    }
    
    center_points = map.markers.slice(0,item_counter);
    hotels_points = map.markers.slice(start_counter, all_counter);
    
    map.centerAndZoomOnMarkers( hotels_points );
}

// ==================================================================================
//                         GEONAMES API  
//===================================================================================

function getGeonames(search_value, media_url, geonames_username) {
  global_media_url = media_url  
  gebi('places_geonames').innerHTML='<img src="'+media_url+'/img/loader.gif" ></img>';
  url = 'http://ws.geonames.org/searchJSON';
  qs = 'maxRows=10&q='+ search_value +'&callback=getGeonamesOk&username='+ geonames_username;
  //$.ajax and jetJSOn don't function to geonames for geonames json data structure! 
  json(url,qs);
}       

function getGeonamesOk(geonames) {
    
  gebi('places_geonames').innerHTML='';
  geonames_marker_counter = geonames.geonames.length;
  if (geonames.geonames.length > 0){
      for (i = 0; i < geonames.geonames.length; i++) {
        
        lat = geonames.geonames[i].lat;
        lng = geonames.geonames[i].lng;
        geonameId = geonames.geonames[i].geonameId;
        place_name = geonames.geonames[i].name;
        link_place_name = place_name.replace(" ", "%20");
        country_name = geonames.geonames[i].countryName;
        link_country_name = country_name.replace(" ", "%20");
        admin_name = geonames.geonames[i].adminName1;
        link_admin_name = admin_name.replace(" ", "%20");
        //that charge in /search/tzsearch_geonames.html
        //text = '<ul id="searchnavlist"><li><span><a class="location_link" href="/near/'+ lat+'/'+lng+'/'+geonameId+'/'+place_name +'/' + country_name + '/' +admin_name +' >'+ place_name+' ('+country_name+ ')</a></span> </li></ul>';
       text = '<ul id="searchnavlist"><li><span><a class="location_link" href="/near/'+ lat+'/'+lng+'/?place_name='+link_place_name +'&country_name=' + link_country_name + '&admin_name=' +link_admin_name +' >'+ place_name+' ('+country_name+ ')</a></span> </li></ul>';
       $(text).appendTo('#places_geonames');
       var temp;
       //alert("hastera doa:" + lat + " // " + lng);
        temp = new Marker(new LatLonPoint(parseFloat(lat),parseFloat(lng)));
        
        temp.setInfoBubble('<div ><h3><a class="location_link" href="/near/'+ lat+'/'+lng+'/?place_name='+link_place_name +'&country_name=' + link_country_name + '&admin_name=' +link_admin_name +' >'+ place_name+' ('+country_name+ ')</a></h3></div>');
        
        temp.setIcon(global_media_url + 'img/placemarkers/search.png', [19, 24], [9, 22]);
        
        temp.setShadowIcon(global_media_url + 'img/placemarkers_small/shadow.png', [27, 34]);
        
        map.addMarker(temp);
        map.autoCenterAndZoom();
      }
  }
  else{
      //if don't have results pass to nearest tagzania results
      toggleTab("nearest_places");
  }    
      geonames_center_lat = geonames.geonames[0].lat;
      geonames_center_lng = geonames.geonames[0].lng;
      
}


// ==================================================================================
//                         PANORAMIO API  
//===================================================================================
function getPanoramioOk(photos) {
    all_counter = map.markers.length-1; 
    marker_counter =  all_counter;
    gebi('photos_panoramio').innerHTML='';
   
    all_counter = map.markers.length; 
    marker_counter =  all_counter;
    
    for (i = 0; i < photos.photos.length; i++){
       obj = gebi('photos_panoramio');
       a = document.createElement('a');
       counter = marker_counter + i;
       a.href = "javascript:void(0);map.markers["+counter+"].openBubble()";
       a.onclick = "javascript:void(0);map.markers[i].openBubble()";
       p = document.createElement('span');
       title = photos.photos[i].photo_title;
       photo_title = title.toLowerCase();
       sometext = document.createTextNode(photo_title);
       p.appendChild(sometext);
       
       img = document.createElement('img');
       photo_url = photos.photos[i].photo_file_url.replace(/small/, "thumbnail")
       img.src=photo_url; //photos.photos[i].photo_file_url;    
       img.title = photos.photos[i].photo_title;
       
       obj.appendChild(a);       
       
       a.appendChild(img);
       a.appendChild(p); 
       
       createMarker(photos.photos[i], i);
    }
  
}

function getPanoramio(media_url, not_center) {
  item_closebubble();
  global_pano_media_url = media_url;
  if (not_center == null ){
      if ( home_center != null ){map.setCenterAndZoom(home_center,home_zoom);}
  }  
  bounds = map.maps[select_marker_api].getBounds();
  sw = bounds.getSouthWest();
  ne = bounds.getNorthEast();
  minlat = sw.lat();
  minlng = sw.lng();
  maxlat = ne.lat();
  maxlng = ne.lng();
    /*
      == PANORAMIO==
    for "order" you can use:
        * popularity
        * upload_date
    for "set" you can use:
        * public (popular photos)
        * full (all photos)
    for "size" you can use:
        * original
        * medium (default value)
        * small
        * thumbnail
        * square
        * mini_square
    */
  gebi('photos_panoramio').innerHTML= '<img src="'+media_url+'/img/loader.gif" ></img>';
  url = 'http://www.panoramio.com/map/get_panoramas.php';
  qs = 'order=popularity&set=public&from=0&to=20&minx='+minlng+'&miny='+minlat+'&maxx='+maxlng+'&maxy='+maxlat+'&size=small&callback=getPanoramioOk';
  json(url,qs);
}       

function createMarker(photo, i){
    temp = new Marker(new LatLonPoint( photo.latitude,photo.longitude));
    photo_url_to_post = photo.photo_file_url.replace(/small/, "medium")
    photo_url_to_bubble = photo.photo_file_url.replace(/small/, "medium")
    temp.setInfoBubble('<div class="bubble_panoramio" ><div  class ="clearfix"><img  src ="http://www.panoramio.com/img/panoramio-marker.png" heigth="10" weigth="10"> ' + photo.photo_title +'</div><a href="'+photo.photo_url+'" ><img src ="'+ photo_url_to_bubble + '" width = "' +photo.width+ '"  height = "'+photo.height+'"></img></a><p><a class="b_title" href="'+photo.photo_url +'"> <span>link</span></a> | <a class="b_title" href=\"/near/' + photo.latitude + '\/'+photo.longitude+'"><span>Search nearby</span></a> | <a class="b_title" href="/post?lat='+ photo.latitude +'&long='+photo.longitude+'&resources='+photo_url_to_post+'&title='+photo.photo_title+'"><span>add</span></a></p></div>');
 	photo.photo_file_url = photo.photo_file_url.replace(/small/, "mini_square")
	temp.setIcon(photo.photo_file_url,[44,44], [16,16]);
	map.addPanoramioMarker(temp);    
}
Mapstraction.prototype.addPanoramioMarker = function(marker) {
  var map = this.maps[this.api];
  marker.mapstraction = this;
  marker.api = this.api;
  marker.map = this.maps[this.api];
  if(this.loaded[this.api] === false) {
    self = this;
    this.onload[this.api].push( function() { self.addPanoramioMarker(marker); } );
    return;
  }

  var gpin = marker.toPanoramio();
  marker.setChild(gpin);
  map.addOverlay(gpin);
  this.markers.push(marker); 
};

Marker.prototype.toPanoramio = function() {
	
	var func_icon = new GIcon();
        func_icon.image = this.iconUrl;
        func_icon.iconSize = new GSize(44, 44);
        func_icon.shadowSize = new GSize(41, 30);
        func_icon.iconAnchor = new GPoint(6, 20);
        func_icon.infoWindowAnchor = new GPoint(5, 1);
        var options = {};
        options.icon = func_icon;
      var gmarker = new GMarker( this.location.toGoogle(),options);
	
  if(this.infoBubble){
    var theInfo = this.infoBubble;
    var event_action;
    if(this.hover) {
      event_action = "mouseover";
    }
    else {
      event_action = "click";
    }
    GEvent.addListener(gmarker, event_action, function() {
      gmarker.openInfoWindowHtml(theInfo, {maxWidth: 100});
    });
  }
	
  if(this.hoverIconUrl){
    GEvent.addListener(gmarker, "mouseover", function() {
      gmarker.setImage(this.hoverIconUrl);
    });
    GEvent.addListener(gmarker, "mouseout", function() {
      gmarker.setImage(this.iconUrl);
    });
  }
	
  if(this.infoDiv){
    var theInfo = this.infoDiv;
    var div = this.div;
    var event_action;
    if(this.hover) {
      event_action = "mouseover";
    }
    else {
      event_action = "click";
    }
    GEvent.addListener(gmarker, event_action, function() {
      document.getElementById(div).innerHTML = theInfo;
    });
  }
	
  return gmarker;
};



// ==================================================================================
//                                                                                          GEONAMES HOTELS API  
//===================================================================================
function getHotelsOk(hotels) {
    
  item_closebubble();
  all_counter = map.markers.length-1; 
  iconUrl = $("#selected_hotel_icon").val();   
  gebi('hotels_geonames').innerHTML='';
 
  bounds = map.maps[select_marker_api].getBounds();
  sw = bounds.getSouthWest();
  ne = bounds.getNorthEast();
  minlat = sw.lat()
  minlng = sw.lng()
  maxlat = ne.lat()
  maxlng = ne.lng()
  near_icon_size = [19,24]
  near_icon_shadow_size = [24,30]
  near_icon_anchor = [9,22]
  center_lat = (minlat+maxlat) /2;
  center_lng = (minlng + maxlng) /2;
  all_counter = map.markers.length; 
  marker_counter =  all_counter;
  icon_base_url = global_media_url + "/img/placemarkers_small/" 
 
 hotels_marker_counter = hotels.hotels.length;
 
  for (i = 0; i < hotels.hotels.length; i++){
     counter = all_counter + i ;
     text = '<ul id="searchnavlist"><li><span><a class="location_link" onclick = "map.markers['+counter+'].openBubble()" href="javascript:void(0);map.markers['+counter+'].openBubble()" >'+hotels.hotels[i].hotelName+' ('+hotels.hotels[i].placeName + ') '+ '</a></span> </li></ul>';
     $(text).appendTo('#hotels_geonames');
     temp = new Marker(new LatLonPoint( hotels.hotels[i].lat, hotels.hotels[i].lng));
     temp.setInfoBubble('<div class="bubble"><a href="'+hotels.hotels[i].bookingURLs[0].bookingURL+'" >'+hotels.hotels[i].hotelName + '<p><img src ="'+hotels.hotels[i].imageURL + '" width= "80" heigth = "80"></img></p></a><p>'+hotels.hotels[i].address +' (' +hotels.hotels[i].placeName +')</p><p><a href="'+hotels.hotels[i].bookingURLs[0].bookingURL+'" >See this hotel </a> | <a class="b_title" href=\"/near/' + hotels.hotels[i].lat + '\/'+hotels.hotels[i].lng +'">Search nearby</a> | <a class="b_title" href="/post?lat='+ hotels.hotels[i].lat +'&long='+hotels.hotels[i].lng +'&title='+hotels.hotels[i].hotelName +'">add</a></p></div>');
     temp.setIcon(icon_base_url + 'hotel.png', near_icon_size, near_icon_anchor);
     temp.setShadowIcon(icon_base_url +'shadow.png', near_icon_shadow_size);
     map.addMarker(temp);
  }
  link_text = '<p><em><a href="http://www.booking.com/searchresults.html?aid=316513&latitude=' + center_lat +'&longitude=' + center_lng + '&radius=50">More hotels near</a></em><br></p>';
  $(link_text).appendTo('#hotels_geonames');
  search_hotels_visible();
}

function getHotels(media_url) {
  
  global_media_url = media_url
  gebi('hotels_geonames').innerHTML='<img src="'+media_url+'/img/loader.gif" ></img>';
  bounds = map.maps[select_marker_api].getBounds();
  sw = bounds.getSouthWest();
  ne = bounds.getNorthEast();
  minlat = sw.lat()
  minlng = sw.lng()
  maxlat = ne.lat()
  maxlng = ne.lng()
  center_lat = (minlat+maxlat) /2;
  center_lng = (minlng + maxlng) /2;
  url = 'http://ws.geonames.org/findNearbyHotelsJSON' //'http://www.panoramio.com/map/get_panoramas.php';
  qs = 'lat='+center_lat+'&lng='+center_lng+'&username=luistxo&callback=getHotelsOk' //'order=popularity&set=public&from=0&to=20&minx='+minlng+'&miny='+minlat+'&maxx='+maxlng+'&maxy='+maxlat+'&size=thumbnail&callback=getPanoramioOk';
  json(url,qs);
}       

function addPanoramioListener(){
    GEvent.clearListeners(map.maps[map.api], "dragend");
    GEvent.addListener(map.maps[map.api], "dblclick", function(){ getPanoramio(global_pano_media_url, true); });
}
function addHotelsListener(){  
    GEvent.clearListeners(map.maps[map.api], "dragend");
    GEvent.addListener(map.maps[map.api], "dragend", function(){  getHotels(global_media_url); });
}



function get_street_view()
{
    //p=map.markers[3].proprietary_marker;
   // var p = new GLatLng(40.4165,-3.7025); 
  bounds = map.maps[select_marker_api].getBounds();
  sw = bounds.getSouthWest();
  ne = bounds.getNorthEast();
  minlat = sw.lat();
  minlng = sw.lng();
  maxlat = ne.lat();
  maxlng = ne.lng();
  center_lat = (minlat+maxlat) /2;
  center_lng = (minlng + maxlng) /2; 
  if (STREET_VIEW_ACTIVED != true)
  {
     if (GBrowserIsCompatible()) 
     { 
        STREET_VIEW_ACTIVED = true;
        map.maps[map.api].addOverlay(new GStreetviewOverlay()); 
        geocoder = new GClientGeocoder(); 
        var svc = new GStreetviewClient();                           
        var latlong = new GLatLng(center_lat,center_lng);   
        svc.getNearestPanorama(latlong, function(reply){
                    if (reply.code = 200) { 
                            
                            if (reply.Location) {
                                 var html = "<div class=\"header\"><b>"+reply.Location.description+"</div></b>" + "<div class=\"bubble_street_view\"><embed src=\"http://maps.google.com/mapfiles/cb/googlepano.040.swf\" quality=\"high\" bgcolor=\"#EFEFEF\" style=\"width: 100%; height: 270px;\" wmode=\"opaque\" swliveconnect=\"false\" id=\"googlepano\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noscale\" salign=\"lt\" flashvars=\"panoId="+reply.Location.panoId+"&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=350.08435065836153&amp;zoom=0&amp;browser=3&amp;serverURLPrefix=http://cbk0.google.com/cbk&amp;pitch=10.983050525042998&amp;viewHeight=0.616426117417295\" align=\"middle\"></embed></div>" + "<div class=\"footer\">Copyright: "+reply.Data.copyright+"<br></div>" ; 
                                 var pp = new GLatLng(parseFloat(reply.Location.lat),parseFloat(reply.Location.lng)); 
                                 item_closebubble();
                                 map.maps[map.api].openInfoWindowHtml(pp,html);}
                            else { }
                    } else { GLog.write("Error : "+reply.code);}
                } );            
     }
     else { alert("Sorry, the Google Maps API is not compatible with this browser");STREET_VIEW_ACTIVED = false;}
    
     var svc = new GStreetviewClient(); 
     GEvent.addListener(map.maps[map.api],"click",function(overlay,latlong) 
     { 
        if (latlong){ 
            svc.getNearestPanorama(latlong, function(reply){
                    if (reply.code = 200) { 
                            
                            if (reply.Location) {
                                 var html = "<div class=\"header\"><b>"+reply.Location.description+"</div></b>" + "<div class=\"bubble_street_view\"><embed src=\"http://maps.google.com/mapfiles/cb/googlepano.040.swf\" quality=\"high\" bgcolor=\"#EFEFEF\" style=\"width: 100%; height: 270px;\" wmode=\"opaque\" swliveconnect=\"false\" id=\"googlepano\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" scale=\"noscale\" salign=\"lt\" flashvars=\"panoId="+reply.Location.panoId+"&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=350.08435065836153&amp;zoom=0&amp;browser=3&amp;serverURLPrefix=http://cbk0.google.com/cbk&amp;pitch=10.983050525042998&amp;viewHeight=0.616426117417295\" align=\"middle\"></embed></div>" + "<div class=\"footer\">Copyright: "+reply.Data.copyright+"<br></div>" ; 
                                 var pp = new GLatLng(parseFloat(reply.Location.lat),parseFloat(reply.Location.lng)); 
                                 map.maps[map.api].openInfoWindowHtml(pp,html);}
                            else { }
                    } else { GLog.write("Error : "+reply.code);}
                } );}
     });
   } 
}
