
var eventData = [

        {
                name: "Skydive for Save the Children",
                intro: "Feeling brave? Why not take part in the ultimate challenge and skydive for Save the Children.",
                location: "",
                date: '2010-11-23',
                link: '/en/48_10461.htm'
        },{
                name: "Gold Challenge",
                intro: "Choose your sports, set your goals and create your challenge",
                location: "",
                date: '2010-11-24',
                link: '/en/48_13326.htm'
        },{
                name: "Rick Stein’s Seafood Restaurant, Padstow. Save the Children Charity Lunches. ",
                intro: "Enjoy a very special 3 course lunch for just &pound;18 + a &pound;2-50 cover charge direct to Save the Children.",
                location: "",
                date: '2011-01-24',
                link: '/en/48_13675.htm'
        },{
                name: "The Brighton Marathon",
                intro: "The race route takes in the best of the city centre and fabulous stretches of coastal road, including panoramic views of where the glorious South Downs meets the English Channel.",
                location: "Brighton",
                date: '2011-04-10',
                link: '/en/48_9087.htm'
        },{
                name: "Kilomathon Scotland",
                intro: "The perfect race distance — 16.3 miles",
                location: "Royal Highland Centre, Ingliston, Newbridge, Midlothian, EH28 8NB",
                date: '2011-04-17',
                link: '/en/48_10287.htm'
        },{
                name: "Born to parkrun",
                intro: "Whatever your level, wherever you live, dust off your trainers and run a 5K parkrun for Save the Children",
                location: "50 locations across the UK",
                date: '2011-04-30',
                link: '/en/48_15206.htm'
        },{
                name: "Wessex Walks",
                intro: "We have a walk for everyone, from a two mile family stroll to 20-mile treks for the more adventurous. Every walk is open to groups or individuals of all ages ",
                location: "Salisbury, UK",
                date: '2011-05-15',
                link: '/en/48_wessexwalks.htm'
        },{
                name: "The Edinburgh Marathon Festival",
                intro: "It's official — Edinburgh is the Fastest Marathon in the UK!",
                location: "Edinburgh, Scotland",
                date: '2011-05-21',
                link: '/en/48_10117.htm'
        },{
                name: "Charity Fashion Show and Gig",
                intro: "Singer and model Edyta Grace has organised a spectacular night out with a live band and a fashion show as a great fundraiser for our work.",
                location: "",
                date: '2011-05-23',
                link: '/en/48_15470.htm'
        },{
                name: "Trek the Great Wall of China June 2011",
                intro: "Trek along the Great Wall of China, experience Chinese culture and explore Tiananmen Square",
                location: "",
                date: '2011-06-04',
                link: '/en/48_13246.htm'
        },{
                name: "Nightrider",
                intro: "A fantastic cycle challenge taking in all the key sights of London by night.",
                location: "London",
                date: '2011-06-11',
                link: '/en/48_9668.htm'
        },{
                name: "British Gas Great Swims",
                intro: "No walls, no lanes, no chlorine, just the great outdoors… in this series of televised one-mile swims in spectacular surroundings.",
                location: "",
                date: '2011-06-11',
                link: '/en/48_10407.htm'
        },{
                name: "Cycle London to Paris June 2011",
                intro: "This long-weekend challenge links two great European cities, London to Paris, covering around 300km in just three days.",
                location: "London, UK",
                date: '2011-06-24',
                link: '/en/48_13233.htm'
        },{
                name: "Summer in the City",
                intro: "Guests can enjoy an evening of fine dining and fabulous entertainment in the beautiful surroundings of Mansion House.",
                location: "event-sitc",
                date: '2011-06-27',
                link: '/en/48_12651.htm'
        },{
                name: "British 10K London",
                intro: "Join Team Save the Children in this scenic London run.",
                location: "London, UK",
                date: '2011-07-10',
                link: '/en/48_13329.htm'
        },{
                name: "The Virgin Active London Triathlon ",
                intro: "Run, bike and swim in the world’s largest triathlon ",
                location: "London",
                date: '2011-07-30',
                link: '/en/48_10408.htm'
        },{
                name: "Can you conquer First Monster?",
                intro: "Sign up for the ultimate physical challenge today - and raise vital funds for our work",
                location: "Loch Ness, Inverness, Scotland",
                date: '2011-09-03',
                link: '/en/48_10477.htm'
        },{
                name: "Cycle London to Paris September 2011",
                intro: "This long weekend challenge links two great European cities, London and Paris, covering around 300km in just 3 days.",
                location: "London, UK",
                date: '2011-09-09',
                link: '/en/48_12205.htm'
        },{
                name: "Great North Run",
                intro: "Join 54,000 runners in this iconic race in the North-East",
                location: "Newcastle-upon-Tyne, UK",
                date: '2011-09-18',
                link: '/en/48_13327.htm'
        },{
                name: "Real Berlin Marathon",
                intro: "This route takes you on a big sightseeing loop through one of the most exciting cities in the world.",
                location: "Berlin, Germany",
                date: '2011-09-25',
                link: '/en/48_10747.htm'
        },{
                name: "Run to the Beat Half Marathon",
                intro: "Be inspired and spurred on by specially chosen live bands and DJs at this unique half marathon.",
                location: "The O2, London, UK",
                date: '2011-09-25',
                link: '/en/48_10754.htm'
        },{
                name: "Baxter’s Loch Ness Marathon and Festival of Running",
                intro: "Recognised as one of the UK’s leading marathons.",
                location: "Loch Ness, Scotland",
                date: '2011-10-02',
                link: '/en/48_10118.htm'
        },{
                name: "Trek the Great Wall of China October 2011",
                intro: "Trek along the Great Wall of China, experience Chinese culture and explore Tiananmen Square",
                location: "China",
                date: '2011-10-08',
                link: '/en/48_5667.htm'
        },{
                name: "Royal Parks Half Marathon",
                intro: "Get in touch now to secure your place in this brilliant race!",
                location: "Kensington Gardens, London, UK",
                date: '2011-10-09',
                link: '/en/48_10753.htm'
        },{
                name: "The Cardiff Half Marathon ",
                intro: "More than 11,000 runners are expected to turn out in the Welsh capital for this tour of its most famous sights. ",
                location: "Cardiff, Wales",
                date: '2011-10-16',
                link: '/en/48_10062.htm'
        },{
                name: "The Asian Awards",
                intro: "An exclusive event to reward outstanding achievement from within the worldwide Asian community, held at the Grosvenor House Hotel, London in aid of Save the Children.",
                location: "",
                date: '2011-10-18',
                link: '/en/48_15113.htm'
        },{
                name: "Venice Marathon",
                intro: "Join the 26th Venice Marathon and run through beautiful countryside as well as St. Mark’s Square and Palazzo Ducale, renowned Venice landmarks.",
                location: "Venice, Italy",
                date: '2011-10-23',
                link: '/en/48_10806.htm'
        },{
                name: "ING New York City Marathon",
                intro: "The premier event of New York Road Runners, the ING New York City Marathon is one of the world's great road races, drawing more than 100,000 applicants annually.",
                location: "New York City, USA",
                date: '2011-11-06',
                link: '/en/48_10749.htm'
        },{
                name: "Athens Classic Marathon",
                intro: "Run the original historical course — more than 2,500 years old",
                location: "Athens, Greece",
                date: '2011-11-13',
                link: '/en/48_10807.htm'
        },{
                name: "Trek the Inca Trail May 2012",
                intro: "Enjoy sunrise at Machu Picchu and explore ancient Andean culture whilst having the trip of a lifetime!",
                location: "Peru",
                date: '2012-05-10',
                link: '/en/48_13314.htm'
        },{
                name: "Climb Kilimanjaro September 2012",
                intro: "Take part in the ultimate challenge by climbing the highest mountain in Africa",
                location: "",
                date: '2012-09-10',
                link: '/en/48_13313.htm'
        },

        {}
];

//-----------------------------------------------------------------------------
// [290] - event calendar - 10378 - 10378
// Display event calendar
//-----------------------------------------------------------------------------
var today = toISODate(new Date());

var eventsDates = [];

eventData.pop();

for (e in eventData)
{
    eventsDates.push(eventData[e].date);
}

filter(eventsDates, beforeToday);

eventsDates.sort();


//-------------------------------------------------------------------------
// Determine if given date (ISO short format e.g. 2010-01-29) is in the
// past.
//-------------------------------------------------------------------------
function beforeToday(d) {
    return d < today;
}

$(function() {
//    $('.hide-by-js').hide();

    if (eventsDates.length == 0)
    {
        return;
    }

    $('#eventcalendar').datepicker({
        minDate: fromISODate(eventsDates[0]),
        maxDate: fromISODate(eventsDates[eventsDates.length - 1]),
    
        beforeShowDay: selectableDates,
        dateFormat: 'yy-mm-dd',

        onSelect: function(dateText, inst)  {
            // redirect to the appropriate month#day page
            var year   = dateText.substr(0, 4);
            var month  = dateText.substr(5, 2);
            var day    = dateText.substr(8, 2);

            var base = 'http://www.savethechildren.org.uk/events/';

            window.location = base + year + '/' + month + '/' + day;
        }
    });
});

//-------------------------------------------------------------------------
// Callback function for calendar to determine which dates can be selected.
//-------------------------------------------------------------------------
function selectableDates(theDate) {
    var iDate = toISODate(theDate);

    for (d in eventsDates) {
        if (eventsDates[d] == iDate) {
            return [ true ];
        }
    }

    return [ false ];
}

