﻿
$(function () {

    // Isotope project filtering
    // http://isotope.metafizzy.co/docs/introduction.html
    var current = $('.filter a');
    $('.filter a').click(function () {
        current.removeClass("selected");
        $(this).addClass("selected");
       
        current = $(this);
        var selector = $(this).attr('data-filter');
        $('.all-events').isotope({ filter: selector });
        return false;
    });


    $('.all-events').isotope({
        animationEngine: 'jquery',
        itemSelector: '.events',
        layoutMode: 'straightDown',
        animationOptions: {
            duration: 800,
            easing: 'linear',
            queue: false
        }
    });


    //Pagging of YouTube videos
    $("#videos").quickPager();
    // This function is used to get the dropdown menu to work in IE 6!
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $('li').has('ul').mouseover(function () {
            $(this).children('ul').show();
        }).mouseout(function () {
            $(this).children('ul').hide();
        })
    }
    //Home page tabbing
    $('#hero-content .content').hide();
    $('#hero-content div:first').show();
    $('#hero-content ul li:first').addClass('active');
    $('#hero-content ul li a').click(function () {
        $('#hero-content ul li').removeClass('active');
        $(this).parent().addClass('active');
        var currentTab = $(this).attr('href');
        $('#hero-content .content').hide();
        $(currentTab).show();
        return false;
    });

});

$(function () {

    var $container = $('#location-event-list'),
    // object that will keep track of options
          isotopeOptions = {},
    // defaults, used if not explicitly set in hash
          defaultOptions = {
              filter: '*',
              sortBy: 'original-order',
              sortAscending: true,
              layoutMode: 'masonry'
          };



    var setupOptions = $.extend({}, defaultOptions, {
        itemSelector: '.events-loc',

        getSortData: {
            date: function ($elem) {
                return $elem.attr('data-date');
            },
            type: function ($elem) {
                return $elem.attr('data-category');
            },
            name: function ($elem) {
                return $elem.find('.name').text();
            }
        }
    });

    // set up Isotope
    $container.isotope(setupOptions);

    //reset
    $('a.show-all').click(function () {
        $('.location-options').find('.selected').removeClass('selected');
      
    });

    var $optionSets = $('#options').find('.location-options'),
          isOptionLinkClicked = false;

    // switches selected class on buttons
    function changeSelectedLink($elem) {

        // remove selected class on previous item
        $elem.parents('.location-options').find('.selected').removeClass('selected');
        // set selected class on new item
        $elem.addClass('selected');
    }

    $optionSets.find('a').click(function () {
        var $this = $(this);
        // don't proceed if already selected
        if ($this.hasClass('selected')) {
            return;
        }


        changeSelectedLink($this);
        // get href attr, remove leading #
        var href = $this.attr('href').replace(/^#/, '')
        // convert href into object
        // i.e. 'filter=.inner-transition' -> { filter: '.inner-transition' }
        option = $.deparam(href, true);
        // apply new option to previous
        $.extend(isotopeOptions, option);
        // set hash, triggers hashchange on window
        $.bbq.pushState(isotopeOptions);
        isOptionLinkClicked = true;
        return false;
    });

    var hashChanged = false;

    $(window).bind('hashchange', function (event) {
        // get options object from hash
        var hashOptions = window.location.hash ? $.deparam.fragment(window.location.hash, true) : {},
        // do not animate first call
            aniEngine = hashChanged ? 'best-available' : 'none',
        // apply defaults where no option was specified
            options = $.extend({}, defaultOptions, hashOptions, { animationEngine: aniEngine });
        // apply options from hash
        $container.isotope(options);
        // save options
        isotopeOptions = hashOptions;

        // if option link was not clicked
        // then we'll need to update selected links
        if (!isOptionLinkClicked) {
            // iterate over options
            var hrefObj, hrefValue, $selectedLink;
            for (var key in options) {
                hrefObj = {};
                hrefObj[key] = options[key];
                // convert object into parameter string
                // i.e. { filter: '.inner-transition' } -> 'filter=.inner-transition'
                hrefValue = $.param(hrefObj);
                // get matching link
                $selectedLink = $optionSets.find('a[href="#' + hrefValue + '"]');
                changeSelectedLink($selectedLink);
            }
        }

        isOptionLinkClicked = false;
        hashChanged = true;
    })
    // trigger hashchange to capture any hash data on init
        .trigger('hashchange');

});




function loadVideo(playerUrl, autoplay) {
    var params = {wmode:"transparent"};
    swfobject.embedSWF(
      playerUrl + '&rel=1&border=0&fs=1&autoplay=' +
      (autoplay ? 1 : 0), 'player', '641', '390', '9.0.0', false,
      false, { allowfullscreen: 'true' }, params);
}

function showMyVideos2(data) {
    var feed = data.feed;
    var entries = feed.entry || [];
    var html = ['<ul id="videos">'];
    for (var i = 0; i < entries.length; i++) {
        var entry = entries[i];
        var title = entry.title.$t;
        var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
        var playerUrl = entries[i].media$group.media$content[0].url;
        html.push('<li onclick="loadVideo(\'', playerUrl, '\', true)">',
              '<img src="', thumbnailUrl, '" width="95"/>', '<span>', title, '...</span></li>');
    }
    html.push('</ul><br style="clear: left;"/>');
    document.getElementById('videos2').innerHTML = html.join('');
    if (entries.length > 0) {
        loadVideo(entries[0].media$group.media$content[0].url, false);
    }
}





