// Rotating background images
jQuery(function ($) {
    $.supersized({
        //Functionality
        slideshow: 1,
        //Slideshow on/off
        autoplay: 1,
        //Slideshow starts playing automatically
        start_slide: 1,
        //Start slide (0 is random)
        random: 0,
        //Randomize slide order (Ignores start slide)
        slide_interval: 20000,
        //Length between transitions
        transition: 1,
        //0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
        transition_speed: 2500,
        //Speed of transition
        new_window: 1,
        //Image links open in new window/tab
        pause_hover: 0,
        //Pause slideshow on hover
        keyboard_nav: 0,
        //Keyboard navigation on/off
        performance: 1,
        //0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
        image_protect: 1,
        //Disables image dragging and right click with Javascript
        image_path: '../img/bg/',
        //Default image path
        //Size & Position
        min_width: 0,
        //Min width allowed (in pixels)
        min_height: 0,
        //Min height allowed (in pixels)
        vertical_center: 1,
        //Vertically center background
        horizontal_center: 1,
        //Horizontally center background
        fit_portrait: 1,
        //Portrait images will not exceed browser height
        fit_landscape: 0,
        //Landscape images will not exceed browser width
        //Components
        navigation: 0,
        //Slideshow controls on/off
        thumbnail_navigation: 0,
        //Thumbnail navigation
        slide_counter: 0,
        //Display slide numbers
        slide_captions: 0,
        //Slide caption (Pull from "title" in slides array)
        slides: [ //Slideshow Images
        {
            image: 'uploads/default/files/background1.jpg'
        }, {
            image: 'uploads/default/files/background2.jpg'
        }, {
            image: 'uploads/default/files/background3.jpg'
        }

        ]

    });
});
// End rotating background images
$(function () {
    // If refreshing the page, unset the window hash
    window.location.hash = "";

    // AJAX content grabbing and menu behaviors, 
    // we start by delegating a click event
    $("nav").delegate("a", "click", function (e) {

        // prevent default anchor behavior
        e.preventDefault();

        // cache target href
        var target = $(this).attr("href");

        // target url parts
        var parts = target.split('/'),
            newHash = parts[parts.length - 1];

        // test for target
        if (newHash !== window.location.hash.substring(1)) {

            // modify window hash
            window.location.hash = newHash;

            // Paginate the menu items so the container maintains its shape
            $('#restaurant-menu').pajinate({
                items_per_page: 8,
                item_container_id: '#dinner',
                nav_panel_id: '#menu-controls',
                nav_label_first: '<<',
                nav_label_last: '>>',
                nav_label_prev: ' ',
                nav_label_next: ' '
            });

            // animate out
            $('#content').fadeOut(200, function () {
                $('#mainContent').animate({
                    width: '0',
                    paddingLeft: '0',
                    paddingRight: '0',
                }, {
                    duration: 800,
                    easing: 'linear'
                });

                // load content and animate in       
                $('#content').hide().load(target + " .content2", function () {
                    $('#mainContent').animate({
                        width: '810px',
                        paddingLeft: '65px',
                        paddingRight: '25px'
                    }, {
                        duration: 800,
                        easing: 'linear'
                    });
                    $('#content').delay(1500).fadeIn(200, function () {
						
						Carousel.methods.init();
						
                        // Restaurant Menu Stuff
                        var restaurantMenu = {};

                        $('#restaurant-menu div.menu-item').each(function(index){
                            var menuName = $(this).attr('class').split(' ')[1];
                            restaurantMenu[menuName] = [];
                        });
                        
						$('#restaurant-menu div.menu-item').each(function(index){
							var menuName = $(this).attr('class').split(' ')[1],
								menuItem = {};
							
							menuItem.title = $(this).find('.title').html(),
							menuItem.content = $(this).clone();
								
							restaurantMenu[menuName].push(menuItem);
						});
						
						window.restaurantMenu = restaurantMenu;
						
						$('#dinner div:even').css('background', 'rgba(0,0,0,.03)');
						$('#dinner').jScrollPane({showArrows: true});
                                    
                    });

                });
            });
        }
    });

    $('div#menu-list ul li').live('click', function () {
        var item_id = $(this).attr('class');
        this.description = $('#' + item_id).html();
        $('#item-description').html(this.description).fadeIn();
    });

    $('ul.menu-links li a').live('click', function (e) {
        e.preventDefault();

        var href = $(this).attr('href');
        href = href.substring(1);
        href = 'ul.' + href;

        $('div#menu-list').scrollTo(href, 500, {
            margin: true
        });
    });

    $('.scrollUp').live('click', function (e) {
        e.preventDefault();

        $('div#menu-list').scrollTo('-=150px', 500);
    });

    $('.scrollDown').live('click', function (e) {
        e.preventDefault();

        $('div#menu-list').scrollTo('+=150px', 500);
    });


	$('#categories li a').live('click', function(){

		//filter results based on query  
		function filter(selector, query) {  
  			query =   $.trim(query); //trim white space  
  			query = query.replace(/ /gi, '|'); //add OR for regex query  
  
  			$(selector).each(function() {  
    			($(this).attr('class').search(new RegExp(query, "i")) < 0) ? $(this).hide().removeClass('visible') : $(this).show().addClass('visible');  
  			});  
		}  
		
		var selector = $('div.menu-item'),
			query = $(this).text();
	
		$('h2').text(query);		
		filter(selector, query);
		
		$('#dinner').jScrollPane({showArrows: true});	

	});


	$('a.down').live('click', function(e){
		e.preventDefault();
		$('#dinner').scrollTo('+=420px', 800);
	});
	
	$('a.up').live('click', function(e){
		e.preventDefault();
		$('#dinner').scrollTo('-=420px', 800);
	});

});


$(function () {
    $(".carousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });
});

