<?php
$title = "SST and Percentiles";
ini_set('include_path', './' . PATH_SEPARATOR . '../' . PATH_SEPARATOR . ini_get('include_path'));

include_once("include/header.php");
$DOCROOT = $_SERVER["DOCUMENT_ROOT"];

/*
if (isset($url)) {
	echo "<code>link=$link</code>";
	$stuff = htmlspecialchars($url);
	echo "<code>url=$stuff</code>";
}
*/

function is_gif_file( $file )
{
	if ( substr($file,-4) === '.gif' ) return true;
	return false;
}

function is_fli_file( $file )
{
	if ( substr($file,-4) === '.fli' ) return true;
	return false;
}

function get_latest( $directory ) {
	//$DOCROOT = $_SERVER["DOCUMENT_ROOT"];
	//$files=scandir( $DOCROOT.$BASEDIR.$directory );
	if ( !file_exists( $directory )) return null;
	$files = scandir( $directory );
	$files = array_filter( $files, 'is_gif_file' );
	if (count($files) <= 0) return null;
	$sfiles = sort($files);
	return $directory.'/'.$files[count($files)-1];
}

function get_latest_fli( $directory ) {
	//$DOCROOT = $_SERVER["DOCUMENT_ROOT"];
	//$files=scandir( $DOCROOT.$BASEDIR.$directory );
	if ( !file_exists( $directory )) return null;
	$files = scandir( $directory );
	$files = array_filter( $files, 'is_fli_file' );
	if (count($files) <= 0) return null;
	$sfiles = sort($files);
	return $directory.'/'.$files[count($files)-1];
}
?>

<map name="imap1daily">
	<area shape="rect" coords="102  113  127  132" href="<?php echo get_latest('DR_SST_daily/SST/SAgulfs');?>" alt="SAgulfs" title="SAgulfs">
	<area shape="rect" coords="105  109  146  149" href="<?php echo get_latest('DR_SST_daily/SST/Adelaide');?>" alt="Adelaide" title="Adelaide">
	<area shape="rect" coords="34  109   71  129" href="<?php echo get_latest('DR_SST_daily/SST/AlbEsp');?>" alt="AlbEsp" title="AlbEsp">
	<area shape="rect" coords="160   73  187  109" href="<?php echo get_latest('DR_SST_daily/SST/Brisbane');?>" alt="Brisbane" title="Brisbane">
	<area shape="rect" coords="158   87  182  114" href="<?php echo get_latest('DR_SST_daily/SST/Bris-Syd');?>" alt="Bris-Syd" title="Bris-Syd">
	<area shape="rect" coords="41  40  68  65" href="<?php echo get_latest('DR_SST_daily/SST/Broome2');?>" alt="Broome" title="Broome">
	<area shape="rect" coords="139   42  167   66" href="<?php echo get_latest('DR_SST_daily/SST/CGBR');?>" alt="CGBR" title="CGBR">
	<area shape="rect" coords="27   98   42  109" href="<?php echo get_latest('DR_SST_daily/SST/DonPer');?>" alt="DonPer" title="DonPer">
	<area shape="rect" coords="95   18  133   54" href="<?php echo get_latest('DR_SST_daily/SST/GoC');?>" alt="GoC" title="GoC">
	<area shape="rect" coords="50  32  78  54" href="<?php echo get_latest('DR_SST_daily/SST/Kimberley');?>" alt="Kimberley" title="Kimberley">
	<area shape="rect" coords="126   16  162   44" href="<?php echo get_latest('DR_SST_daily/SST/NGBR');?>" alt="NGBR" title="NGBR">
	<area shape="rect" coords="18   65   43  114" href="<?php echo get_latest('DR_SST_daily/SST/NingLeeu');?>" alt="NingLeeu" title="NingLeeu">
	<area shape="rect" coords="27  54  51  74" href="<?php echo get_latest('DR_SST_daily/SST/NWS');?>" alt="NWS" title="NWS">
	<area shape="rect" coords="68  103  111  127" href="<?php echo get_latest('DR_SST_daily/SST/RechEyre');?>" alt="RechEyre" title="RechEyre">
	<area shape="rect" coords="153   62  180   83" href="<?php echo get_latest('DR_SST_daily/SST/SGBR');?>" alt="SGBR" title="SGBR">
	<area shape="rect" coords="146  109  179  149" href="<?php echo get_latest('DR_SST_daily/SST/Syd-Hob');?>" alt="Syd-Hob" title="Sydney-Hobart">
	<area shape="rect" coords="126  134  163  160" href="<?php echo get_latest('DR_SST_daily/SST/Tas');?>" alt="Tas" title="Tasmania">
	<area shape="rect" coords="63  16  97  42" href="<?php echo get_latest('DR_SST_daily/SST/TimorP');?>" alt="TimorP" title="Timor Passage">
	<area shape="rect" coords="20   4  88  36" href="<?php echo get_latest('DR_SST_daily/SST/Indo');?>" alt="Indo" title="Indonesia">
</map>

<map name="imap2daily">
	<area shape="rect" coords="139   78  199  152" href="<?php echo get_latest('SR_daily/SST/SE');?>" alt="SE" title="South East">
	<area shape="rect" coords="3   62   71  134" href="<?php echo get_latest('SR_daily/SST/SW');?>" alt="SW" title="South West">
	<area shape="rect" coords="129   15  190   87" href="<?php echo get_latest('SR_daily/SST/NE');?>" alt="NE" title="North East">
	<area shape="rect" coords="20   7  95  80" href="<?php echo get_latest('SR_daily/SST/NW');?>" alt="NW" title="North West">
	<area shape="rect" coords="54   98  156  156" href="<?php echo get_latest('SR_daily/SST/GAB');?>" alt="GAB" title="South">
	<area shape="rect" coords="88  141  160  189" href="<?php echo get_latest('SR_daily/SST/SO');?>" alt="SO" title="Southern Ocean">
</map>

<map name="imap3daily">
	<area shape="rect" coords="21   43  163   75" href="<?php echo get_latest('AR_daily/SLA/AUS');?>" alt="SLA" title="Sea Level Anomaly">
	<area shape="rect" coords="21  119  163  151" href="<?php echo get_latest('AR_daily/SST/AUS');?>" alt="SSTA" title="Sea Surface Temperature Anomaly">
</map>

<map name="imap1daily_anim">
	<area shape="rect" coords="102  113  127  132" href="<?php echo get_latest_fli('DR_SST_daily/SST/SAgulfs');?>" alt="SAgulfs" title="SAgulfs">
	<area shape="rect" coords="105  109  146  149" href="<?php echo get_latest_fli('DR_SST_daily/SST/Adelaide');?>" alt="Adelaide" title="Adelaide">
	<area shape="rect" coords="34  109   71  129" href="<?php echo get_latest_fli('DR_SST_daily/SST/AlbEsp');?>" alt="AlbEsp" title="AlbEsp">
	<area shape="rect" coords="160   73  187  109" href="<?php echo get_latest_fli('DR_SST_daily/SST/Brisbane');?>" alt="Brisbane" title="Brisbane">
	<area shape="rect" coords="158   87  182  114" href="<?php echo get_latest_fli('DR_SST_daily/SST/Bris-Syd');?>" alt="Bris-Syd" title="Bris-Syd">
	<area shape="rect" coords="41  40  68  65" href="<?php echo get_latest_fli('DR_SST_daily/SST/Broome2');?>" alt="Broome" title="Broome">
	<area shape="rect" coords="139   42  167   66" href="<?php echo get_latest_fli('DR_SST_daily/SST/CGBR');?>" alt="CGBR" title="CGBR">
	<area shape="rect" coords="27   98   42  109" href="<?php echo get_latest_fli('DR_SST_daily/SST/DonPer');?>" alt="DonPer" title="DonPer">
	<area shape="rect" coords="95   18  133   54" href="<?php echo get_latest_fli('DR_SST_daily/SST/GoC');?>" alt="GoC" title="GoC">
	<area shape="rect" coords="50  32  78  54" href="<?php echo get_latest_fli('DR_SST_daily/SST/Kimberley');?>" alt="Kimberley" title="Kimberley">
	<area shape="rect" coords="126   16  162   44" href="<?php echo get_latest_fli('DR_SST_daily/SST/NGBR');?>" alt="NGBR" title="NGBR">
	<area shape="rect" coords="18   65   43  114" href="<?php echo get_latest_fli('DR_SST_daily/SST/NingLeeu');?>" alt="NingLeeu" title="NingLeeu">
	<area shape="rect" coords="27  54  51  74" href="<?php echo get_latest_fli('DR_SST_daily/SST/NWS');?>" alt="NWS" title="NWS">
	<area shape="rect" coords="68  103  111  127" href="<?php echo get_latest_fli('DR_SST_daily/SST/RechEyre');?>" alt="RechEyre" title="RechEyre">
	<area shape="rect" coords="153   62  180   83" href="<?php echo get_latest_fli('DR_SST_daily/SST/SGBR');?>" alt="SGBR" title="SGBR">
	<area shape="rect" coords="146  109  179  149" href="<?php echo get_latest_fli('DR_SST_daily/SST/Syd-Hob');?>" alt="Syd-Hob" title="Sydney-Hobart">
	<area shape="rect" coords="126  134  163  160" href="<?php echo get_latest_fli('DR_SST_daily/SST/Tas');?>" alt="Tas" title="Tasmania">
	<area shape="rect" coords="63  16  97  42" href="<?php echo get_latest_fli('DR_SST_daily/SST/TimorP');?>" alt="TimorP" title="Timor Passage">
	<area shape="rect" coords="20   4  88  36" href="<?php echo get_latest_fli('DR_SST_daily/SST/Indo');?>" alt="Indo" title="Indonesia">
</map>

<map name="imap2daily_anim">
	<area shape="rect" coords="139   78  199  152" href="<?php echo get_latest_fli('SR_daily/SST/SE');?>" alt="SE" title="South East">
	<area shape="rect" coords="3   62   71  134" href="<?php echo get_latest_fli('SR_daily/SST/SW');?>" alt="SW" title="South West">
	<area shape="rect" coords="129   15  190   87" href="<?php echo get_latest_fli('SR_daily/SST/NE');?>" alt="NE" title="North East">
	<area shape="rect" coords="20   7  95  80" href="<?php echo get_latest_fli('SR_daily/SST/NW');?>" alt="NW" title="North West">
	<area shape="rect" coords="54   98  156  156" href="<?php echo get_latest_fli('SR_daily/SST/GAB');?>" alt="GAB" title="South">
	<area shape="rect" coords="88  141  160  189" href="<?php echo get_latest_fli('SR_daily/SST/SO');?>" alt="SO" title="Southern Ocean">
</map>

<map name="imap3daily_anim">
	<area shape="rect" coords="21   43  163   75" href="<?php echo get_latest_fli('AR_daily/SLA/AUS');?>" alt="SLA" title="Sea Level Anomaly">
	<area shape="rect" coords="21  119  163  151" href="<?php echo get_latest_fli('AR_daily/SST/AUS');?>" alt="SSTA" title="Sea Surface Temperature Anomaly">
</map>

<map name="imapCdaily">
	<area shape="rect" coords="102  113  127  132" href="DR_SST_CLIM/SST/SAgulfs/00.gif" alt="SAgulfs" title="SAgulfs">
	<area shape="rect" coords="105  109  146  149" href="DR_SST_CLIM/SST/Adelaide/00.gif" alt="Adelaide" title="Adelaide">
	<area shape="rect" coords="34  109   71  129" href="DR_SST_CLIM/SST/AlbEsp/00.gif" alt="AlbEsp" title="AlbEsp">
	<area shape="rect" coords="160   73  187  109" href="DR_SST_CLIM/SST/Brisbane/00.gif" alt="Brisbane" title="Brisbane">
	<area shape="rect" coords="158   87  182  114" href="DR_SST_CLIM/SST/Bris-Syd/00.gif" alt="Bris-Syd" title="Bris-Syd">
	<area shape="rect" coords="41  40  68  65" href="DR_SST_CLIM/SST/Broome2/00.gif" alt="Broome" title="Broome">
	<area shape="rect" coords="139   42  167   66" href="DR_SST_CLIM/SST/CGBR/00.gif" alt="CGBR" title="CGBR">
	<area shape="rect" coords="27   98   42  109" href="DR_SST_CLIM/SST/DonPer/00.gif" alt="DonPer" title="DonPer">
	<area shape="rect" coords="95   18  133   54" href="DR_SST_CLIM/SST/GoC/00.gif" alt="GoC" title="GoC">
	<area shape="rect" coords="50  32  78  54" href="DR_SST_CLIM/SST/Kimberley/00.gif" alt="Kimberley" title="Kimberley">
	<area shape="rect" coords="126   16  162   44" href="DR_SST_CLIM/SST/NGBR/00.gif" alt="NGBR" title="NGBR">
	<area shape="rect" coords="18   65   43  114" href="DR_SST_CLIM/SST/NingLeeu/00.gif" alt="NingLeeu" title="NingLeeu">
	<area shape="rect" coords="27  54  51  74" href="DR_SST_CLIM/SST/NWS/00.gif" alt="NWS" title="NWS">
	<area shape="rect" coords="68  103  111  127" href="DR_SST_CLIM/SST/RechEyre/00.gif" alt="RechEyre" title="RechEyre">
	<area shape="rect" coords="153   62  180   83" href="DR_SST_CLIM/SST/SGBR/00.gif" alt="SGBR" title="SGBR">
	<area shape="rect" coords="146  109  179  149" href="DR_SST_CLIM/SST/Syd-Hob/00.gif" alt="Syd-Hob" title="Sydney-Hobart">
	<area shape="rect" coords="126  134  163  160" href="DR_SST_CLIM/SST/Tas/00.gif" alt="Tas" title="Tasmania">
	<area shape="rect" coords="63  16  97  42" href="DR_SST_CLIM/SST/TimorP/00.gif" alt="TimorP" title="Timor Passage">
	<area shape="rect" coords="20   4  88  36" href="DR_SST_CLIM/SST/Indo/00.gif" alt="Indo" title="Indonesia">
</map>


<div class="row">
	<div class="col-md-4">
		<h3 class="highlightedHeader">SST and Percentiles</h3>
		<div class="panel-group" id="accordian" role="tablist" aria-multiselectable="true">
			<div class="panel panel-default">
				<div class="panel-heading" role="tab" data-toggle="collapse"  data-parent="#accordian" data-target="#zoomInsContent" >
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="true" aria-controls="zoomInsContent"> Detailed regions </a>
					</h4>
				</div>
				<div id="zoomInsContent" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="zoomIns">
					<div class="panel-body">
						<img class="highlight" src="misc/imap1daily.gif" usemap="#imap1daily">
					</div>
				</div>
			</div>

<!--
			<div class="panel panel-default">
				<div class="panel-heading" role="tab"  data-toggle="collapse" data-parent="#accordian" data-target="#midSizeContent">
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="false" aria-controls="midSizeContent"> State regions </a>
					</h4>
				</div>
				<div id="midSizeContent" class="panel-collapse collapse" role="tabpanel" aria-labelledby="midSize">
					<div class="panel-body">
						<img class="highlight" src="misc/imap2.gif" usemap="#imap2daily">
					</div>
				</div>
			</div>
-->
<!--
			<div class="panel panel-default">
				<div class="panel-heading" role="tab"  data-toggle="collapse" data-parent="#accordian" data-target="#largeAreaContent">
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="false" aria-controls="largeAreaContent"> Australia region </a>
					</h4>
				</div>
				<div id="largeAreaContent" class="panel-collapse collapse" role="tabpanel" aria-labelledby="largeArea">
					<div class="panel-body">
						<img class="highlight" src="misc/imap3mm.gif" usemap="#imap3daily">
					</div>
				</div>
			</div>
-->
			<div class="panel panel-default">
				<div class="panel-heading" role="tab" data-toggle="collapse"  data-parent="#accordian" data-target="#zoomInsContentAnimation" >
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="false" aria-controls="zoomInsContentAnimation"> Animation - Detailed regions </a>
					</h4>
				</div>
				<div id="zoomInsContentAnimation" class="panel-collapse collapse" role="tabpanel" aria-labelledby="zoomInsAnimation">
					<div class="panel-body">
						<img class="highlight" src="misc/imap1daily.gif" usemap="#imap1daily_anim">
					</div>
				</div>
			</div>

<!--
			<div class="panel panel-default">
				<div class="panel-heading" role="tab"  data-toggle="collapse" data-parent="#accordian" data-target="#midSizeContentAnimation">
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="false" aria-controls="midSizeContentAnimation"> Animation - State regions </a>
					</h4>
				</div>
				<div id="midSizeContentAnimation" class="panel-collapse collapse" role="tabpanel" aria-labelledby="midSizeAnimation">
					<div class="panel-body">
						<img class="highlight" src="misc/imap2.gif" usemap="#imap2daily_anim">
					</div>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading" role="tab"  data-toggle="collapse" data-parent="#accordian" data-target="#largeAreaContentAnimation">
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="false" aria-controls="largeAreaContentAnimation"> Animation - Australia region </a>
					</h4>
				</div>
				<div id="largeAreaContentAnimation" class="panel-collapse collapse" role="tabpanel" aria-labelledby="largeAreaAnimation">
					<div class="panel-body">
						<img class="highlight" src="misc/imap3mm.gif" usemap="#imap3daily_anim">
					</div>
				</div>
			</div>
-->
			<div class="panel panel-default">
				<div class="panel-heading" role="tab" data-toggle="collapse"  data-parent="#accordian" data-target="#climContent" >
					<h4 class="panel-title">
						<a class="external" href="#" aria-expanded="false" aria-controls="climContent"> Climatology </a>
					</h4>
				</div>
				<div id="climContent" class="panel-collapse collapse" role="tabpanel" aria-labelledby="climContent">
					<div class="panel-body">
						<img class="highlight" src="misc/imap1daily.gif" usemap="#imapCdaily">
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="col-md-8">
		<div id="proxiedPagesContainer">
			<div class="voffset4"></div>
			<!--<h4>Choose and then click on a map to see the graphs</h4>-->
			<h4>Choose region</h4>
			<a href="<?php echo $BASEDIR ?>whatsshown.php" class="btn btn-primary " type="button">What's shown in these maps</a>
			<br/>
			<br/>
			<h4>Data used to make these maps:</h4>
			<p><a href="http://thredds.aodn.org.au/thredds/catalog/IMOS/SRS/SST/ghrsst/L3S-6d/ngt/catalog.html" class="btn btn-primary btn-sm" type="button">SST: L3S-6d ngt</a></p>
			<p><a href="http://thredds.aodn.org.au/thredds/catalog/IMOS/OceanCurrent/GSLA/catalog.html" class="btn btn-primary btn-sm" type="button">GSLA</a></p>
		</div>
	</div>
</div>

<?php
include_once("include/sfooter.php");

if (isset($_REQUEST["link"])) {
	$link = normalise_path($_REQUEST["link"]);
	echo "<script>\n";
	echo '+function ($) {';
	echo "\n";
	if (substr($link,-4) === '.fli' ) {
		//echo '  $("#proxiedPagesContainer").load( "views/mmAnimationsTpl.php",{"link": "'.$link.'"});';
		echo '  $("#proxiedPagesContainer").load( "views/dailyAnimationsTpl.php",{"link": "'.$link.'"});';
	}
	else {
		echo '  $("#proxiedPagesContainer").load( "views/dailyTpl.php",{"link": "'.$link.'"});';
	};
	echo "\n";
	echo "}(jQuery);\n";
	echo "</script>\n";
}

?>
<script src="<?php echo $BASEDIR ?>js/soceancolour.js"></script>
<script src="<?php echo $BASEDIR ?>js/imageMapResizer.min.js"></script>
<script>

+function ($) {
	$('area').each(function () {
		var href = $(this).attr('href');
		//console.log('reset:'+href);
		//$(this).attr('data-href',href);
		$(this).attr('href','#');
		// Anything with an fli we also add in the data attributes
		if ( href.substr( -4 ) == '.fli' ) {
			$(this).attr('data-mp4-file', href.slice(0,-4)+'.mp4')
			$(this).attr('data-ogg-file', href.slice(0,-4)+'.ogg')
			$(this).attr('data-avi-file', href.slice(0,-4)+'.avi')
		}
		$(this).click( function() {
			var data = {'link': href};
			var url = "views/dailyTpl.php";
			if ( href.substr( -4 ) == '.fli' ) {
				//url = "views/mmAnimationsTpl.php";
				url = "views/dailyAnimationsTpl.php";
				//data = {'link':href.slice(0,-4)};
			}
			else if ( href.substr( -7, 1 ) == '/' ) {
				url = "views/dailyCTpl.php";
			}
			//console.log('click='+href);
			if (href.length > 0 ) {
				$.ajax({
					url: url,
					data: data,
					success: function (res, status) {
						if (status == "success") {
							//console.log('setting view');
							$('#proxiedPagesContainer').html(res);
						}
					}
				});
			};
		});
	});
}(jQuery);

</script>
