var IzikoPage = Class.create();
var SearchField = Class.create();

IzikoPage.prototype = {
 initialize: function() {
  this.searchBox = null;
  this.footerPadding = 0;
  this.isSafari = navigator.userAgent.match(/safari/gi);
  this.pathName = document.location.pathname;
  this.host = document.location.host;
  this.protocol = document.location.protocol;
  this.rootUrl = this.protocol + "//" + this.host;
 },
 
 loaded: function(e) {
  this.getExternalLinks('rel', 'external');
  this.searchBox = new SearchField('Keywords', 'Search');
  this.spanH3s();
  if ($("ContactMap")) {
   this.showContactMap();
  }
 },
 
 loadHomePromoFlash: function(movieURL) {
  if($("HomePromo")) {
   flashvar = ($("HomePromoLink")) ? "mainlink=" + $("HomePromoLink").getAttribute("href") : "mainlink=/";
   this.homePromoMovie = { 
    movie:movieURL,
    width:"696",
    height:"196",
    majorversion:"6",
    build:"40",
    flashvars:flashvar
   }
      UFO.create(this.homePromoMovie, "HomePromo");
  }
 },
 
 getExternalLinks: function(attr, val) {
  if (!document.getElementsByTagName) return;
  allLinks = $A(document.getElementsByTagName('a'));
  allLinks.each(function(lnk) {
   if (lnk.getAttribute(attr)==val) {
    Element.addClassName(lnk, val);
    Event.observe(
     lnk,
     'click',
     function(e) {
      newwind = window.open(Event.element(e).getAttribute('href'));
      newwind.focus();
      Event.stop(e);
     }
    );
    // Safari hack to overcome lack of event.preventDefault function
    if (this.isSafari) {
     lnk.onclick = function() { return false; };
    };
   }
  }.bind(this));
 },
 
 spanH3s: function() {
  h3s = $A($$('#Content h3'));
  h3s.each(function(h3) {
   if (!Element.hasClassName(h3, 'run-in')) {
    cloned = h3.firstChild.cloneNode(true);
    newSpan = document.createElement('span');
    newSpan.appendChild(cloned);
    h3.replaceChild(newSpan, h3.firstChild);
   }
  });
 },
 
 showContactMap: function() {
  /*document.write("<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAALPrdkKw0luNjtZ8rUHW1UxRIM7Z37K38eKitCdl1inssT_EGjxQVEonkpQk8BQF_g-sn5Be_sdozjA\" type=\"text/javascript\"></script>");
  if (GBrowserIsCompatible()) {
   this.gMap = new GMap2($("ContactMap"));
   this.gMap.setCenter(new GLatLng(-0.117180864437932, 51.525142572451), 13);
  } */
  
 }
};
SearchField.prototype = {
 initialize: function(el, startVal) {
  this.el = $(el);
  this.startVal = startVal;
  this.doblur();
  Event.observe(this.el, "focus", this.dofocus.bind(this));
  Event.observe(this.el, "blur", this.doblur.bind(this));
 },
 
 dofocus: function() {
  this.el.value = (this.el.value == this.startVal) ? '' : this.el.value;
 },
 
 doblur: function() {
  this.el.value = (this.el.value == '') ? this.startVal : this.el.value;
 } 
 
};

var thisPage = new IzikoPage();
Event.observe(window, 'load', thisPage.loaded.bind(thisPage));