<?php
include '../auth.php';
?>
<html>
<head>
<?php
//header("Content-Type: text/plain");
  $bg = array('1.jpeg','2.jpeg','3.jpeg','4.jpeg','5.jpeg','6.jpeg','7.jpeg','8.jpeg','9.jpeg'); // array of filenames

  $i = rand(0, count($bg)-1); // generate random number size of the array
  $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>
<title>ArOZ Mirror</title>
<link rel="stylesheet" href="../script/tocas/tocas.css">
<script src="../script/tocas/tocas.js"></script>
<script src="../script/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons-wind.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.min.css">
<style>
  h1 { margin:0 0 10px 0; }
  .wrapper { position: relative; height:200px; width:300px; margin:20px 0; overflow:hidden; }
  .content { position:absolute; bottom:0; width:100%; }
  .content div { padding:10px;}
  
  body{
background: url(img/bg/<?php echo $selectedBg; ?>) no-repeat;
    background-size:     cover;                      /* <------ */
    background-repeat:   no-repeat;
}

</style>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

<!-- style="background-color:black;color:white;" -->
</head>
<body style="color:white;">
<div id="time" align="right" style="position: fixed; top: 10%; right: 5%; width: auto; height: 300px;">
<div id="dayOfWeek" style="font-size: 5vh;height:5vh;"></div>
<div id="CurrentDate" style="font-size: 4vh;height:4vh;"></div>
<div id="CurrentTime" style="font-size: 3vh;height:3vh;"></div>
</div>

<div id="weather" align="left" style="position: fixed; top: 10%; left: 5%; width: auto; height: 500px;">

<div style="font-size: 4vh;height:4vh;" id="country" style="text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black !important;"></div>
<div style="font-size: 2vh;height:2vh;">
   <div class="h1"></div>
   <p id="city" style="font-size: 3vh;"></p>
   <br>
   <P><i class="wi wi-night-sleet"  style="font-size:80px" id="weathericon"></i></p>
   <div class="h2" id="temp" style="text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;"></div>
   <p id="description" style="text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;"></p>
   <!-- <br class="clear"> -->
   <p id="forecast_details" style="text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;"></p>
   <p id="wind_details" style="text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;"></p>
</div>
</div>

</body>
<script>
$( document ).ready(function() {
    var t = setInterval(updateTime,1000);
	//show(22.302242, 114.174052);
	setTimeout(getLocation(),1500);
});

function updateTime(){
	var currentdate = new Date(); 
	$("#dayOfWeek").html(GetDay());
	$("#CurrentTime").html(zeroFill(currentdate.getHours(),2) + ":"+ zeroFill(currentdate.getMinutes(),2) + ":"  + zeroFill(currentdate.getSeconds(),2));
	//$("#CurrentDate").html(currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear());
	$("#CurrentDate").html(GetMonthName() + " " + currentdate.getDate() +", " + currentdate.getFullYear());
}

function GetDay(){
	var d = new Date();
	var weekday = new Array(7);
	weekday[0] =  "Sunday";
	weekday[1] = "Monday";
	weekday[2] = "Tuesday";
	weekday[3] = "Wednesday";
	weekday[4] = "Thursday";
	weekday[5] = "Friday";
	weekday[6] = "Saturday";

	var n = weekday[d.getDay()];
	return n;
}

function GetMonthName(){
	var monthNames = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
	var d = new Date();
	return(monthNames[d.getMonth()]);
}
function zeroFill( number, width )
{
  width -= number.toString().length;
  if ( width > 0 )
  {
    return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
  }
  return number + ""; // always return a string
}
</script>

<script>
function getLocation() {
    if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(showPosition);	
    } else { 
        console.log("Geolocation is not supported by this browser.");}
    }
function showPosition(position) {
    console.log("Latitude: " + position.coords.latitude + "Longitude: " + position.coords.longitude);
	show(position.coords.latitude , position.coords.longitude);
}
function show(lt , ln){
	$.getJSON( "https://fcc-weather-api.glitch.me/api/current?lat=" + lt.toFixed(5) + "&lon=" + ln.toFixed(5), function( data ) {
		if(typeof data.sys.country !== "undefined"){
			$( "#country" ).text(ISO3166[data.sys.country]);
		}
		if(typeof data.name !== "undefined"){
			$( "#city" ).text(data.name);
		}
		if(typeof data.weather[0].id !== "undefined"){
			$( "#weathericon").attr('class',"wi wi-owm-" + data.weather[0].id);
		}
		if(typeof data.main.temp !== "undefined"){
			$( "#temp" ).text(data.main.temp + " °C");
		}
		if(typeof data.weather[0].main !== "undefined"){
			$( "#description" ).text(data.weather[0].main);
		}
		if(typeof data.main.temp_max !== "undefined" && typeof data.main.temp_min !== "undefined"){
			$( "#forecast_details" ).html('Forecast: ' + data.main.temp_max + ' / ' + data.main.temp_min + '&nbsp;°C');
		}
		if(typeof data.wind.speed !== "undefined"){
			$( "#wind_details" ).html('Wind: ' + data.wind.speed + ' km/h');
		}
		if(typeof data.wind.deg !== "undefined"){
			$( "#wind_details" ).append(' <span class="comp sa20" ><i class="wi wi-wind towards-' + data.wind.deg + '-deg"></i></span> from ' + data.wind.deg + 'degree');
		}
	});
}

var ISO3166 = {
	"AF": "Afghanistan",
	"AX": "land Islands",
	"AL": "Albania",
	"DZ": "Algeria",
	"AS": "American Samoa",
	"AD": "Andorra",
	"AO": "Angola",
	"AI": "Anguilla",
	"AQ": "Antarctica",
	"AG": "Antigua and Barbuda",
	"AR": "Argentina",
	"AM": "Armenia",
	"AW": "Aruba",
	"AU": "Australia",
	"AT": "Austria",
	"AZ": "Azerbaijan",
	"BS": "Bahamas",
	"BH": "Bahrain",
	"BD": "Bangladesh",
	"BB": "Barbados",
	"BY": "Belarus",
	"BE": "Belgium",
	"BZ": "Belize",
	"BJ": "Benin",
	"BM": "Bermuda",
	"BT": "Bhutan",
	"BO": "Bolivia",
	"BQ": "Bonaire",
	"BA": "Bosnia and Herzegovina",
	"BW": "Botswana",
	"BV": "Bouvet Island",
	"BR": "Brazil",
	"IO": "British Indian Ocean Territory",
	"BN": "Brunei Darussalam",
	"BG": "Bulgaria",
	"BF": "Burkina Faso",
	"BI": "Burundi",
	"KH": "Cambodia",
	"CM": "Cameroon",
	"CA": "Canada",
	"CV": "Cape Verde",
	"KY": "Cayman Islands",
	"CF": "Central African Republic",
	"TD": "Chad",
	"CL": "Chile",
	"CN": "China",
	"CX": "Christmas Island",
	"CC": "Cocos (Keeling) Islands",
	"CO": "Colombia",
	"KM": "Comoros",
	"CG": "Congo",
	"CD": "Congo",
	"CK": "Cook Islands",
	"CR": "Costa Rica",
	"CI": "Cte d'Ivoire",
	"HR": "Croatia",
	"CU": "Cuba",
	"CW": "Curaao",
	"CY": "Cyprus",
	"CZ": "Czech Republic",
	"DK": "Denmark",
	"DJ": "Djibouti",
	"DM": "Dominica",
	"DO": "Dominican Republic",
	"EC": "Ecuador",
	"EG": "Egypt",
	"SV": "El Salvador",
	"GQ": "Equatorial Guinea",
	"ER": "Eritrea",
	"EE": "Estonia",
	"ET": "Ethiopia",
	"FK": "Falkland Islands (Malvinas)",
	"FO": "Faroe Islands",
	"FJ": "Fiji",
	"FI": "Finland",
	"FR": "France",
	"GF": "French Guiana",
	"PF": "French Polynesia",
	"TF": "French Southern Territories",
	"GA": "Gabon",
	"GM": "Gambia",
	"GE": "Georgia",
	"DE": "Germany",
	"GH": "Ghana",
	"GI": "Gibraltar",
	"GR": "Greece",
	"GL": "Greenland",
	"GD": "Grenada",
	"GP": "Guadeloupe",
	"GU": "Guam",
	"GT": "Guatemala",
	"GG": "Guernsey",
	"GN": "Guinea",
	"GW": "Guinea-Bissau",
	"GY": "Guyana",
	"HT": "Haiti",
	"HM": "Heard Island and McDonald Islands",
	"VA": "Holy See (Vatican City State)",
	"HN": "Honduras",
	"HK": "Hong Kong",
	"HU": "Hungary",
	"IS": "Iceland",
	"IN": "India",
	"ID": "Indonesia",
	"IR": "Iran",
	"IQ": "Iraq",
	"IE": "Ireland",
	"IM": "Isle of Man",
	"IL": "Israel",
	"IT": "Italy",
	"JM": "Jamaica",
	"JP": "Japan",
	"JE": "Jersey",
	"JO": "Jordan",
	"KZ": "Kazakhstan",
	"KE": "Kenya",
	"KI": "Kiribati",
	"KP": "Korea",
	"KR": "Korea",
	"KW": "Kuwait",
	"KG": "Kyrgyzstan",
	"LA": "Lao People's Democratic Republic",
	"LV": "Latvia",
	"LB": "Lebanon",
	"LS": "Lesotho",
	"LR": "Liberia",
	"LY": "Libya",
	"LI": "Liechtenstein",
	"LT": "Lithuania",
	"LU": "Luxembourg",
	"MO": "Macao",
	"MK": "Macedonia",
	"MG": "Madagascar",
	"MW": "Malawi",
	"MY": "Malaysia",
	"MV": "Maldives",
	"ML": "Mali",
	"MT": "Malta",
	"MH": "Marshall Islands",
	"MQ": "Martinique",
	"MR": "Mauritania",
	"MU": "Mauritius",
	"YT": "Mayotte",
	"MX": "Mexico",
	"FM": "Micronesia",
	"MD": "Moldova",
	"MC": "Monaco",
	"MN": "Mongolia",
	"ME": "Montenegro",
	"MS": "Montserrat",
	"MA": "Morocco",
	"MZ": "Mozambique",
	"MM": "Myanmar",
	"NA": "Namibia",
	"NR": "Nauru",
	"NP": "Nepal",
	"NL": "Netherlands",
	"NC": "New Caledonia",
	"NZ": "New Zealand",
	"NI": "Nicaragua",
	"NE": "Niger",
	"NG": "Nigeria",
	"NU": "Niue",
	"NF": "Norfolk Island",
	"MP": "Northern Mariana Islands",
	"NO": "Norway",
	"OM": "Oman",
	"PK": "Pakistan",
	"PW": "Palau",
	"PS": "Palestine",
	"PA": "Panama",
	"PG": "Papua New Guinea",
	"PY": "Paraguay",
	"PE": "Peru",
	"PH": "Philippines",
	"PN": "Pitcairn",
	"PL": "Poland",
	"PT": "Portugal",
	"PR": "Puerto Rico",
	"QA": "Qatar",
	"RE": "Runion",
	"RO": "Romania",
	"RU": "Russian Federation",
	"RW": "Rwanda",
	"BL": "Saint Barthlemy",
	"SH": "Saint Helena",
	"KN": "Saint Kitts and Nevis",
	"LC": "Saint Lucia",
	"MF": "Saint Martin (French part)",
	"PM": "Saint Pierre and Miquelon",
	"VC": "Saint Vincent and the Grenadines",
	"WS": "Samoa",
	"SM": "San Marino",
	"ST": "Sao Tome and Principe",
	"SA": "Saudi Arabia",
	"SN": "Senegal",
	"RS": "Serbia",
	"SC": "Seychelles",
	"SL": "Sierra Leone",
	"SG": "Singapore",
	"SX": "Sint Maarten (Dutch part)",
	"SK": "Slovakia",
	"SI": "Slovenia",
	"SB": "Solomon Islands",
	"SO": "Somalia",
	"ZA": "South Africa",
	"GS": "South Georgia and the South Sandwich Islands",
	"SS": "South Sudan",
	"ES": "Spain",
	"LK": "Sri Lanka",
	"SD": "Sudan",
	"SR": "Suriname",
	"SJ": "Svalbard and Jan Mayen",
	"SZ": "Swaziland",
	"SE": "Sweden",
	"CH": "Switzerland",
	"SY": "Syrian Arab Republic",
	"TW": "Taiwan",
	"TJ": "Tajikistan",
	"TZ": "Tanzania",
	"TH": "Thailand",
	"TL": "Timor-Leste",
	"TG": "Togo",
	"TK": "Tokelau",
	"TO": "Tonga",
	"TT": "Trinidad and Tobago",
	"TN": "Tunisia",
	"TR": "Turkey",
	"TM": "Turkmenistan",
	"TC": "Turks and Caicos Islands",
	"TV": "Tuvalu",
	"UG": "Uganda",
	"UA": "Ukraine",
	"AE": "United Arab Emirates",
	"GB": "United Kingdom",
	"US": "United States",
	"UM": "United States Minor Outlying Islands",
	"UY": "Uruguay",
	"UZ": "Uzbekistan",
	"VU": "Vanuatu",
	"VE": "Venezuela",
	"VN": "Viet Nam",
	"VG": "Virgin Islands",
	"VI": "Virgin Islands",
	"WF": "Wallis and Futuna",
	"EH": "Western Sahara",
	"YE": "Yemen",
	"ZM": "Zambia",
	"ZW": "Zimbabwe"
}
</script>
</html>