$(document).ready(function(){ 

mainmenu();
initialize();

	//$("#mefade").fadeTo(1000, 0.2).fadeTo(1000, 1).fadeTo(1000, 0.2).fadeTo(1000, 1);

	$('#keywords').bind('focus', function() {
  		$('#keywords').val("");
	});
});

function initialize() {

	if (GBrowserIsCompatible() && document.getElementById("map_canvas")) {
		var map = new GMap2(document.getElementById("map_canvas"));
		map.setMapType(G_NORMAL_MAP);    
		map.setCenter(new GLatLng(38.77, -92.65), 6);
		map.setUIToDefault();
               
        
		G_PHYSICAL_MAP.getMinimumResolution = function () { return 6 }; 
        G_NORMAL_MAP.getMinimumResolution = function () { return 6 }; 
        G_SATELLITE_MAP.getMinimumResolution = function () { return 6 }; 
        G_HYBRID_MAP.getMinimumResolution = function () { return 6 }; 
        
        G_PHYSICAL_MAP.getMaximumResolution = function () { return 7 }; 
        G_NORMAL_MAP.getMaximumResolution = function () { return 7 }; 
        G_SATELLITE_MAP.getMaximumResolution = function () { return 7 }; 
        G_HYBRID_MAP.getMaximumResolution = function () { return 7 }; 	
		
		
		GEvent.addListener(map, "click", function(overlay, point){
			map.clearOverlays();
			if (point) {
				map.addOverlay(new GMarker(point));
				map.panTo(point);
				lat = point.lat();;
				lng = point.lng();
				document.getElementById("lat").value = lat;
				document.getElementById("lng").value = lng;
			}
		});

		//map.addControl(new GSmallMapControl());
		//map.addControl(new GMapTypeControl());		
	}	
}


function mainmenu() {
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function() {
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function() {
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

function goPublish(id) {
	var r=confirm("Are you sure you want to APPROVE this image?");
	if (r==true) {

		var dataString = 'id='+ id;
		
		$.ajax({
			type: "POST",
			url: "publish.php",
			data: dataString,
   			dataType: "json",			
			cache: false,
			
			success: function(data) {
 				$("#"+id+"").fadeOut('slow');	
			}		
		});
		
		return false;
	}
}

function goDeny(id) {
	var r=confirm("Are you sure you want to DENY this image?");
	if (r==true) {

		var dataString = 'id='+ id;
		
		$.ajax({
			type: "POST",
			url: "deny.php",
			data: dataString,
   			dataType: "json",			
			cache: false,
			
			success: function(data) {
 				$("#"+id+"").fadeOut('slow');
			}		
		});
		
		return false;
	}  
}

function goDupe(id) {
	var r=confirm("Are you sure you want to Delete this image?");
	if (r==true) {

		var dataString = 'id='+ id;
		
		$.ajax({
			type: "POST",
			url: "dupe.php",
			data: dataString,
   			dataType: "json",			
			cache: false,
			
			success: function(data) {
 				$("#"+id+"").fadeOut('slow');
			}		
		});
		
		return false;
	}
}

function addToVote(id, vote) {
	/* var r=confirm("Are you sure you want to ADD this image?"); 
	if (r==true) {*/

		var dataString = 'id='+id+'&vote='+vote;
		
		$.ajax({
			type: "POST",
			url: "updatevote.php",
			data: dataString,
   			dataType: "json",			
			cache: false,
			
			success: function(data) {
				$('#'+id+'').attr('class', 'results-container-selected');
				
				var img = '#'+id+' .results-add-remove .results-img';
				
				$(img).attr({
					src: "../images/remove-from-vote.png",
					alt: "REMOVE",
					onClick: "removeFromVote("+id+", 0)"
				});
			}		
		});
		
		return false;
	//}
}
	
function removeFromVote(id, vote) {
	/* var r=confirm("Are you sure you want to REMOVE this image?"); 
	if (r==true) {*/

		var dataString = 'id='+id+'&vote='+vote;
		
		$.ajax({
			type: "POST",
			url: "updatevote.php",
			data: dataString,
   			dataType: "json",			
			cache: false,
			
			success: function(data) {
				$('#'+id+'').attr('class', 'results-container');
				
				var img = '#'+id+' .results-add-remove .results-img';
				
				$(img).attr({
					src: "../images/add-to-vote.png",
					alt: "ADD",
					onClick: "addToVote("+id+", 1)"
				});
			}		
		});
		
		return false;
	//}
}

function addMyVote(id, pTitle) {
	var r=confirm("Are you sure you want to VOTE for "+pTitle+"?"); 
	if (r==true) {
	
		var dataString = 'id='+id;
		
		$.ajax({
			type: "POST",
			url: "addmyvote.php",
			data: dataString,
   			dataType: "json",			
			cache: false,
			
			success: function(data) {
				window.alert('Thank you. Your vote has been cast.\n\n Remember you can vote again in 24 hours.');
				location.reload();
			}		
		});
		
		return false;
	}
}				
		






