jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$("document").ready(function() {
   $.preloadImages("./images/portfolio/Workpocket.jpg"); 
   $.preloadImages("./images/portfolio/Diana%20Trust.jpg"); 
});

function changeImage(option) {
    // Load which images shall be in the slideshow
    var portfolioImage = new Array();
    portfolioImage[1] = "Workpocket.jpg";
    portfolioImage[2] = "Diana%20Trust.jpg";
    portfolioImage[3] = "Discover.jpg";
    portfolioImage[4] = "Lambeth-lone%20parent.jpg";
    portfolioImage[5] = "Orbital.jpg";
    portfolioImage[6] = "Kimpton.jpg";
    portfolioImage[7] = "Katanga%20Orientation2.jpg";
    portfolioImage[8] = "Lamplight.jpg";
    portfolioImage[9] = "SmartetEnergy.jpg";
    portfolioImage[10] = "Microfolia.jpg";
    portfolioImage[11] = "Paul%20Hamlyn.jpg";
    portfolioImage[12] = "Loxford.jpg";
    portfolioImage[13] = "CofA.jpg";
    
    var portfolioText = new Array();
    portfolioText[1] = "Workpocket is an annually-updated, easy-to-follow guide to employment legislation and best practice, which we research, write and design for <b>Randstad</b>, one of Europe’s leading recruitment consultancies. Writing is shared between specialist HR writers and our in-house editors. Now in its sixth year, the Workpocket is distributed to Randstad’s clients as part of the company’s ongoing commitment to thought-leadership and knowledge sharing.";
    portfolioText[2] = "<b>The Diana, Princess of Wales Memorial Fund</b> co-ordinated the campaign to ban cluster bombs. Mot Juste was commissioned to create the identity of the campaign under the banner ‘Lethal litter, the work continues’.";
    portfolioText[3] = "<b>Croydon Enterprise</b> is seeking to strengthen community involvement and local business partnerships as part of its urban regeneration programme. A key aim is encouraging residents to take a fresh look at the opportunities on their doorstep. Mot Juste researched and produced a series of ‘Discover’ leaflets and a loyalty card scheme for seven of the borough’s town centres.";
    portfolioText[4] = "Getting single parents back into work in a deprived area such as Lambeth is not an easy task. Although there are a number of agencies there to help, uptake of their services is low and <b>Lambeth Lone Parent into Work Partnership</b> was launched to point lone parents in the right direction. Mot Juste devised a wall chart and leaflet<br />to promote the initiative and a significant number of people are now getting ready to re-enter the workplace.";
    portfolioText[5] = "The Mot Juste-produced <b>Orbital Sound</b> brochure won high marks from Communicators in Business award judges. “What a cracking package” was their verdict.";
    portfolioText[6] = "From dazzling stage productions to thought-provoking exhibitions, leading scenery builders <b>Kimpton Walker</b> brings innovative and challenging designs to life. Mot Juste produced a series of mail shots, each targeting a different sector of the industry.";
    portfolioText[7] = "<b>Katanga Mining</b> is keen to play a strong and positive role in the socio-economic development of the countries in which it operates. The company’s codes of practice set out the exacting standards it expects from its staff in achieving this aim. Mot Juste designed a series of handbooks and manuals to make the information accessible to Katanga’s diverse international workforce.";
    portfolioText[8] = "<b>Lamplight Designs</b> is a Texas-based company producing handcrafted steel and brass decorative lighting. Many of its designs owe their inspiration to the 18th century craftsmen who developed a decorative painting method, known as ‘tole’. Drawing on Lamplight’s distinctive styling and vision, Mot Juste designed a range of mail, point-of-sale and internet marketing material.";
    portfolioText[9] = "<b>SmartestEnergy</b> is playing a leading role in bringing renewable energy into the mainstream. Through publications, media advertising and exhibition displays,<br />Mot Juste has helped the company to forge a strong presence in the UK’s<br />competitive renewable power market. <a href=\"http://www.smartestenergy.com/\" target=\"_blank\">smartestenergy.com</a>";
    portfolioText[10] = "<b>Microfolia</b> supplies and maintains decorative plants in many of London’s top office buildings. Mot Juste commissioned Robert Hall to create some stunning pictures<br />of Microfolia’s work. The result: a brochure that conveys the company’s<br />ambition and creative imagination.";
    portfolioText[11] = "Following a re-branding, Mot Juste produced a series of leaflets for <b>The Paul Hamlyn Foundation</b>. This leaflet explained its new strategic grant making policies the Foundation’s high-level stakeholders.";
    portfolioText[12] = "<b>Loxford School of Science and Technology</b> was looking for an innovative presentation of its Sixth Form prospective. An interactive CD proved to be more effective among its IT-savvy audience. And it costs less too!";
	portfolioText[13] = "Many of Ghana's young women miss out on education because they are forced to work from when they are little and then marry and have children at a young age. Their daughters often then carry on this depressing cycle. '<b>College for Ama</b>' is seeking to break this cycle and enable Ghanaian women to fulfil their potential by changing attitudes and offering chances to gifted and talented young women. Mot Juste provides its services free, helping the foundation to publicise its work and raise funds from its many friends around the world.";
	
    // Count total
    for (var totalImages=0; totalImages<portfolioImage.length; totalImages++) {}
    totalImages--;
    
    // Get current image (its in the class of the DIV)
    var current_image = $("#current_image").html();
        
   // Calculate which image will be shown next
    if (option == "next") {
        if (current_image != totalImages) {
            next_image = parseInt(current_image)+1;
            nextnext_image = parseInt(current_image)+2;
        } else {
            next_image = 1;
        }
    } else {
        if (current_image != 1) {
            next_image = parseInt(current_image)-1;
        } else {
            next_image = parseInt(totalImages);
        }
    }
    
    $.preloadImages("images/portfolio/"+portfolioImage[nextnext_image]);
    
    // FX!
    $("#slideshow").fadeOut('normal',function(){
        $("#slideshow").html("<img src='./images/portfolio/"+portfolioImage[next_image]+"' width='500' /><p class=\"portfoliotxt\">"+portfolioText[next_image]+"</p>");
        $("#slideshow").fadeIn('slow');
        $("#current_image").html(next_image);
    });
}