﻿$(document).ready(function() {
    // navigation menu
    $("#navbar_new li").hoverIntent({
        sensitivity: 1,
        interval: 250,
        over: function() { $("ul", this).slideDown('slow') },
        timeout: 0,
        out: function() { $("ul", this).slideUp('slow') }
    });

    $('#gallery a').lightBox();

    $('#twitter_update_list').innerfade({ animationtype: 'fade', speed: 2000, timeout: 5000, type: 'random_start' });
    
    // populate the events list
    CreateEventsList();

});

// 
function CreateEventsList() {

    var eventsList = $('ul#EventsList');

    if (eventsList.length > 0) {
        var event;
        var eventArray = new Array();

        //event = new Event("Regimental Banquet", "26th Febuary 2011", null, null, null, null, null);
        //eventArray.push(event);

        //event = new Event("Ashton Town Hall", "Saturday 23th April", "Ashton, Oldham", null, null, null, "http://montagus.org.uk/forum/viewtopic.php?f=43&t=638");
        //eventArray.push(event);

        //event = new Event("Training and Social weekend", "Friday 22nd April - Monday 25th April", null, null, null, null, "http://montagus.org.uk/forum/viewtopic.php?f=43&t=639");
        //eventArray.push(event);

        //event = new Event("West Wickham Park", "27th May - 29th May", null, null, null, null, null);
        //eventArray.push(event);

        event = new Event("Chippenham", "25th June - 26th June", null, null, "http://www.facebook.com/event.php?eid=155034221234100", "http://english-civil-war-society.org.uk/www/cms/index.php?option=com_jcalpro&Itemid=180&extmode=view&extid=72", null);
        eventArray.push(event);

        event = new Event("Caldicott Castle, Langport", "2nd July - 3rd July", null, null, null, null, null);
        eventArray.push(event);

        event = new Event("Windermere Air Show, Cumbria", "23rd July - 24th July", null, null, null, null, null);
        eventArray.push(event);

        event = new Event("Alnwick Castle, Northumberland", "6th August - 7th August", null, null, null, null, "http://montagus.org.uk/forum/viewtopic.php?f=43&t=650");
        eventArray.push(event);

        event = new Event("St Fagans, Cardiff", "13th August - 14th August", null, null, null, null, null);
        eventArray.push(event);

        event = new Event("Lanark, Scotland", "20th August - 21st August", null, null, null, null, null);
        eventArray.push(event);

        event = new Event("Detling", "27th August - 29th August", null, null, null, null, null);
        eventArray.push(event);

        event = new Event("Hollingworth Carnival", "10th September", null, null, null, null, null);
        eventArray.push(event);

        event = new Event("Rainford, St Helens", "11th September", null, null, null, null, null);
        eventArray.push(event);

        for (i = 0; i < eventArray.length; i++) {
            $(eventsList).append(CreateEventHtml(eventArray[i]));
        }
    }
}

//
function CreateEventHtml(event) {
    
    var htmlStr = '';
    
    htmlStr += "<div class='eventBox'>";


    if (event != undefined && event != null) {

        if (event.Title != undefined && event.Title != null) {
            htmlStr += "<span class='eventTitle'>" + event.Title + "</span><br />";
        }

        if (event.EventDate != undefined && event.EventDate != null) {
            htmlStr += "<span class='eventDateHeading'>Date: </span>";
            htmlStr += "<span class='eventDate'> " + event.EventDate + "</span><br />";
        }

//        if (event.Location != undefined && event.Location != null) {
//            htmlStr += "<span class='eventDateHeading'>Location: </span>";
//            htmlStr += "<span class='eventLocation'>" + event.Location + "</span><br />";
//        }

        if (event.ForumUrl != undefined && event.ForumUrl != null) {
            htmlStr += "<span class='forumLink'><a href='" + event.ForumUrl + "'>Warning Order</a></span><br />";
        }

//        if (event.enableMoreInfo != undefined && event.enableMoreInfo != null && event.enableMoreInfo != false) {
//            htmlStr += "<span class='eventMoreInfo'>More Info...</span><br />";
//        }

        if (event.GoogleEvent != undefined && event.GoogleEvent != null) {
            htmlStr += "<a href='" + event.GoogleEvent + "'><img src='/i/calendar-date-icon.png' border='0'>Add to Google Calendar</a>";
        }

        if (event.FacebookEvent != undefined && event.FacebookEvent != null) {
            htmlStr += "<a href='" + event.FacebookEvent + "'><img src='/i/facebook.png' border='0'>Facebook Event</a>";
        }
        if (event.EcwsEvent != undefined && event.EcwsEvent != null) {
            htmlStr += "<a href='" + event.EcwsEvent + "'><img src='/i/ecws-official.jpg' border='0'>ECWS Official Website</a>";
        }
    }
    
    return htmlStr;
}


function Event(title, date, location, googleUrl, fbUrl, ecwsUrl, forumUrl) {
    this.Title = title;
    this.EventDate = date;
    this.Location = location;
    this.GoogleEvent = googleUrl;
    this.FacebookEvent = fbUrl;
    this.EcwsEvent = ecwsUrl;
    this.ForumUrl = forumUrl;
}
/*
Event.prototype.GetEventHtml = new function () {

    var resultHtml = new Array();
    var result;

    if(this.Title != undefined && this.Title != null) {
    
    }
    
    if(this.EventDate != undefined && this.EventDate != null) {
    
    }
    
    if(this.Location != undefined && this.Location != null) {
    
    }
    
    if(this.GoogleEvent != undefined && this.GoogleEvent != null) {
    
    }
    
    if(this.FacebookEvent != undefined && this.FacebookEvent != null) {
    
    }
    if(this.EcwsEvent != undefined && this.EcwsEvent != null) {
    
    }
}
*/
