﻿// JScript File

function drawCircle(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa)
{
// Esa 2006
    //calculating km/degree
    var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100;
    var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100;

    //Loop 
    var points = [];
    var step = parseInt(360/nodes)||10;
    for(var i=0; i<=360; i+=step)
    {
        var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng() + (radius/lngConv * Math.sin(i * Math.PI/180)));
        points.push(pint);
        //bounds.extend(pint); //this is for fit function
    }
    points.push(points[0]); // Closes the circle, thanks Martin
    fillColor = fillColor||liColor||"#0055ff";
    liWidth = liWidth||2;
    var poly = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa);
    map.addOverlay(poly);
}

   
function showAddress(i) {
    GEvent.trigger(gmarkers[i], "click");
}

var home_set = null;

function loadAddress(g_index, container, title, address, description, lat, lng, ishome) {
    var point = new GLatLng(lat,lng);
    title = title.replace(/'/g,"");
    //check to see if point is the center.  if so, use the home icon and render the circle
    if (!home_set)
    {
        map.setCenter(point, 14);
        //use home icon
        /*var icon = new GIcon();
        icon.image = "http://ampedup.ecityinteractive.com/marker.png";
        icon.iconSize = new GSize(20, 34);
        icon.iconAnchor = new GPoint(9, 34);
        icon.infoWindowAnchor = new GPoint(5, 1);*/
        var marker = new GMarker(point);
        //drawCircle(point, '1.61', '100');

        home_set = "yes";

        //place radius image
        //var myRadius = new GIcon();

        //myRadius.image = "http://ampedup.ecityinteractive.com/radius_1.png";
        //myRadius.iconSize = new GSize(220, 220);
        //myRadius.iconAnchor = new GPoint(110, 110);

        //var myRadiusMarker = new GMarker(point, myRadius);
        //map.addOverlay(myRadiusMarker);  
    }
    else
    {
        var marker = new GMarker(point);              
    }  

    //Display info box onclick
    GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("<div style='float:left; margin-right:4px'>"+description+"</div><b>" + title + "</b><br/><p style='text-align:left'>" + address+"</p>" );
    });

    gmarkers[g_index] = marker;
    bounds.extend(point);
    //add marker to map
    map.addOverlay(marker);
    map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

    if(container != "none")
        document.getElementById(container).innerHTML += "<a href='javascript:showAddress(" + g_index + ");'>" + title + "</a>";
    delay_time = delay_time + 100;
}

jQuery(function( $ ){
    //borrowed from jQuery easing plugin
    //http://gsgd.co.uk/sandbox/jquery.easing.php
    $.scrollTo.defaults.axis = 'xy'; 
    $.easing.elasout = function(x, t, b, c, d) {
	    var s=1.70158;var p=0;var a=c;
	    if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	    if (a < Math.abs(c)) { a=c; var s=p/4; }
	    else var s = p/(2*Math.PI) * Math.asin (c/a);
	    return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    };
});
