/*******************************************************************************************
** Photo Control
*******************************************************************************************/
var ie = null;
var photosOn = 0; //Starts off.

function addPhotoLayer()
{
	
	removePhotoLayer();
	map.addOverlay(new GLayer("com.panoramio.all"));
	var photoButton = document.getElementById("photoButtonText");
	//photoButton.onclick = removePhotoLayer;
	photoButton.innerHTML = "Hide Photos";
	
	if(ie)
	{	document.getElementById("mapshowphotos").onclick = removePhotoLayer;	}
	else
	{	photoButton.onclick = removePhotoLayer;	}
	
	photosOn = 1; //Turns the photos ON.
}

function removePhotoLayer()
{
	map.removeOverlay(new GLayer("com.panoramio.all"));
	var photoButton = document.getElementById("photoButtonText");
	
	photoButton.innerHTML = "Show Photos";
	
	if(ie)
	{	document.getElementById("mapshowphotos").onclick = addPhotoLayer;	}
	else
	{	photoButton.onclick = addPhotoLayer;	}
	
	photosOn = 0; //Turns the photos OFF.
}


function photoControl(){};
photoControl.prototype = new GControl();

photoControl.prototype.initialize = function(map) 
{
    	// Is this MSIE, if so we need to use AlphaImageLoader
	var agent = navigator.userAgent.toLowerCase();
	if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ie = true} else {ie = false}
	
	var photoMore = document.createElement("div");
    	photoMore.title = "Show/Hide Photos";
    	
	// Handle transparent PNG files in MSIE
	if (ie)
	{
		var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"http://maps.mustseemap.com/images/map_button_1.png\", sizingMethod=\"scale\");";
		
		var photoHTML = "<div style='width:110px;height:24px;" + loader + " ' class='mapshowphotos' id='mapshowphotos' onClick='addPhotoLayer();'><ul><li>";
		photoHTML += "<a href='javascript:void(0);' id='photoButtonText' >Show Photos</a></li></ul></div>";
		photoMore.innerHTML =  photoHTML;
	}
	else
	{
		photoMore.id = "photoButton";
    		photoMore.setAttribute("class", "mapshowphotos");
		photoMore.innerHTML = "<ul><li><a href='javascript:void(0);' id='photoButtonText' onClick='addPhotoLayer();'>Show Photos</a></li></ul>";
	}
	
	
    	map.getContainer().appendChild(photoMore);
    	return photoMore;
}

photoControl.prototype.getDefaultPosition = function() 
{   return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(165, 10));  }

/*******************************************************************************************
** Map Menu Control
*******************************************************************************************/

function changeMapTypes(newMapType)
{
	switch(newMapType)
	{
		case 1: var myMapType = G_NORMAL_MAP; break;
		case 2: var myMapType = G_PHYSICAL_MAP; break;
		case 3: var myMapType = G_SATELLITE_MAP; break;
		case 4: var myMapType = G_HYBRID_MAP; break;
	}
	
	map.setMapType(myMapType);
}


function mapMenuControl(){};
mapMenuControl.prototype = new GControl();

mapMenuControl.prototype.initialize = function(map) 
{

	var mapMenu = document.createElement("div");
    	mapMenu.title = "Change Map Styles";
    	
	// Handle transparent PNG files in MSIE
	if (ie)
	{
		var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"http://maps.mustseemap.com/images/map_button_2.png\", sizingMethod=\"scale\");";
		
		var menuHTML = "<div style='width:110px;height:24px;" + loader + " ' class='mapstyledropdown' id='mapstyledropdown' >";
		menuHTML += "<ul><li><a href='javascript:void(0);' >Map Style</a><ul>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(1);'>Road</a></li>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(2);'>Terrain</a></li>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(3);'>Satellite</a></li>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(4);'>Hybrid</a></li></ul></li></ul></div>";
    		
		mapMenu.innerHTML =  menuHTML;
	}
	else
	{
		mapMenu.id = "mapstyledropdown";
    		mapMenu.setAttribute("class", "mapstyledropdown");
    		
    		var menuHTML = "<ul><li><a href='javascript:void(0);' >Map Style</a><ul>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(1);'>Road</a></li>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(2);'>Terrain</a></li>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(3);'>Satellite</a></li>";
    		menuHTML += "<li><a href='javascript:void(0);' id='photoButtonText' onClick='changeMapTypes(4);'>Hybrid</a></li></ul></li></ul>";
    		
		mapMenu.innerHTML = menuHTML;
	}
	
	
    	map.getContainer().appendChild(mapMenu);
    	return mapMenu;
}

mapMenuControl.prototype.getDefaultPosition = function() 
{   return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(50, 10));  }

/*******************************************************************************************
** 3D Control Button
*******************************************************************************************/
function load3D()
{
	map.closeInfoWindow();
	map.setMapType(G_SATELLITE_3D_MAP);
	map.addControl(gMenu);
}

function threeDControl(){};
threeDControl.prototype = new GControl();

threeDControl.prototype.initialize = function(map) 
{
    	// Is this MSIE, if so we need to use AlphaImageLoader
	var agent = navigator.userAgent.toLowerCase();
	if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ie = true} else {ie = false}
	
	var threeDButton = document.createElement("div");
    	threeDButton.title = "View in 3D";
    	threeDButton.id = "3dButton";
    	threeDButton.setAttribute("class", "map3d");
    	threeDButton.innerHTML = "<a href='javascript:void(0);' onClick='load3D();'><img src='http://" + domainName + "/images/map_button_3d.png' width='39' height='39' border='0' ></a>";

    	map.getContainer().appendChild(threeDButton);
    	return threeDButton;
}

threeDControl.prototype.getDefaultPosition = function() 
{   return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 3));  }

/*******************************************************************************************
** Loading Image
*******************************************************************************************/
function loadingImage(){};
loadingImage.prototype = new GControl();
loadingImage.prototype.initialize = function(map) 
{
    var more = document.createElement("div");
    more.id = "loading_image";
    more.style.display = "none";
    more.innerHTML = "<img src=\"http://" + domainName + "/images/loading_animation.gif\" />"
    map.getContainer().appendChild(more);
    return more;
}

loadingImage.prototype.getDefaultPosition = function() 
{   return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(50, 7));  }

/*******************************************************************************************
** Message Container
*******************************************************************************************/
function mapMessages(){};
mapMessages.prototype = new GControl();
mapMessages.prototype.initialize = function(map) 
{
    var more = document.createElement("div");
    more.id = "mapMessages";
    more.style.display = "none";
    more.style.fontSize = "18px";
    more.style.color = "#cc0000";
    more.style.fontWeight = "bold";
    more.style.padding = "5px 10px 5px 10px";
    more.style.opacity = .85;
    more.style.alphaIE = 'alpha(opacity=' + (more.style.opacity * 100) + ')';
    more.style.backgroundColor= "#333333";
    map.getContainer().appendChild(more);
    return more;
}

mapMessages.prototype.getDefaultPosition = function() 
{   return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(125, 7));  }
