
var thismap;
var thislat;
var thislon;
var thismapskey;

function update(url)
{
	document.getElementById('bigimage').src=url;
}

function showposting_init_map()
{
        if (GBrowserIsCompatible()) {
                thismap = new google.maps.Map2(document.getElementById("map_canvas"));
                var point = new google.maps.LatLng(thislat, thislon);
                thismap.setCenter(point, 15);
                thismap.addControl(new google.maps.SmallMapControl());
                thismap.addControl(new google.maps.MapTypeControl());
                thismap.addOverlay(new google.maps.Marker(thismap.getCenter()));
        }
}

function showposting_load_map()
{
	google.load("maps", "2",{"callback" : showposting_init_map});
}

function showposting_load_map_api()
{
        if (typeof GMap2 != 'function')
        {
                var script = document.createElement('script');
                script.type = 'text/javascript';
                script.src = 'http://www.google.com/jsapi?key=' + thismapskey + '&callback=showposting_load_map';
                document.getElementsByTagName("head")[0].appendChild(script);
        }
}

function showposting_enlarge_map(lat,lon,mapskey)
{
	document.getElementById('map_static').style.display='none';
	document.getElementById('map_canvas').style.display='block';
	document.getElementById('posting_content_wrapper').style.marginRight='-562px';
	document.getElementById('posting_content').style.backgroundImage='url(/common/images/bg_posting_expanded.gif)';
	document.getElementById('posting_details').style.marginRight='562px';
	document.getElementById('posting_extra').style.width='561px';
	document.getElementById('map_enlarge').style.display='none';
	document.getElementById('map_shrink').style.display='block';
        if ( !thismap )
        {
		thislat = lat;
		thislon = lon;
		thismapskey = mapskey;
                showposting_load_map_api();
        }
	else
	{
		thismap.checkResize();
	}
}

function showposting_shrink_map()
{
        document.getElementById('map_canvas').style.display='none';
	document.getElementById('map_static').style.display='block';
        document.getElementById('posting_content_wrapper').style.marginRight='-383px';
	document.getElementById('posting_content').style.backgroundImage='url(/common/images/bg_posting.gif)';
        document.getElementById('posting_details').style.marginRight='383px';
        document.getElementById('posting_extra').style.width='382px';
	document.getElementById('map_shrink').style.display='none';
	document.getElementById('map_enlarge').style.display='block';
}

function showposting_is_preview()
{
	return $( '#posting' ).hasClass( "preview" );
}

function showposting_view_counter()
{
	if( showposting_is_preview() ){ return; }

	var site_id    = parseInt( $( "meta[name=DCSext.site_id]" ).attr( "content" ) );
	var posting_id = parseInt( $( "meta[name=DCSext.posting_id]" ).attr( "content" ) );

	$.getJSON(
		"http://vc.gumtree.com/?ps=" + posting_id + "&jsonp=?",
		function( json ){
			if( json.total !== undefined ) {
				var message = ' <span class="divider">|</span> <span class="info">Ad viewed:</span> ' + json.total + ' times';
				$("#posting_details #date").append( message );
			}
		}
	);
}

$(document).ready( function(){
	showposting_view_counter();
	activateAdPlacements();
} );
