// facebook recommend
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

// pop up flyer
$(function() {
	$('.flyer a').lightBox();
	$('.image a').lightBox();
});

// picture flyer slider
$(document).ready(function(){	
	$("#flyer").easySlider({
		auto: false,
		continuous: false,
		numeric: true,
		speed: 100
	});
})

// picture url addressing
$(function () {
		$('ul').accordion();
		$('ul li:has(ul, div) > a').click(function(event, silent) {
				if (silent === undefined) {
						$.address.value('/');
						$('ul li[class*=active]:has(ul, div) > a').each(function() {
								$.address.parameter('a', $(this).attr('href').replace(/^#/, ''), true);
						});
						$.address.update();
						return false;
				}
		});
});
$.address.autoUpdate(false).change(function(event) {
		var params = event.parameters['a'];
		$('ul li:has(ul, div) > a').each(function() {
				var active = $(this).parent('li').attr('class').indexOf('active') != -1;
				if ($.inArray(
								$(this).attr('href').replace(/^#/, ''), 
								[].concat(params ? params : [])) != -1) {
						if (!active) $(this).trigger('click', [true]);
				} else if (active) {
						$(this).trigger('click', [true]);
				}
		});
});
