Array.prototype.shuffle = function(b)
{
 var i = this.length, j, t;
 while( i )
 {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }

 return this;
};

$(document).ready(function() {
  var works = new Array();
  works[0] = {
    name: 'You Deserve A Holiday 2010 Campaign',
    post : 'P&amp;O Ferries',
    image : '/img/work-images/PO_ferries_YDAH_2010_press_ads/po_ydah.jpg',
    page : '/ourwork/you_deserve_a_holiday_2010.html'
  }
  works[1] = {
    name : 'Brand Campaign',
    post : 'Wales in Style',
    image : '/img/work-images/Wales_in_Style/WIS_thumbnail.jpg',
    page : '/ourwork/wales_in_style.html'
  }
  works[2] = {
    name : 'We\'re Your Link Campaign',
    post : 'Wightlink Ferries',
    image : '/img/work-images/Wightlink/wighlink_thumbnail.gif',
    page : '/ourwork/wightlink_ferries.html'
  }
  works[3] = {
    name : 'Make Yourself a Star',
    post : 'Lancashire and Blackpool Tourist Board',
    image : '/img/work-images/Blackpool/Blackpool_thumbnail.jpg',
    page : '/ourwork/blackpool_tourist_board.html'
  }
  works[4] = {
    name : 'More Than Just  A Coach Company Campaign',
    post : 'Shearings Holidays',
    image : '/img/work-images/Shearings/Work_shearings_thumbnail.jpg',
    page : '/ourwork/shearings_holidays.html'
  }
  works[5] = {
    name : 'Big Red Brochure Campaign',
    post : 'Virgin Holidays',
    image : '/img/work-images/Virgin/Virgin_thumbnail.jpg',
    page : '/ourwork/virgin_holidays_brochures.html'
  }
  works[6] = {
    name : 'Local Heroes',
    post : 'Thomson Holidays',
    image : '/img/work-images/Thomson/thomson_thumb_1.jpg',
    page : '/ourwork/thomson_holidays_local_heroes.html'
  }
  works[7] = {
    name : '40th Birthday Campaign',
    post : 'Travel Weekly',
    image : '/img/work-images/TravelWeekly/tw_thumbnail.jpg',
    page : '/ourwork/travel_weekly.html'
  }
  works[8] = {
    name : '2010 Brand Campaign',
    post : 'LV=',
    image : '/img/work-images/LV2010/lv_thumbnail_v1.jpg',
    page : '/ourwork/lv2010.html'
  }

  works.shuffle();

  for(var i = 0; i < works.length; i++) {
    var element;
    element  = '<a href="' + works[i].page + '"><img src="' + works[i].image +'" alt="" /></a>';
    element += '<h5><a href="' + works[i].page + '">' + works[i].name +'</a></h5>';
    element += '<p>' + works[i].post + '</p>';

    var child = $("<li></li>").append(element);

    $(".workList").append(child);
  }

});
