﻿var map = null;
var locationid = "0";
var pagenam = "";
var oGSmallZoomControl = new GSmallZoomControl3D();
var oGMapTypeControl = new GMapTypeControl();

var baseIcon = new GIcon();
baseIcon.shadow = "http://media.ombrosbrands.com/Markers/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);


var myPano;   
var panoClient;
var nextPanoId;

function setupmap(lat, lng, showads)
{
    map = new GMap2(document.getElementById("mapContainer"));
    
    map.addControl(oGSmallZoomControl);
    map.addControl(oGMapTypeControl);
    
    //Prevent zoomout
    var mt = map.getMapTypes();
    for (var i=0; i<mt.length; i++)
    {
        mt[i].getMinimumResolution = function() {return 12;}
    }
    
    //this.map.disableDragging();
    this.map.disableInfoWindow();
    
    this.map.setCenter(new GLatLng(lat, lng), 16);
    
    var icon = new GIcon(baseIcon);
    icon.image = "http://media.ombrosbrands.com/Markers/markerx.png";
    
    var markeropts = new Object;
    markeropts.icon = icon;
    
    var marker = new GMarker(new GLatLng(lat, lng), markeropts);
    
    this.map.addOverlay(marker);
    
    if (showads == true)
    {
        var publisherID = 'pub-6818287547163744';
        var adsManagerOptions = {
        maxAdsOnMap : 1,
        style: 'adunit',
        channel: '5369817147'
        };
        adsManager = new GAdsManager(map, publisherID, adsManagerOptions);
        adsManager.enable();
    }
     
//    if (document.getElementById('mapstreetview'))
//    {
//        $(document).ready
//        (
//            function()
//            { 
//                panoClient = new GStreetviewClient();
//                var svGLatLng = new GLatLng(lat, lng);
//                myPano = new GStreetviewPanorama(document.getElementById("mapstreetview"));  
//                myPano.setLocationAndPOV(svGLatLng);  
//                GEvent.addListener(myPano, "error", handleStreetViewError);    
//                panoClient.getNearestPanorama(svGLatLng, showStreetView);
//            }
//        );
//    }
}

function showStreetView(panoData) 
{
    if (panoData.code == 200) 
    {    
        $('#mapstreetview').show('slow');
        return;  
    }
    else
    {
        return;
    }
    
    nextPanoId = panoData.links[0].panoId;

    myPano.setLocationAndPOV(panoData.location.latlng);
}


function showloading()
{
    document.getElementById("LoadingWindow").style.visibility = "visible"
}

function hideloading()
{
    document.getElementById("LoadingWindow").style.visibility = "hidden"
}


function verifyLocation()
{
    GDownloadUrl("restHandler.ashx?method=VerifyLocation&LocationID=" + this.locationid, function(data, responseCode)
    { });
}


function reportLocation()
{
    showModalWindow("Report a Problem", "<div style=\"padding: 12px;\"><iframe src=\"Location_Report_Popup.aspx?LocationID=" + this.locationid + "\" width=100% height=\"300\" frameborder=0 align=middle>loading...</iframe></div>", 340, 440);
}


function sendEmailFriend()
{
    showModalWindow("Email a friend", "<div style=\"padding: 12px;\"><iframe src=\"Location_EmailFriend_Popup.aspx?LocationID=" + this.locationid + "\" width=100% height=\"330\" frameborder=0 align=middle>loading...</iframe></div>", 370, 440);
}


function createPageLink()
{
    showModalWindow("Link to this page", "<div style=\"padding: 12px;\"><img align=\"middle\" src=\"images/icon_link32.gif\" /><span class=\"headerRed\">Create a link to this page</span><br /><br /><span style=\"color: #555555;\" class=\"standardm1\">If you would like to create a link to this page simply copy the entire URL below.</span><br /><br /><textarea name=\"link\" rows=\"6\" cols=\"20\" class=\"standardm1\" style=\"width:370px;\">" + window.location.href + "</textarea></div>", 230, 410);
}


function flagComment(locationcommentid)
{
    showModalWindow("Report this comment", "<div style=\"padding: 12px;\"><iframe src=\"Location_FlagComment_Popup.aspx?LocationCommentID=" + locationcommentid + "\" width=100% height=310 frameborder=0 align=middle>loading...</iframe></div>", 380, 440);
}


function addTag()
{
    showModalWindow("Add a new tag", "<div style=\"padding: 12px;\"><iframe src=\"Location_AddTag_Popup.aspx?LocationID=" + locationid + "\" width=100% height=100% frameborder=0 align=middle>loading...</iframe></div>", 220, 440);
}



