﻿/* 
 * Author: Steve Bumbaugh 
 * Date: November 2008
 */
function initP2PMap(name1, address1, name2, address2, mapId, distanceId, driveTimeId, width, height) {
    var mapp2p = null;
    var gdir = null;
    var url = null;
    var geocoder = null;
    var divMapId = "div" + mapId;

    // this is a hack to insert a div into the DOM, which BlogEngine.NET
    // prevents.  I was using a 'p' tag previously, but that was causing
    // JS errors in IE7.  The work around for this is to insert a span
    // into the page, that span has a div dynamically inserted into the 
    // DOM that is used to display the google map
    var div = '<div id="' + divMapId + '" style="width: ' + width + 'px; height: ' + height + 'px;"></div>';
    $j('.' + mapId).append(div);

    mapp2p = new GMap2(document.getElementById(divMapId));
    gdir = new GDirections(mapp2p, null);
    geocoder = new GClientGeocoder();
    
    GEvent.addListener(gdir, "error", function() {
        alert("Error getting directions.  Error Code: " + gdir.getStatus().code);
    });

    GEvent.addListener(gdir, "load", function() {
        if (distanceId != null) {
            $j('.' + distanceId).html(gdir.getDistance().html);
        }
        if (driveTimeId != null) {
            $j('.' + driveTimeId).html(gdir.getDuration().html);
        }
    });

    geocoder.getLatLng(address1, function(point1) {
        mapp2p.setMapType(G_PHYSICAL_MAP);
        mapp2p.addControl(new GLargeMapControl());
        mapp2p.addControl(new GMapTypeControl());

        geocoder.getLatLng(address2, function(point2) {
            var from = name1 + "@" + point1.lat() + "," + point1.lng();
            var dest = name2 + "@" + point2.lat() + "," + point2.lng();
            gdir.load("from: " + from + " to: " + dest, {});
        });
    });
}

/*
* mapType: G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP, G_PHYSICAL_MAP
* Author: Steve Bumbaugh 
* Date: January 2009
*/
function displaySimpleMap(mapId, address, name, width, height, lngOffset, latOffset, altitude, mapType) 
{
	if (GBrowserIsCompatible()) 
	{
		var map = null;
		var geocoder = null;

		var divMapId = "div" + mapId;
		var div = '<' + 'div id="' + divMapId + '" style="width: ' + width + 'px; height: ' + height + 'px;"' + '><' + '/div' + '>';

		$j('.' + mapId).append(div);

		map = new GMap2(document.getElementById(divMapId));
		geocoder = new GClientGeocoder();

		geocoder.getLatLng(address, function(point) {
			var latLong = new GLatLng((point.lat() + latOffset), point.lng() + lngOffset);

			map.setMapType(mapType);
			map.setCenter(latLong, altitude);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());

			var marker = new GMarker(point, { title: name });
			map.addOverlay(marker);
		});
	}
}

/* 
* Author: Steve Bumbaugh 
* Date: January 2009
*/
function initYouTubeVideo(classname, url) {
	var html = '<' + 'object width="425" height="344"' + '><' + 'param name="movie" value="' + url + '"' + '><' + '/param' + '><' + 'param name="allowFullScreen" value="true"' + '><' + '/param' + '><' + 'param name="allowscriptaccess" value="always"' + '><' + '/param' + '><' + 'embed src="' + url + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"' + '><' + '/embed' + '><' + '/object>';
	$j('.' + classname).append(html);
}

/* 
* Author: Steve Bumbaugh 
* Date: January 2009
*/
function initImageClick(triggerId, imgClick)
{
	$j('#' + triggerId).click(function() {
		$j('#' + imgClick).click();
		return false;
	});
}

