// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(function() {
  $('.shop-link').fancybox({
    autoDimensions: false,
    width: 640,
    height: 'auto',
    overlayOpacity: 0.5,
    transitionIn: 'elastic',
    transitionOut: 'elastic'
  });
  $('.restaurant-link').fancybox({
    autoDimensions: false,
    width: 640,
    height: 600,
    overlayOpacity: 0.5,
    transitionIn: 'elastic',
    transitionOut: 'elastic'
  });

  if (window.location.hash) {
    $(window.location.hash + "_trigger").trigger('click');
  }
  $(window).hashchange( function(){
    $(window.location.hash + "_trigger").trigger('click');
  });

  $('#shop-filters a').click(function() {
    var shop_tag = this.id.replace(/filter_by_/, '');
    // console.log($(this).contents());
    $('.shop-list li').each(function(index) {
      // console.log($(this).contents());
      var matched = false;
      $(this).find('.shop-tags li').each(function() {
        // console.log("looking for: " + shop_tag + "; current: " + this.innerHTML);
        if (shop_tag == $.trim(this.innerHTML)) {
          matched = true;
          return;
        }
      });
      if (shop_tag == 'all') {
        $(this).fadeIn('slow');
        return;
      }
      if (matched == true) {
        $(this).fadeIn('slow');
      } else {
        $(this).fadeOut('slow');
      }
    });
  });
  $('#shop-filters').show();
});

$(window).load(function() {
  $('div[href*=.flv]').each(function() {
    // Don't embed a player if one has already been attached. Accordion and
    // fancybox code may have already put one here, and its settings should
    // remain unmolested.
    if (! $(this).flowplayer(0)) {
      var autoplay = $(this).attr('autoplay') === 'true' ? true : false;

      // Empty the video container before embedding flowplayer; otherwise,
      // flowplayer has to be embedded a second time before it works.
      $(this).empty();

      $(this).flowplayer('/flowplayer/flowplayer-3.2.7.swf', {
        clip: {
          autoPlay: autoplay,
          autoBuffering: true
        }
      });
    }
  });
});

