window.onload = initPage;

function initPage() {
  externalLinks();
  insertFlashObject("flash", "flash/banner.swf", 935, 178, "");
  checkMootools();
  if(document.getElementById('contact_name')) {
    document.getElementById('contact_name').onfocus = clearfield;
    document.getElementById('contact_name').onblur = reinstatefield;
    document.getElementById('contact_address').onfocus = clearfield;
    document.getElementById('contact_address').onblur = reinstatefield;
    document.getElementById('contact_postcode').onfocus = clearfield;
    document.getElementById('contact_postcode').onblur = reinstatefield;
    document.getElementById('contact_telephone').onfocus = clearfield;
    document.getElementById('contact_telephone').onblur = reinstatefield;
    document.getElementById('contact_email').onfocus = clearfield;
    document.getElementById('contact_email').onblur = reinstatefield;
    document.getElementById('contact_enquiry').onfocus = clearfield;
    document.getElementById('contact_enquiry').onblur = reinstatefield;
  }  
}

function trim(str, chars) {
  var replaceLeft, replaceRight;
  chars = chars || "\\s";
  replaceLeft = str.replace(new RegExp("^[" + chars + "]+", "g"), "");
  replaceRight = replaceLeft.replace(new RegExp("[" + chars + "]+$", "g"), "");
  return replaceRight;
}

function clearfield() {
  switch(this.id) {
    case 'contact_name':
      trimValue = trim(this.value);
      if(trimValue == 'Name: *') {
        this.value = '';
      }
    break;
    
    case 'contact_address':
      trimValue = trim(this.value);
      if(trimValue == 'Address:') {
        this.value = '';
      }
    break;
    
    case 'contact_postcode':
      trimValue = trim(this.value);
      if(trimValue == 'Postcode:') {
        this.value = '';
      }
    break;
    
    case 'contact_telephone':
      trimValue = trim(this.value);
      if(trimValue == 'Telephone:') {
        this.value = '';
      }
    break;
    
    case 'contact_email':
      trimValue = trim(this.value);
      if(trimValue == 'Email: *') {
        this.value = '';
      }
    break;
    
    case 'contact_enquiry':
      trimValue = trim(this.value);
      if(trimValue == 'Enquiry: *') {
        this.value = '';
      }
    break;
  }
}

function reinstatefield() {
  switch(this.id) {
    case 'contact_name':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Name: *';
      }
    break;
    
    case 'contact_address':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Address:';
      }
    break;
    
    case 'contact_postcode':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Postcode:';
      }
    break;
    
    case 'contact_telephone':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Telephone:';
      }
    break;
    
    case 'contact_email':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Email: *';
      }
    break;
    
    case 'contact_enquiry':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Enquiry: *';
      }
    break;
  }
}

function externalLinks() { 
  if(!document.getElementsByTagName) {
    return;
  }
  var anchors = document.getElementsByTagName("a"); 
  for(var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" ) {
      anchor.target = "_blank";
    }
  }
  if(document.getElementById('regionselect')) {
    document.getElementById('regionselect').onchange = regionSelect; 
  } 
}

function regionSelect() {
  if(this.value != 0) {
    window.location = "region.htm?region=" + this.value;
  }
}

function insertFlashObject(objID, flashLocation, width, height, flashString) {
  var flashObject;
  flashObject = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + width + "' height='" + height + "'>";
  flashObject = flashObject + "<param name='wmode' value='transparent'>";
  flashObject = flashObject + "<param name='movie' value='" + flashLocation + "' />";
  flashObject = flashObject + "<param name='quality' value='high' />";
  if(typeof(flashString) == "undefined") {
    flashObject = flashObject + "<embed src='" + flashLocation + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' wmode='transparent'";
  } else {
    flashObject = flashObject + "<param name='FlashVars' value='" + flashString + "'";
    flashObject = flashObject + "<embed src='" + flashLocation + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' wmode='transparent' ";
    flashObject = flashObject + "FlashVars='" + flashString + "'";
  }
  flashObject = flashObject + "></embed></object>";
  if(document.getElementById(objID)) {
    document.getElementById(objID).innerHTML = flashObject;
  }
}

function checkMootools() {
var anchors = document.getElementsByTagName("a");
  var moobox = false;
  for(var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "video") {
      moobox = true;
    }
  }
  if(moobox == true) {
    window.addEvent('domready', Videobox.init.bind(Videobox));
  }
}

function display_overlay(url) {
  var objLink = document.createElement('a');
  objLink.setAttribute('href', url);
  objLink.setAttribute('rel', 'overlay');
  jQuery.prototype.start(objLink);
}

if(typeof(jQuery) != "undefined") {
(function($) {
$.fn.lightBox = function(settings) {
settings = jQuery.extend({
overlayBgColor: '#000000',
overlayOpacity:  0.8,
fixedNavigation: false,
imageLoading: 'images/icons/loading.gif',
imageBtnClose: 'images/buttons/close.jpg',
imageBlank:  'images/icons/blank.gif',
containerBorderSize: 10,
containerResizeSpeed:  400,
imageArray: [],
activeImage: 0
},settings);
var jQueryMatchedObj = this;
function _initialize() {
_start(this,jQueryMatchedObj); return false;
}
function _start(objClicked,jQueryMatchedObj) {
$('embed, object, select').css({ 'visibility' : 'hidden' });
_set_interface();
settings.imageArray.length = 0;
settings.activeImage = 0;
if(jQueryMatchedObj.length == 1) {
settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
} else {
for(var i=0;i<jQueryMatchedObj.length;i++) {
settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
}
}
while(settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href')) {
settings.activeImage++;
}
_set_image_to_view();
}
function _set_interface() {
$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>');  
var arrPageSizes = ___getPageSize();
$('#jquery-overlay').css({
backgroundColor: settings.overlayBgColor,
opacity: settings.overlayOpacity,
width: arrPageSizes[0],
height: arrPageSizes[1]
}).fadeIn();
var arrPageScroll = ___getPageScroll();
$('#jquery-lightbox').css({
top: arrPageScroll[1] + (arrPageSizes[3] / 10),
left: arrPageScroll[0]
}).show();
$('#jquery-overlay,#jquery-lightbox').click(function() {
_finish();                  
});
$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
_finish();
return false;
});
$(window).resize(function() {
var arrPageSizes = ___getPageSize();
$('#jquery-overlay').css({
width: arrPageSizes[0],
height: arrPageSizes[1]
});
var arrPageScroll = ___getPageScroll();
$('#jquery-lightbox').css({
top: arrPageScroll[1] + (arrPageSizes[3] / 10),
left: arrPageScroll[0]
});
});
}
function _set_image_to_view() {
$('#lightbox-loading').show();
if(settings.fixedNavigation) {
$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
} else {
$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
}
var objImagePreloader = new Image();
objImagePreloader.onload = function() {
$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
objImagePreloader.onload=function() {};
};
objImagePreloader.src = settings.imageArray[settings.activeImage][0];
};
function _resize_container_image_box(intImageWidth,intImageHeight) {
var intCurrentWidth = $('#lightbox-container-image-box').width();
var intCurrentHeight = $('#lightbox-container-image-box').height();
var intWidth = (intImageWidth + (settings.containerBorderSize * 2));
var intHeight = (intImageHeight + (settings.containerBorderSize * 2));
var intDiffW = intCurrentWidth - intWidth;
var intDiffH = intCurrentHeight - intHeight;
$('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
if((intDiffW == 0) && (intDiffH == 0)) {
if($.browser.msie) {
___pause(250);
} else {
___pause(100);  
}
} 
$('#lightbox-container-image-data-box').css({ width: intImageWidth });
$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
};
function _show_image() {
$('#lightbox-loading').hide();
$('#lightbox-image').fadeIn(function() {
_show_image_data();
});
};
function _show_image_data() {
$('#lightbox-container-image-data-box').slideDown('fast');
$('#lightbox-image-details-caption').hide();
if(settings.imageArray[settings.activeImage][1]) {
$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();
}
}
function _finish() {
$('#jquery-lightbox').remove();
$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
$('embed, object, select').css({ 'visibility' : 'visible' });
}
function ___getPageSize() {
var xScroll, yScroll;
if(window.innerHeight && window.scrollMaxY) {  
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if(document.body.scrollHeight > document.body.offsetHeight) {
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else {
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if(self.innerHeight) {
if(document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth; 
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if(document.documentElement && document.documentElement.clientHeight) {
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if(document.body) {
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}  
if(yScroll < windowHeight) {
pageHeight = windowHeight;
} else { 
pageHeight = yScroll;
}
if(xScroll < windowWidth) {  
pageWidth = xScroll;    
} else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
return arrayPageSize;
};
function ___getPageScroll() {
var xScroll, yScroll;
if(self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if(document.documentElement && document.documentElement.scrollTop) {
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if(document.body) {
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;  
}
arrayPageScroll = new Array(xScroll,yScroll);
return arrayPageScroll;
};
function ___pause(ms) {
var date = new Date(); 
curDate = null;
do { var curDate = new Date(); } while(curDate - date < ms);
};
return this.unbind('click').click(_initialize);
};

$(function() { $('a[@rel*=overlay]').lightBox(); }); 

})(jQuery);
}

var Videobox = {
init: function (options) {
this.options = Object.extend({
resizeDuration: 80,
initialWidth: 425,
initialHeight: 350,
defaultWidth: 425,
defaultHeight: 350,
animateCaption: true,
flvplayer: 'flash/flvplayer.swf'
}, options || {});
this.anchors = [];
$A($$('a')).each(function(el) {
if(el.rel && el.href && el.rel.test('^video', 'i')) {
el.addEvent('click', function (e) {
e = new Event(e);
e.stop();
this.click(el);
}.bind(this));
this.anchors.push(el);
}
}, this);
this.overlay = new Element('div').setProperty('id', 'lbOverlay').injectInside(document.body);
this.center = new Element('div').setProperty('id', 'lbCenter').setStyles({width: this.options.initialWidth + 'px', height: this.options.initialHeight + 'px', marginLeft: '-' + (this.options.initialWidth/2) + 'px', display: 'none'}).injectInside(document.body);
this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainer').setStyle('display', 'none').injectInside(document.body);
this.bottom = new Element('div').setProperty('id', 'lbBottom').injectInside(this.bottomContainer);
new Element('a').setProperties({id: 'lbCloseLink', href: '#'}).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
this.caption = new Element('div').setProperty('id', 'lbCaption').injectInside(this.bottom);
this.number = new Element('div').setProperty('id', 'lbNumber').injectInside(this.bottom);
new Element('div').setStyle('clear', 'both').injectInside(this.bottom);
var nextEffect = this.nextEffect.bind(this);
this.fx = {
overlay: this.overlay.effect('opacity', {duration: 500}).hide(),
center: this.center.effects({duration: 500, transition: Fx.Transitions.sineInOut, onComplete: nextEffect}),
bottom: this.bottom.effect('margin-top', {duration: 400})
};
},
click: function(link) { return this.open (link.href, link.title, link.rel); },
open: function(sLinkHref, sLinkTitle, sLinkRel) {
this.href = sLinkHref;
this.title = sLinkTitle;
this.rel = sLinkRel;
this.position();
this.setup();
this.video(this.href);
this.top = Window.getScrollTop() + (Window.getHeight() / 15);
this.center.setStyles({top: this.top + 'px', display: ''});
this.fx.overlay.start(0.8);
this.step = 1;
this.center.setStyle('background','#FFFFFF url(images/icons/loading.gif) no-repeat center');
this.caption.innerHTML = this.title;
this.fx.center.start({'height': [this.options.contentsHeight]});
},
setup: function() {
var aDim = this.rel.match(/[0-9]+/g);
this.options.contentsWidth = (aDim && (aDim[0] > 0)) ? aDim[0] : this.options.defaultWidth;
this.options.contentsHeight = (aDim && (aDim[1] > 0)) ? aDim[1] : this.options.defaultHeight;
},
position: function() {
this.overlay.setStyles({'top': window.getScrollTop() + 'px', 'height': window.getHeight() + 'px'});
},
video: function(sLinkHref) {
if(sLinkHref.match(/youtube\.com\/watch/i)) {
this.flash = true;
var hRef = sLinkHref;
var videoId = hRef.split('=');
this.videoID = videoId[1];
this.so = new SWFObject("http://www.youtube.com/v/" + this.videoID, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
this.so.addParam("wmode", "transparent");
} else if(sLinkHref.match(/google\.com\/videoplay/i)) {
this.flash = true;
var hRef = sLinkHref;
var videoId = hRef.split('=');
this.videoID = videoId[1];
this.so = new SWFObject("http://video.google.com/googleplayer.swf?docId=" + this.videoID + "&hl=en", "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
this.so.addParam("wmode", "transparent");
} else if(sLinkHref.match(/\.mov/i)) {
this.flash = false;
if(navigator.plugins && navigator.plugins.length) {
this.other ='<object id="qtboxMovie" type="video/quicktime" codebase="http://www.apple.com/qtactivex/qtplugin.cab" data="' + sLinkHref + '" width="' + this.options.contentsWidth + '" height="' + this.options.contentsHeight + '"><param name="src" value="' + sLinkHref + '" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
} else {
this.other = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' + this.options.contentsWidth + '" height="' + this.options.contentsHeight + '" id="qtboxMovie"><param name="src" value="' + sLinkHref + '" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
}
} else if(sLinkHref.match(/\.wmv/i) || sLinkHref.match(/\.asx/i)) {
this.flash = false;
this.other = '<object NAME="Player" WIDTH="'+this.options.contentsWidth + '" HEIGHT="' + this.options.contentsHeight + '" align="left" hspace="0" type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param NAME="URL" VALUE="' + sLinkHref + '"><param><param NAME="AUTOSTART" VALUE="false"></param><param name="showControls" value="true"></param><embed WIDTH="' + this.options.contentsWidth + '" HEIGHT="' + this.options.contentsHeight + '" align="left" hspace="0" SRC="' + sLinkHref + '" TYPE="application/x-oleobject" AUTOSTART="false"></embed></object>'
} else if(sLinkHref.match(/\.flv/i)) {
this.flash = true;
this.so = new SWFObject(this.options.flvplayer + "?file=" + sLinkHref, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0", "#000000");
} else {
this.flash = true;
this.videoID = sLinkHref;
this.so = new SWFObject(this.videoID, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
}
},
nextEffect: function() {
switch (this.step++) {
case 1:
this.fx.center.start({'width': [this.options.contentsWidth], 'marginLeft': [this.options.contentsWidth / -2]}); break; this.step++;
case 2:
this.center.setStyle('background','#FFFFFF');
this.flash ? this.so.write(this.center) : this.center.setHTML(this.other) ;
this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight) + 'px', height: '0px', marginLeft: this.center.style.marginLeft, width: this.options.contentsWidth + 'px',display: ''});
if(this.options.animateCaption) {
this.fx.bottom.set(-this.bottom.offsetHeight);
this.bottomContainer.style.height = '';
this.fx.bottom.start(0);
break;
}
this.bottomContainer.style.height = '';
this.step++;
}
},
close: function() {
this.fx.overlay.start(0);
this.center.style.display = this.bottomContainer.style.display = 'none';
this.center.innerHTML = '';
return false;
}
};