//Initalise page
$(document).ready( function(){

	//check Flash installation
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} 
	else {
		rightFlashVersion = DetectFlashVer(8, 0, 24);
	}
	
	caseStudy_bind();
	deployMap();
	
});

function caseStudy_bind() {
	
	//bind click events to case study page
	if ( $('#case-study-image img').attr('src') != undefined && $('#case-study-thumbnail').attr('mode') != 'edit' ) {
		
		//hide copy
		$('#content-main span:first').hide();
					
		//add 'more' button to page
		$('#content-upper').append('<a id="button-case-study" class="button-black" href="#"><span class="tl"></span><span class="bl"></span>Read more<span class="tr"></span><span class="br"></span></a>');
		
		//bind click event to image and button
		$('#content-upper #button-case-study, #case-study-image img').click( function() {
			if ( $('#content-area').attr('status') == "image" ) {
				$('#case-study-image').slideUp(500, function() { $('#content-main span:first').slideDown(500); });
				$('#content-area').attr({'status': 'copy'});	
			}
			else {
				$('#content-main span:first').slideUp(500, function() { $('#case-study-image').slideDown(500); }); 
				$('#content-area').attr({'status': 'image'});	
			}
			
			return false;
		});
	}
}

function deployMap() {
	$('#map-location').append('<iframe id="map-container" frameborder="0" marginheight="0" marginwidth="0" scrolling="0" src="/iln/map.aspx"></iframe>');
}

function initializeMapSmall() {

	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map-canvas"));
		map.setCenter(new GLatLng( 51.5167, -0.0790 ), 15);
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();
		map.addControl(new GSmallMapControl());
		
		
		var iln = new GLatLng( 51.5183, -0.0734 );
		var ilnMarker = new GMarker( iln );

		map.addOverlay( ilnMarker );
		GEvent.addListener( ilnMarker, "click", function() {  map.openInfoWindow( iln, d ); });


		var d = document.createElement('div');
		d.setAttribute('id', 'map-info');
		
		var h2 = document.createElement('h2');
		h2.appendChild (document.createTextNode('Illustrated London News') );
		d.appendChild(h2);

		var addr = document.createElement('address');
		addr.appendChild (document.createTextNode('10 Fashion Street') );
		addr.appendChild (document.createElement('br'));
		addr.appendChild (document.createTextNode('London E1 9PX') );
		addr.appendChild (document.createElement('br'));
		addr.appendChild (document.createTextNode('UK') );
		d.appendChild(addr);
		
		map.openInfoWindow( iln, d );
	}
}

