﻿/* Copyright © DR Solutions International Ltd / Author: Andrew MacKie Green / 2009.10 */
/* DRS client script */

// GLOBAL VARIABLES:
var cUrl = window.location.pathname;
var cFilename = cUrl.substring(cUrl.lastIndexOf('/') + 1); if (cFilename.length == 0) { cFilename = "default.asp"; }
var cImageUrl = "resources/";  // Url path for image files.
//var cRequestUrl = "json.asp";  // Url path and filename to JSON request file.
//var cSplit = "|";  // Delimiter char for values.
//var cSplitSub = "~";  // Delimiter char for sub values.
//var cRecLimit = 10; // Default record limit count.
//var cDate = new Date();  // Current date.
//var cDay = cDate.getDay();  // Current day.
//var cWeekday = new Array(7); cWeekday[0] = "Sunday"; cWeekday[1] = "Monday"; cWeekday[2] = "Tuesday"; cWeekday[3] = "Wednesday"; cWeekday[4] = "Thursday"; cWeekday[5] = "Friday"; cWeekday[6] = "Saturday";
//var cFileSizeLimit = 209715200;  // Upload file size limit in bytes // 200MB.

// GLOBAL FUNCTIONS:
$.fn.idle = function(time, callback) {
  var i = $(this);
  i.queue(function() { setTimeout(function() { i.dequeue(); callback(i); }, time); });
};

$.fn.setHistoryBack = function() {
  var a = $(this);
  a.click(function() {
    history.go(-1);
  });
  return false;
};

$.fn.googleMap = function(address, options) {
  var defaults = {
    lat: 50.841395,
    long: -0.761189,
    zoom: 13,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    //      mapTypeId: google.maps.MapTypeId.SATELLITE
    //      mapTypeId: google.maps.MapTypeId.HYBRID
    //      mapTypeId: google.maps.MapTypeId.TERRAIN
  };
  options = $.extend(defaults, options || {});
  var center = new google.maps.LatLng(options.lat, options.long);
  var map = new google.maps.Map(this.get(0), $.extend(options, { center: center }));
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode({ address: address }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
        //map.set_center(results[0].geometry.location);
        var marker = new google.maps.Marker({
          position: results[0].geometry.location,
          map: map
        });

      }
    }
  });
};


$.fn.setBike = function() {
  var div = $(this), a = div.find("a[rel='rates']"), ul = div.find("ul.rates");
  a.click(function() {
    ul.slideToggle(250);
  });
};


// GLOBAL EVENTS:

// DOM READY:
$(document).ready(function() {
  $("a[rel*='back']").each(function() { $(this).setHistoryBack(); });
  $("a[rel*='external']").each(function() { this.target = "_blank"; });  // Sets target "_blank" for all <a> elements with rel "external".
  $("div.bike").each(function() { $(this).setBike(); });
  if ($("div#googleMap").length) { $("div#googleMap").googleMap("Unit 36, St James Industrial Estate, Westhampnett Road, Chichester, West Sussex, PO19 7JU"); }
});

