var map;
var latlng;
var arr_points = new Array();
var arr_content = new Array();
var arr_content_simple = new Array();
var globaljson;
function handleNoFlash(errorCode) {
  
    if (errorCode == 603) {
        alert("Error: Flash doesn’t appear to be supported by your browser");
        return;
    }
    if (errorCode == 600) {
        alert("Street View Not Available For This Location");
        return;
    }

}
function initialize() {
    latlng = new google.maps.LatLng(44.929, -67.238);
    var myOptions = {
        zoom: 10,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: true
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    
}
function detailFancy()
{
 $("#mapdetails").css("display","");

    //var content = $("#pano").html();
    //$("#mapdetails").html(content);
/*    $.fancybox(
        content,
        {
            'autoDimensions'	: false,
            'width'         		: 750,
            'height'        		: 250,
            'transitionIn'		: 'none',
            'transitionOut'		: 'none'
        }
        );*/
}

function streetView()
{    
  
  document.getElementById("streetview").style.display="";
}

function attachInfowindow(marker,number, content) {

    google.maps.event.addListener(marker, 'click', function() {

        showInfoWindow(marker,number, content);

    });



}
function showInfoWindow(marker,number, content)
{
    var resultContent_= "";
    $('#pano2').show("slow");$('#streetview').hide("slow");
    if(globaljson[number].Listingid!=""){
        resultContent_ = resultContent_ + '<div style="float:left;"><strong>MLS# </strong>'+globaljson[number].Innerid+'<br />';
    }
    if(globaljson[number].Listprice!=""){
                resultContent_ = resultContent_ + '<p id="resultline'+number+'"><strong>$'+globaljson[number].Listprice+'</strong><br />';
            }
    if(globaljson[number].Address!="")
    {
        resultContent_ = resultContent_ + ''+globaljson[number].Address+'<br />';
    }
    if(globaljson[number].Beds!="" && globaljson[number].Beds!=null)
    {
        resultContent_ = resultContent_ + ''+globaljson[number].Beds+' Beds';
    }
    if(globaljson[number].Bathsfull!="" && globaljson[number].Bathsfull!=null) {
        resultContent_ = resultContent_ + ', '+globaljson[number].Bathsfull+' Baths';
    }

    if(globaljson[number].Link!="") {
        resultContent_ = resultContent_ + '<br /><a href="/'+globaljson[number].Link+'.html">View details</a>';
    }
        resultContent_ = resultContent_ + "<br /><a href=\"#\" id=\"streetviewlink\">Street view</a></div>";

      if(globaljson[number].Mainpic!="") {
        resultContent_ = resultContent_ + '<img  src="'+globaljson[number].Mainpic+'" />';
    }
    
    $("#pano2").html(resultContent_);
    $("#pano2").show("slow");
    $("#streetviewlink").click(function(){
    
    $('#pano2').hide('slow');
    setTimeout("$('#streetview').show('slow')",200);
    $('#togglestreetview').show();
    $('#togglestreetview').click(function(){
        $("#streetview").hide();
        $("#pano2").show("slow");
        $('#togglestreetview').hide();
        
        return false;
    });
    return false;
});

    
    var html = ' <div class="tabsmap" id=\"tabsmap'+number+'\" >'+content+'<!--<a href=\"#pano\" class=\"maplink\" id=\"maplink'+number+'\" onclick=\"detailFancy()\" return false;\">Expand</a>--></div></div>';
    var infowindow = new google.maps.InfoWindow(
    {
        maxWidth:500

    });

    infowindow.setContent(html);

    infowindow.open(map,marker);
    var point = new GLatLng(globaljson[number].Latitude, globaljson[number].Longitude);
    panoramaOptions = {
        latlng:point
    };
    if($("#streetview").length!=0) { 
       $("#streetview").html('');
       //$("#streetview").css('width', 280);
       //$("#streetview").css('height', 280);
         var myPano = new GStreetviewPanorama(document.getElementById("streetview"), panoramaOptions);
        GEvent.addListener(myPano, "error", handleNoFlash);
        

    }

/*    $("#streetview").hover(
    function(){
        alert('!!!');}, function(){alert('out!');}
    );*/
    
    /*$("#maplink"+number).fancybox(

        {
            'autoDimensions'	: false,
            'width'         		: 750,
            'height'        		: 250,
            'transitionIn'		: 'none',
            'transitionOut'		: 'none'
        }
        );*/
//    var tid = '#tabsmap'+number;
//        setTimeout("$('"+tid+"').tabs()",600);

}
