var ap_instances = new Array();
function ap_stopAll(playerID) {
    for(var i = 0; i < ap_instances.length; i++) {
        try {
            if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
            else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
            
        }
        catch( errorObject ) {
            // stop any errors
        }
        
    }
    
}

function ap_registerPlayers() {
    var objectID;
    var objectTags = document.getElementsByTagName("object");
    for(var i=0; i < objectTags.length; i++) {
        objectID = objectTags[i].id;
        if(objectID.indexOf("audioplayer") == 0) {
            ap_instances[i] = objectID.substring(11, objectID.length);
            
        }
        
    }
    
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );

jQuery(function() {
    
		jQuery('a.audio').each(function(index) {

			var $this = $(this);
			var mp3src = $this.attr("href");
			var mp3id = index+=1;
			var swfsrc = "../js/player.swf";

			$(this.parentNode).html('<object type="application/x-shockwave-flash" data="'+swfsrc+'" id="audioplayer'+mp3id+'" height="24" width="290" /> <param name="movie" value="'+swfsrc+'" /> <param name="FlashVars" value="playerID='+mp3id+'&amp;soundFile='+mp3src+'" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="transparent" /></object>');

		});

	});

jQuery(function() {

		if(document.getElementById('map')){
			var js=document.createElement('script');
			js.type='text/javascript';
				if(window.location.href.indexOf('st-michaels-church')>-1){
					js.src="http://maps.google.com/maps?file=api&v=2.117&key=ABQIAAAADLUYKLJptW-F_gXNdCdC6BSgdZsKg_eS2Zr3T_14pHNBio61ZRRU4ilaYLR1-WJ91HZFqPH4v7DzVw&c&async=2";
				}
				if(window.location.href.indexOf('stmichaels.ch')>-1){
					js.src="http://maps.google.com/maps?file=api&v=2.117&key=ABQIAAAADLUYKLJptW-F_gXNdCdC6BTcw-g-N9uVXad9m6kVMiEYe33D3hSxMRjX_5a8dAksJvG7DPjZqCdlcg&c&async=2";
				}

			document.getElementsByTagName('head')[0].appendChild(js);	
		}

	jQuery(document.body).unload(function() {

		if (GBrowserIsCompatible()) {
			GUnload();
		}
        
	});

	var map;
	var markers = [];

	function loadMap() {

		if (GBrowserIsCompatible()) {
			// Load the KML.   
				if(window.location.href.indexOf('st-michaels-church')>-1){
					var geoXml = new GGeoXml("http://st-michaels-church.org.uk/stmichaels.kml");
				}
				if(window.location.href.indexOf('stmichaels.ch')>-1){
					var geoXml = new GGeoXml("http://stmichaels.ch/stmichaels.kml");
				}
			// Initialize the map.   
			var map = new GMap2(document.getElementById("map"));
            	map.setCenter(new GLatLng(51.515425,-2.544779), 15);
            	map.setMapType(G_HYBRID_MAP);
            	map.addControl(new GLargeMapControl());
            	map.addOverlay(geoXml); 
		}      
	};

	var runyet = 0;

	jQuery(function() {

		jQuery('#map').hide();

		// toggles the map on clicking the link
		jQuery('a#showmap').click(function() {
			jQuery('#map').toggle();
			if(runyet==0){
				runyet++;
				loadMap();
			};


            	        mapAdditions();

//			return false;
	  	});
	
	});


});

function mapAdditions() {

            jQuery('#map').live('mouseover', function() {

            	jQuery("#mtgt_geoxml_2").attr("title","St Michael's Church");

            	jQuery("#mtgt_geoxml_1").attr("title","Old School Rooms");

            	jQuery("#mtgt_geoxml_3").attr("title","Preschool & Nursery");

            });

};



jQuery(function() {
    
		jQuery('input.longinput').each(function() {

			var $this = $(this);
			var fieldID = $this.attr("id");
			var fieldName = $this.attr("name");

			$(this.parentNode).html('<label for="'+fieldID+'" class="labelleft">Your message:</label> <textarea id="'+fieldID+'" name="'+fieldName+'" class="longinput"></textarea>');

		});

	});

