jQuery.fn.reorder = function() {
  // random array sort from
  // http://javascript.about.com/library/blsort2.htm
  function randOrd() { return(Math.round(Math.random())-0.5); }
 
  return(jQuery(this).each(function() {
    var $this = jQuery(this);
    var $children = $this.children();
    var childCount = $children.length;
 
    if (childCount > 1) {
      $children.remove();
 
      var indices = new Array();
      for (i=0;i<childCount;i++) { indices[indices.length] = i; }
      indices = indices.sort(randOrd);
      jQuery.each(indices,function(j,k) { $this.append($children.eq(k)); });
 
    }
  }));
}

jQuery(document).ready(function($) {
  jQuery.getJSON('/wp-content/themes/whitlam/get-recent-posts.php', function(data) {
    jQuery('#blogPosts').html(data);
    jQuery('#blogPosts').slideDown();
  });
  
jQuery(document).ready(function(){
  jQuery.getJSON('/wp-content/themes/whitlam/get-recent-posts2.php', function(data) {
	jQuery('#blogPostsResources').html(data);
    jQuery('#blogPostsResources').slideDown();
  });
});
  
  
  $('#more-benefits').bind('click', function() {
    if ( $('#benefits-info').is(':hidden') ) {
      $('#benefits-info').slideDown();
      $('#more-benefits').html('&minus;');
    } else {
      $('#benefits-info').slideUp();
      $('#more-benefits').html('+');
    }
    return false;
  });

  $('#more-recruitment').bind('click', function() {
    if ( $('#recruitment-info').is(':hidden') ) {
      $('#recruitment-info').slideDown();
      $('#more-recruitment').html('&minus;');
    } else {
      $('#recruitment-info').slideUp();
      $('#more-recruitment').html('+');
    }
    return false;
  });

  $('#customer-logos').show();


/*
  $('input[name="delivery-date"]').bind('focus', function(){
    console.log('test');
  });
*/
  $('#deliveryDate').datepicker();

});

sfHover = function() {
  var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


var currentSlide = 1;
var totalSlides  = 1;
var changeIntervalId;

jQuery(document).ready(function(){
  totalSlides = jQuery('ul.slide li').size();
  changeIntervalId = setInterval("changeSlide()", 5000);

  jQuery('ul.slide li').bind('click', function(){
    //clearInterval(changeIntervalId);
  });
});

function changeSlide() {
  currentSlide++;
  if ( currentSlide > totalSlides ) {
    currentSlide = 1;
  }
  jQuery('ul.slide li:nth-child('+currentSlide+')').find('a').trigger('click');
}
