﻿/* 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); });
};

$.setFooter = function() {
  var b = $("#body"), f = $("#foot");
  f.addClass("fixed");
  //if ($("#body").offset().top + $("#body").height() < $(window).height()) { $("#foot").addClass("absolute"); } else { $("#foot").removeClass("absolute"); }
  b.css("min-height", ((f.offset().top - 2) - ($("#head").height() + $("#menu").height())));
  f.removeClass("fixed");
};

$.fn.setMenu = function() {
  var ul = $(this);
  ul.find("li > a[rel*='menu']").each(function() {
    var a = $(this), menu = ul.find("ul#" + a.attr("rel"));
    menu.css("left", ul.offset().left).css("top", ul.offset().top + 35);
    a.mouseover(function() {
      ul.find("ul[id*='menu'][id!='" + menu.attr("id") + "']").fadeOut(300);
      menu.slideDown(200);
    });
    menu.mouseleave(function() {
      ul.idle(500, function(ul) {
        ul.find("li.sub > ul").each(function() {
          if ($(this).is(":visible")) { $(this).slideUp(300); }
        });
      });
    });
  });
};

$.fn.googleMap = function(address, options) {
  var defaults = {
    lat: 50.80863989938619,
    long: -0.5403470993041992,
    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.setTestimonialLink = function() {
  var a = $(this), aRel = a.attr("rel"), img = $("img#testimonialBanner");
  a.click(function() {
    img.attr("src", aRel);
    return false;
  });
};

// GLOBAL EVENTS:
$(window).resize(function() { $.setFooter(); });

// DOM READY:
$(document).ready(function() {
  $.setFooter();
  $("ul#menu").setMenu();
  $("a[rel*='external']").each(function() { this.target = "_blank"; });  // Sets target "_blank" for all <a> elements with rel "external".
  //$("ul#menu > li > a[rel='" + cFilename.split(".")[0] + "']").addClass("active");  // Sets "active" class for active page <a> element.
  $("#rotate").cycle({ fx: "fade", timeout: 5000 });
  $(".lightbox a").lightBox({
    imageLoading: "resources/lightbox/lightbox-ico-loading.gif",
    imageBtnPrev: "resources/lightbox/lightbox-btn-prev.gif",
    imageBtnNext: "resources/lightbox/lightbox-btn-next.gif",
    imageBtnClose: "resources/lightbox/lightbox-btn-close.gif",
    imageBlank: "resources/lightbox/images/lightbox-blank.gif"
  });
  $("#scroll").scrollable({ size: 5, activeClass: "" });
  $("div.testimonials-button a").each(function() { $(this).setTestimonialLink(); }); // Sets testimonial banner swap links.
});

