google.load("maps", "2.x");

$(document).ready(function(){

		var rand = (Math.floor(Math.random()*9999));
		$('.newCards').load('/ajax/lastCard/?'+rand, function(){
		$(".cardCreatedFront").humane_dates_plain();
		$('.usercardImage').hover(
        function () {$(this).next('.usercardBeakBeakHover').show();}, 
        function () {$(this).next('.usercardBeakBeakHover').hide();});
		$('.newCards').fadeIn('slow');
		});
});

function showCards(sequence){
		var rand = (Math.floor(Math.random()*9999));
		$('.newCards').everyTime( '8s', function(){//10s
		$('.usercardImage').fadeOut('fast');
		$('.newCards').load('/ajax/lastCard/?sequence='+sequence+'&rand='+rand, function(){
		$(".cardCreatedFront").humane_dates_plain();
		$('.usercardImage').hover(
        function () {$(this).next('.usercardBeakBeakHover').show();}, 
        function () {$(this).next('.usercardBeakBeakHover').hide();});
		$('.usercardImage').fadeIn('fast');
		});
		});

}

//called when the cards run out to stop the timer so we can start again.

function stopTimer(){
         $('.recentCard').stopTime();
}

//called when cards run out to start from beginning.

function goAgain(){
		var rand = (Math.floor(Math.random()*9999));
		$('.newCards').load('/ajax/lastCard/?'+rand, function(){
		$(".cardCreatedFront").humane_dates_plain();
		$('.usercardImage').hover(
        function () {$(this).next('.usercardBeakBeakHover').show();}, 
        function () {$(this).next('.usercardBeakBeakHover').hide();});
		$('.newCards').fadeIn('slow');
		});
}

function showMap(lat, long) {
    var map = new google.maps.Map2(document.getElementById("miniMap"));
    map.setCenter(new GLatLng(lat, long), 14);
    var location = new GLatLng(lat, long);
    var marker = new GMarker(location);
    var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10)); //position nav
    map.addControl(new GSmallMapControl(), topRight);
    map.addOverlay(marker);
    map.checkResize();
}