$(function() {	


/*	$('.related h3').click(function() {
			if (this.className == 'collapse') {
				$(this).removeClass('collapse').addClass('expand');
				$(this).next().removeClass('button_collapse').addClass('button_expand');
			} else {
				$(this).removeClass('expand').addClass('collapse');
				$(this).next().removeClass('button_expand').addClass('button_collapse');
			}
		$(this).parent().next().toggle('slow');
		return false;
	}) */
	
	
	$('.related h3').click(function() {
			if (this.parentNode.className == 'heading collapse') {
				$(this).parent().removeClass('collapse').addClass('expand');
			} else {
				$(this).parent().removeClass('expand').addClass('collapse');
			}
		$(this).parent().next().toggle('slow');
		return false;
	})	
	
	
	

	
	$('.related .button').click(function() {
			if (this.parentNode.className == 'heading collapse') {
				$(this).parent().removeClass('collapse').addClass('expand');
			} else {
				$(this).parent().removeClass('expand').addClass('collapse');
			}
		$(this).parent().next().toggle('slow');
		return false;
	})	
	
	

		if($('.related .video').length > 0) {
				$('.related .video .media_title').hide();
		}
		
		
		var str= window.location + "";
	
		 
	if (str.match("/audio/") != null) {
		$('.related .video .media').hide();	
		$('.related .video .heading').removeClass('collapse').addClass('expand');		
	} else if (str.match("/photos/") != null) {

 	 	$('.related .video .media').hide();
		$('.related .video .heading').removeClass('collapse').addClass('expand');
		$('.related .audio .media').hide();	
		$('.related .audio .heading').removeClass('collapse').addClass('expand');		
			
			if (str.match("/bigpicture=true/") != null) {
				$('.player .button_bigpicture').hide();
			} else {
				$('.player .button_slideshow').hide();
			}
			
	} else if (str.match("/videos/") != null) {
 	 	$('.related .photo .media').hide();
		$('.related .photo .heading').removeClass('collapse').addClass('expand');
		$('.related .audio .media').hide();	
		$('.related .audio .heading').removeClass('collapse').addClass('expand');				
	 
	} else {
		
	}
	 

		

		// Check for custom map geo co-ords when no video/photo media present
		if (  ($('.article').length > 0) &&  (    ($('.related .photo').length <= 0) && ($('.related .video').length <= 0) )    ){

		} else {	

			if($(".map iframe").length > 0) {	
			

				var mapSrc = $(".map iframe").attr("src");
				var lat = mapSrc.match(/latitude=[\w.-]+/) + '';
				var latDec = lat.substring(lat.indexOf('.') + 1);
				var lon = mapSrc.match(/longitude=[\w.-]+/) + '';
				var lonDec = lon.substring(lon.indexOf('.') + 1);
				
				
				if ((latDec.length <= 4) && (lonDec.length <= 4))  {
					
					// Setting delay to allow map to load center function properly
					setTimeout("initmap()", 1000);

				} 
			}
		}
		
	// Script for Twitter Dunnart, moves it to related media column
	if ($('#twitter_dunnart_wrapper').html() != null) {
		
		var twitterModule = $('#twitter_dunnart_wrapper').html();
		$('#twitter_dunnart_wrapper').remove();
		$('#col1 .related').append('<div id="twitter_dunnart_wrapper" style="margin: 15px 0 0 0">' + twitterModule + '</div>');
		
	}
		
		
	// Script for #Hero module, moves it to below the .summary class
	if ($('#col1 #hero').html() != null) {
		
		if ($('#col1 #hero .ugc').html() != null) {

			
		} else {			

			var heroModule = $('#col1 #hero').html();
			$('#col1 #hero').remove();
			$('#col1 #module1 .summary').append(heroModule);			
			
		}
		
	}		


	// Script for #hero_bottom module, moves it to story_footer class above topics
	if ($('#col1 #hero_bottom').html() != null) {	
	
		$('#col1 #hero_bottom').hide();
		$('#col1 .story_footer .topics').before('<div class="loading" style="margin: 0 0 20px 0;"><img src="http://pluck.abc.net.au/ver1.0/Content/ua/images/throbber.gif" alt="Loading" title="Loading"/></div>');
		


				setTimeout(function() {
					$('#col1 #hero_bottom').show();
					var heroModule = $('#col1 #hero_bottom').html();									
					$('#col1 #hero_bottom').remove();	
					$('#col1 .story_footer .loading').remove();	
				
					$('#col1 .story_footer .topics').before(heroModule);	
				}, 7000);
				
				

		
	}	




		// Script for rssfeed control, moves it to related media column added by Rae
	if ($('#feedControl').html() != null) {
		
		var feedControlModule = $('#feedControl').html();
		$('#feedControl').remove();
		$('#col1 .related').append('<div id="feedControl" style="margin: 15px 0 0 0">' + feedControlModule + '</div>');
		
	}


	});


	

function initmap() {
		$('.related .map .media').hide();
		$('.related .map .heading').removeClass('collapse').addClass('expand');	
}






