/*========================*/
/* Bespoke Simple Tooltip */
/*========================*/

$(document).ready(function() { 
    //Anchor tags with rel of tooltip will initialise
    $('a[ref=tooltip]').mouseover(function(e) {         
        //Append the tooltip layout with the contents of the tooltip rel item
        $(this).append('<div class="tooltip"><div class="tooltip_top">' + $(this).html() + '</div><div class="tooltip_footer"></div></div>');         
    }).mouseout(function() {
        //Remove the appended tooltip
        $(this).children('.tooltip').remove();         
    }); 
});


/*=====================*/
/* Bespoke Simple Tabs */
/*=====================*/

$(document).ready(function(){

   // Set up a listener so that when anything with a class of 'tab' 
   // is clicked, this function is run.
   $('.tabd').click(function () {

    // Remove the 'active' class from the active tab.
    $('.tabs > li.active').removeClass('active');
      
    // Add the 'active' class to the clicked tab.
    $(this).parent().addClass('active');

    // Remove the 'tab_contents_active' class from the visible tab contents.
    $('.tab_contents_container > div.tab_contents_active').removeClass('tab_contents_active');

    // Add the 'tab_contents_active' class to the associated tab contents.
    $(this.rel).addClass('tab_contents_active');

  });
});


/*================================================================================*/
/* Shuffle function - used in Featured area to randomise image order on page load */
/*================================================================================*/


/*
 * jQuery shuffle
 *
 * Copyright (c) 2008 Ca-Phun Ung <caphun at yelotofu dot com>
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://yelotofu.com/labs/jquery/snippets/shuffle/
 *
 * Shuffles an array or the children of a element container.
 * This uses the Fisher-Yates shuffle algorithm <http://jsfromhell.com/array/shuffle [v1.0]>
 */
 
(function($){

  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children().clone(true);
      return (items.length) ? $(this).html($.shuffle(items)) : this;
    });
  }
  
  $.shuffle = function(arr) {
    for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
    return arr;
  }
  
 })(jQuery);

function go(url){
    window.location.href = url;
}

var elms;
var valcount;

function validateForm (form){
  elms = [];
  valcount = 0;
  try{
    $(".enquiry.required").each(function(intIndex){
      if(this.value.length < 1){
        this.style.borderColor = '#F00';
        //elms.push();
        //this.prev().css('color','#F00');
        valcount++;
      } else {
        this.style.borderColor = '#a3c646';
      }
    });
  }catch(err){
    console.log(err);
    valcount++;
  }

  if(valcount > 0){
    $('#txt_warning').html('<p style="color:#F00"><strong>Please complete all required fields</strong></p>');
    return false;
  } else {
    $('#txt_warning').html('');
    form.submit();
  }
}

