﻿/* Global JavaScript (requires Mootools v1.2)
 *
 * Original Author: Karen Comber, Webexpectations.com
 * Last updated: 2008/09/03
 *
 */

/* - Initialisation (runs functions common to all pages) - */

window.addEvent('domready', function() {
  attachExternals(); // Make external links open in a new window.
  menuOvers(); //hover fix for ie
  var images = [
    '/_images/home-banner-syrups-hover.jpg',
    '/_images/home-banner-crystal-hover.jpg',
    '/_images/home-banner-treacle-hover.jpg',
    '/_images/home-banner-custom-hover.jpg',
    '/_images/home-banner-organic-hover.jpg',
    '/_images/back-sidenav-h2-hover.gif',
    '/_images/back-leftsignpost-a-hover.png',
    '/_images/back-mainsignpost-hover.gif',
    '/_images/back-mainsignpost-h2-hover.gif',
    '/_images/80years_badge-hover.gif',
    '/_images/naturalchoice_badge-hover.gif',
    '/_images/products_syrups-hover-alt.jpg',
    '/_images/products_crystal-hover.jpg',
    '/_images/products_treacle-hover.jpg',
    '/_images/products_custom-hover.jpg',
    '/_images/products_organic-hover-alt.jpg',
    '/_images/bgd-products_signpost-hover.jpg',
    '/_images/bgd-products_signpost-hover.jpg',
    '/_images/search-signpost-bottom-hover.gif',
    '/_images/search-signpost-top-hover.gif',
    '/_images/background-header-search-hover',
    '/_images/contact-button-hover.gif',
    '/_images/background-header-search-hover.gif'
  ];
  preloadImages(images); // Preload specific images (usually for hover states).
  new SmoothScroll(); // Enable smooth scrolling for anchors.
});

/* - Functions - */

function attachExternals() {
  var extLinks = $$('a.external');
  extLinks.each(function(extLink, i){
    extLink.setProperty('target','_blank');
  });
}

function menuOvers () {
  var lis = $$('ul#navbar li','div.contactus','div.back-send-l','div.security','div.staffmember img','div#homepg div#homeconversions a','div#google a','form#cse-search-box input.button','input#contact-submit','input#blogsearchbutton');
  lis.each(function(li){
    li.addEvent('mouseenter',function(){
      li.addClass('over');
    });
    li.addEvent('mouseleave',function(){
      li.removeClass('over');
    });
  });
}

function preloadImages (imagearray) {
  imagearray.each(function(image){
    var preloader = new Element('div', {'class': 'preloader'});
    preloader.inject($('headerholder'),'bottom');
    preloader.setStyle('background','url(' + image + ')');
  });
  (function(){ $$('div.preloader').destroy(); }).delay(1000);
}



