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/expectra.jpg"); 
});

function changeImage(option) {
    // Load which images shall be in the slideshow
    var portfolioImage = new Array();
    portfolioImage[1] = "workpocket.jpg";
    portfolioImage[2] = "expectra.jpg";
    portfolioImage[3] = "diana_trust.jpg";
    portfolioImage[4] = "croydon.jpg";
    portfolioImage[5] = "lambeth_lone_parent.jpg";
    portfolioImage[6] = "orbital.jpg";
    portfolioImage[7] = "kimpton.jpg";
    portfolioImage[8] = "emailvision.jpg";
    portfolioImage[9] = "lamplight.jpg";
    portfolioImage[10] = "world_gold_council.jpg";
    portfolioImage[11] = "microfolia.jpg";
    portfolioImage[12] = "paul_hamlyn.jpg";
    portfolioImage[13] = "loxford.jpg";
	portfolioImage[14] = "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 produce for <strong>Randstad</strong>, one of Europe’s leading staffing agencies. Writing is shared between HR specialist writers and our in-house editors. Now in its tenth 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] = "GuideRH is the annual guide to French employment issues that Mot Juste produces for <strong>Expectra</strong>, a French recruitment consultancy and part of the Randstad group. Now in its second edition, Mot Juste in-house writers work with French employment experts to produce this comprehensive guide aimed at HR professionals and senior managers in SMEs.";
    portfolioText[3] = "<strong>The Diana, Prices of Wales Memorial Fund</strong> co-ordinated the campaign to ban cluster bombs. Mot Juste was commissioned to design the leaflet for its ‘Lethal litter, the work continues’ campaign.";
	portfolioText[4] = "Regenerating town centres and helping local businesses prosper in a tough economic climate has been high on the government’s agenda. Mot Juste researched and produced a series of ‘Discover’ leaflets and a loyalty card scheme for seven of <strong>Croydon’s</strong> town centres. At the end of the project, Mot Juste produced an operating manual to ensure continuity of the work. Similar projects were executed for the London boroughs of Lambeth and Bromley.";
	portfolioText[5] = "Getting single parents back into work in a deprive 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 <strong>Lambeth Lone Parent into Work Partnership</strong> was launched to point lone parents in the right direction. Mot Juste devised all literature to promote the initiative and the council met it’s target.";
	portfolioText[6] = "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[7] = "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[8] = "In locations as diverse as Shanghai, Sao Paulo, New York, Paris and Amsterdam, <b>Emailvision</b> staff work hard to help its customers get the most out of their email campaigns. To ensure a consistent approach to doing business, the company asked Mot Juste to design its corporate policy and procedures handbook.";
    portfolioText[9] = "<b>Lamplight Designs</b> is a Texas-based manufacturer of 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 print and online catalogue.";
    portfolioText[10] = "<b>The World Gold Council</b> is the market development company of the gold industry. With offices across the globe, the company needed to communicate its corporate policies to its staff. Mot Juste produced an attractive, professional looking manual.";
    portfolioText[11] = "<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[12] = "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 to the Foundation’s high-level stakeholders.";
    portfolioText[13] = "<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[14] = "Many of Ghana’s young women are deprived of education to help their families survive; they often do physically demanding work, marry young and have children at a young age. Their daughters then carry on this depressing cycle of poverty. <b>‘College for Ama’</b> attempts to break this cycle by changing attitudes and offering chances to gifted and talented young women. Mot Juste works pro bono to spread the message and raise funds among the foundation’s 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);
    });
}
