<?php
/* 
 * View script for the OurResorts controller
 * 
 * @change      01/05/2012 - scott.collins@wyn.com - 
 *                           Provide show resort features button - hidden by default
 *                           Remove the default text from the video button. Set it based on resort selection,
 *                           as the video may be an artist impression 
 * 
 */

global $GoogleAPIKey;

$this->HeadScript()->appendFile("scripts/common.js"); // Common JS functions
$this->HeadScript()->appendFile("http://www.google.com/jsapi?key=$GoogleAPIKey"); // Google API javascript
$this->HeadScript()->appendFile("data/resortLocationData.js");         // JSON file containing resort locations
$this->HeadScript()->appendFile("scripts/resortlocations.js"); // Javascript functions for this page

$this->headTitle ( 'Resorts' );
$this->placeholder ('title' )->set ( 'Resorts' );
$this->placeholder('backgroundimage')->set("bg_plain.jpg");


// Default video url is /videos/ from the same server
$gVideoURL = "/videos/";


// For remote sites, change the video URL to the local server.
$clientIP = $_SERVER['REMOTE_ADDR'];
$ip = explode('.', $clientIP);
if ($ip[2] == "120") { $gVideoURL = "\\\\nzmadca0\\video$\\"; }
if ($ip[2] == 206) {
    if (($ip[3] > 129) &&  ($ip[3] < 190)) { $gVideoURL = "\\\\auwadba2\\video$\\"; }
    if (($ip[3] > 65)  &&  ($ip[3] < 94))  { $gVideoURL = "\\\\auwadca1\\video$\\"; }
}
if ($ip[2] == "207") { $gVideoURL = "\\\\nzmadca0\\video$\\"; }
if ($ip[2] == "208") { $gVideoURL = "\\\\fjnadca1\\video$\\"; }
if ($ip[2] == "210") { $gVideoURL = "\\\\nzwadca0\\video$\\"; }
if ($ip[2] == "211") { $gVideoURL = "\\\\aunsdca2\\video$\\"; }
if ($ip[2] == "212") { $gVideoURL = "\\\\goldenbeachdc\\video$\\"; }
if ($ip[2] == "213") { $gVideoURL = "\\\\kirradc\\video$\\"; }
if ($ip[2] == "214") { 
    if (($ip[3] > 1) &&  ($ip[3] < 65)) { $gVideoURL = "\\\\auvidca0\\video$\\"; }
    if (($ip[3] > 65)  &&  ($ip[3] < 126))  { $gVideoURL = "\\\\auvidca2\\video$\\"; }
}
if ($ip[2] == "215") { 
    if (($ip[3] > 1) &&  ($ip[3] < 65)) { $gVideoURL = "\\\\aunsdca3\\video$\\"; }
    if (($ip[3] > 65)  &&  ($ip[3] < 126))  { $gVideoURL = "\\\\auqldba2\\video$\\"; }
    if (($ip[3] > 129)  &&  ($ip[3] < 254))  { $gVideoURL = "\\\\auqldca1\\video$\\"; }
}
if ($ip[2] == "216") { 
    if (($ip[3] > 1) &&  ($ip[3] < 65)) { $gVideoURL = "\\\\tssydneydc\\video$\\"; }
    if (($ip[3] > 65)  &&  ($ip[3] < 126))  { $gVideoURL = "\\\\aunsdca1\\video$\\"; }
    if (($ip[3] > 129)  &&  ($ip[3] < 190))  { $gVideoURL = "\\\\auqldca7\\video$\\"; }
}
if ($ip[2] == "219") { $gVideoURL = "\\\\hobartdc\\video$\\"; }

?>

<script>
  var gVideoURL = "<?php echo(str_replace("\\", "\\\\", $gVideoURL)); ?>";

  google.load("earth", "1.8");
  google.setOnLoadCallback(init);

  var ge = null;

  function init() {
    // WARNING: Hack for Firefox
    // See for more detail: http://code.google.com/p/earth-api-samples/issues/detail?id=141
    displayNoneWorkaround("googlemap");
    
    // Create the GE plugin instance
    google.earth.createInstance("googlemap", initCallback, failureCallback);
  }
  
  function initCallback(object) {
    ge = object;
    ge.getWindow().setVisibility(true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true); 
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
    ge.getOptions().setAtmosphereVisibility(true);
    ge.getOptions().setMouseNavigationEnabled(true);
    
    la = ge.createLookAt('');
    la.set(-27.0,150.0,0,ge.ALTITUDE_RELATIVE_TO_GROUND,0,0,7000000);
    ge.getView().setAbstractView(la);
       
    // Populate the list
    initList();

    <?php 
        // Jump to a specific resort according to URL, eg /ourresorts/listid=1
        $listid = "";
        if ($_REQUEST) { $listid = $_REQUEST["listid"]; }
        if ($listid != "") {
            
    ?>
            var listid="<?php echo $listid; ?>";
            var lResorts = document.getElementById("resort_sel");
            if (lResorts == null) return;

            // This is all necessary because IE6 is stupid:
            lResorts.options[listid].setAttribute('selected', true);
            lResorts.selectedIndex = listid;
            ListChanged(lResorts);
    <?php
        }
    ?>
  }
    
  function failureCallback(object) {
    
  }
</script>

<div id="left_panel_ourresorts">
    <fieldset class="resortlocations">
      <legend>Show on the Globe</legend> 

      <select onChange="ListChanged(this)" name="resort_sel" id="resort_sel" size=1 style="width: 300px;">
        <option>(loading resorts, please wait)</option>
      </select>
    </fieldset>
    <br/>
    
    <div id="btn_resort_video" onclick="ShowResortVideo()" style="display:none;"></div>
    <div id="resort_thumbnails"></div>        
    <div id="btn_resort_feature" onclick="ShowFeatures()" style="display:none;">Show Features</div>    
    <div id="btn_return_to_map" onclick="ReturnToMap()" style="display:none;">Return to globe</div>
</div>


<div id="resort_content"></div>

<div id="right_panel">
  <div id="googlecontainer" class="ChartContainer"><div id="googlemap" style="height:100%;"></div></div>  
</div>

