/**
 * Random Case Studies
 * --------------------
 * Company: SearchPath
 * Author: Shane Simpkins 
 * Email: shane.simpkins@searchpath.co.uk
 * URL: http://www.searchpath.co.uk/WebDevelopment/
 *  
**/

// - Do not edit this line
var caseStudies = new Array();

//
// Case Studies
// - Edit the case studies below
// - Do not edit the code below the case studies!
//

// Steppes Travel
caseStudies[caseStudies.length] = {
    Caption: "Steppes Travel",
    URL : "http://www.searchpath.co.uk/CaseStudies/default.html#SteppesTravel",
    AltText : "Searchpath Created the Steppes Travel Website",
    Thumbnail : "http://www.searchpath.co.uk/images/gallery/steppes/main.jpg"
};

// Perry Bishop
caseStudies[caseStudies.length] = {
    Caption: "Perry Bishop",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#PerryBishop",
    AltText : "Searchpath Created the Perry Bishop Website",
    Thumbnail : "http://www.searchpath.co.uk/images/gallery/perry-bishop/main.jpg"
};

// Quick Move Now
caseStudies[caseStudies.length] = {
    Caption: "Quick Move Now",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#QuickMoveNow",
    AltText: "Searchpath Created the Quickmove Now Website",
    Thumbnail: "http://www.searchpath.co.uk/images/gallery/quickmovenow/main.jpg"
};

// Rugbytots
caseStudies[caseStudies.length] = {
    Caption: "Rugbytots",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#Rugbytots",
    AltText: "Searchpath Created the Rugbytots Website",
    Thumbnail: "http://www.searchpath.co.uk/images/gallery/rugbytots/main.jpg"
};

// DrSearch
caseStudies[caseStudies.length] = {
    Caption: "DrSearch",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#DrSearch",
    AltText: "Searchpath Created the DrSearch Website",
    Thumbnail: "http://www.searchpath.co.uk/images/gallery/drsearch/main.jpg"
};

// Indigo Assessment
caseStudies[caseStudies.length] = {
    Caption: "Indigo Assessment",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#IndigoAssessment",
    AltText: "Searchpath Created the Indigo Assessment Website",
    Thumbnail: "http://www.searchpath.co.uk/images/gallery/indigo/main.jpg"
};

// Traverseline
caseStudies[caseStudies.length] = {
    Caption: "Traverseline",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#Traverseline",
    AltText: "Searchpath Created the Traverseline Website",
    Thumbnail: "http://www.searchpath.co.uk/images/gallery/traverseline/main.jpg"
};

// JSNA
caseStudies[caseStudies.length] = {
    Caption: "JSNA",
    URL: "http://www.searchpath.co.uk/CaseStudies/default.html#JSNA",
    AltText: "Searchpath makes frequent updates to the JSNA Website",
    Thumbnail: "http://www.searchpath.co.uk/images/gallery/jsna/main.jpg"
};

/*******************************************************************************
 ***  DO NOT EDIT BELOW THIS LINE                                            ***
 *******************************************************************************/ 
 
 // This method is resposible for randomly selecting 
 // case studies to be displayed on the page.
 function RandomizeCaseStudies()
 {
    var resA = -1;
    var resB = -1;
    var now = new Date();
    var seed = now.getSeconds();
    
    // Generate random indices for getting the case studies
    if (caseStudies && caseStudies.length > 0)
    {
        resA = Math.ceil(Math.random(seed) * caseStudies.length - 1);
        
        // Only try to get a second one if there are more than one case studies
        if (caseStudies.length > 1)
        {
            do {
                resB = Math.ceil(Math.random(seed) * caseStudies.length - 1);
            }
            while (resA == resB); // Ensure that we don't have the same case study twice!
        }
    }
    
    // Ensure that the left box is populated before the right one
    if (resA == -1 && resB > -1)
    {
        resA = resB;
        resB = -1;
    }
    
    // Output case study to left box
    if (resA > -1 && resA < caseStudies.length)
    {
        OutputCaseStudy(".contentboxleft", resA);
    }
    else
    {
        OutputCaseStudy(".contentboxleft", -1);
    }
    
    // Output case study to right box
    if (resB > -1 && resB < caseStudies.length)
    {
        OutputCaseStudy(".contentboxright", resB);
    }
    else
    {
        OutputCaseStudy(".contentboxright", -1);
    }
 }
 
 // This method is resposible for outputting the casestudy 
 // html to the specified element using a jquery selector.
 function OutputCaseStudy(selector, index)
 {
    // Attempt to select the element
    var elem = jQuery(selector);
    
    // If the elem could be grabbed then output the case study html
    if (elem)
    {
      if (index > -1)
      {
          elem.html('<a class="iframeLink" href="' + caseStudies[index].URL + '"><img src="' + caseStudies[index].Thumbnail + '" alt="' + caseStudies[index].AltText + '" style="margin-top: 5px; float: left; border: 1px solid rgb(204, 204, 204);" width="200" border="0" height="135"><br /><div style="text-align: center; clear: both; padding-top: 6px;">' + caseStudies[index].Caption + '</div></a>');
      }
      else
      {
        // Clear Out The Element
        elem.html('&nbsp;');
      }
    }
 }
 
 // Populate the case studies when the page is fully ready
 jQuery(document).ready(function() {
    RandomizeCaseStudies();
 });
 
