var FIVENAPKIN = FIVENAPKIN || {}

FIVENAPKIN = {
	'common' : {
		// GLOBAL
		init : function(){
			// GLOBAL INIT
			function Navigation () {
				var navlist = $('body > nav > ul');

				navlist.find('li > ul').css({
					'display': 'none',
					'visibility': 'visible'
				});

				navlist.children().hover(function() {
					$(this).children('ul').stop(true, true).slideDown(200);
				}, function() {
					$(this).children('ul').stop(true, true).fadeOut(400);
				});
			}
			
			Navigation();
			
		},
		finalize : function(){
			// GLOBAL FINALIZE
			
			// Email Signup
			$('.newsletter a, a.email-signup').fancybox({
				'centerOnScroll' : true,
				'height' : 590,
				'overlayColor' : '#fff',
				'overlayOpacity' : 0.9,
				'scrolling' : 'no',
				'titleShow' : false,
				'type' : 'iframe',
				'width' : 480,
				'onComplete': function () {
					$('#fancybox-content').addClass('signup-form');
				}
			})
			
			// Anchor Scrolling
			// function Scroller(link, speed) {
			// 	if (!speed) var speed = 500;
			// 
			// 	$(link).click(function() {
			// 		this.blur();
			// 		this.hideFocus = true;
			// 		this.style.outline = 'none';
			// 
			// 		var elementClicked = $(this).attr("href");
			// 		var destination = $(elementClicked).offset().top;
			// 		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-30}, speed );
			// 		return false;
			// 	});
			// }
			
			$('a[href^=#]').not('a[href=#], #meet-the-burgers a, #menus nav a, .gallery-navigation a').smoothmove();
			
			// Scroller(scrolls, 300).;
			
			// Open Google Maps in Fancybox Overlay
			$('a[href^=http://maps.]').fancybox({
				'autoScale'     : true,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'speedIn'		: 800, 
				'speedOut'		: 200, 
				'overlayColor'  : '#fff',
				'overlayOpacity': 0.75,
				'overlayShow'	: true,
				'titlePosition' : 'over',
				'type'          : 'iframe',
				'height'        : 530,
				'width'         : 800
			});
			
			
			
			// Livebookings
			// Set defaults for all instances
			$.lbuiDirect.setDefaults({
				connectionid: 'US-RES-NAPKINBURGERGROUP:27420',
				language: 'en-US',
				modalWindow: {
					enabled: true
				}
			});
			// Attach to all links with Livebookings codes in the rel attribute
			$('.reservations-item a').not('[rel="external"]').lbuiDirect();
			
			
			// $('.reservations-item a[rel=124611]').fancybox({
			// 	'autoScale'     : true,
			// 	'transitionIn'	: 'fade',
			// 	'transitionOut'	: 'fade',
			// 	'speedIn'		: 800, 
			// 	'speedOut'		: 200, 
			// 	'overlayColor'  : '#fff',
			// 	'overlayOpacity': 0.75,
			// 	'overlayShow'	: true,
			// 	'titlePosition' : 'over',
			// 	'type'          : 'ajax',
			// 	'height'        : 530,
			// 	'width'         : 800,
			// 	'href': 'http://5napkinburger.com/wp-mainsite/wp-content/themes/5nbsite-dev/reservations-uws.html'
			// });
			
			
		}
	},
	'page' : {
		// PAGES
		init : function(){
			
		},
		home : function(){
			Slideshow('#feature');
			Tabs('#burger-navigation li a', '#burger-content li');
			simpleTabs('#photo-gallery', true);
		},
		reservations : function() {

			// $('input#submit').hide();
			// $('#OT_submitWrap').html('<button type="submit" id="submit" class="OT_TableButton">Find a Table</button>');
		}
	},
	'category' : {
		// CATEGORIES
		init : function(){
			
		},
		press : function(){
			// Press Page
			Carousel('#recent-press');
		}
	},
	'parent-pageid-73' : {
		// INDIVIDUAL LOCATIONS
		init : function() {
			simpleTabs('#menus');
			$('#gallery a').fancyFlickr('http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&photoset_id=72157626302812427&extras=url_o&api_key=0b69691367737c93ad32feb35364fad8&user_id=61375994@N07&format=json&jsoncallback=?');			
		}
	}
}

UTIL = {

	fire : function(func,funcname, args){

		var namespace = FIVENAPKIN;

		funcname = (funcname === undefined) ? 'init' : funcname;
		if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function'){
			namespace[func][funcname](args);
		}

	},

	loadEvents : function(){

		var bodyId = document.body.id;

		// hit up common first.
		UTIL.fire('common');

		// do all the classes too.
		$.each(document.body.className.split(/\s+/),function(i,classnm){
			UTIL.fire(classnm);
			UTIL.fire(classnm,bodyId);
		});

		UTIL.fire('common','finalize');

	} 

};

$(document).ready(UTIL.loadEvents);
