// JavaScript Document// Autoreveal function. This is built from an accordion script. I just removed
// the "on" state and stopped it from closing others. Easy enough...
jQuery.fn.autoreveal = function(options) {
    // options
    var SLIDE_DOWN_SPEED = 'fast';
    var SLIDE_UP_SPEED = 'fast';
    var startClosed = options && options.start && options.start == 'closed';
    return this.each(function() {
		jQuery(this).find('ul').hide();
        jQuery(this).find('h3').click(function() {
            var current = jQuery(this.parentNode).find('ul:visible');
            var next = jQuery(this).find('+ul');
            if (next.is(':visible')) {
                next.slideUp(SLIDE_UP_SPEED);
            } else {
                next.slideDown(SLIDE_DOWN_SPEED);
            }
        });
        if (!startClosed) {
            jQuery(this).find('p:eq(' + + ')').slideDown(SLIDE_DOWN_SPEED);
        }
    });
};

$(function() {
	$("#menu_options h3").each(function(){
		$(this).click(function() {
			$(this).toggleClass("expanded");
		});
	});
});


$(function() {
	$("#menu_1").each(function(){
		$(this).click(function() {
			$('#subcat_1').toggle(); // show subcat_1 open 
			$('h3#cat_1').toggleClass("expanded"); // show h3#cat_1 arrow 
			return false;
		});
	});
});

$(function() {
	$("#menu_2").each(function(){
		$(this).click(function() {
			$('#subcat_2').toggle(); // show subcat_2 open 
			$('h3#cat_2').toggleClass("expanded"); // show h3#cat_1 arrow
			return false;
		});
	});
});

$(function() {
	$("#menu_3").each(function(){
		$(this).click(function() {
			$('#subcat_3').toggle(); // show subcat_3 open
			$('h3#cat_3').toggleClass("expanded"); // show h3#cat_3 arrow
			return false;
		});
	});
});

$(function() {
	$(".btn_sandwich_platter").each(function(){
		$(this).click(function() {
			$('#product_sandwich_platter').toggle();
			$('#product_catering').toggle();
			trackOmniPageView(
				[
					['pageName','Catering: Sandwich Platter'],
					['products',';Catering: Sandwich Platter'],
					['events','event7'],
					['prop14','Catering: Sandwich Platter'],
					['eVar16','Catering: Sandwich Platter']
				]
			);
			return false;
		});
	});
});

$(function() {
	$(".btn_giant_subs").each(function(){
		$(this).click(function() {
			$('#product_giant_subs').toggle();
			$('#product_catering').toggle();
			trackOmniPageView(
				[
					['pageName','Catering: Giant Subs'],
					['products',';Catering: Giant Subs'],
					['events','event7'],
					['prop14','Catering: Giant Subs'],
					['eVar16','Catering: Giant Subs']
				]
			);
			return false;
		});
	});
});

$(function() {
	$(".btn_cookie_platter").each(function(){
		$(this).click(function() {
			$('#product_cookie_platter').toggle();
			$('#product_catering').toggle();
			trackOmniPageView(
				[
					['pageName','Catering: Cookie Platter'],
					['products',';Catering: Cookie Platter'],
					['events','event7'],
					['prop14','Catering: Cookie Platter'],
					['eVar16','Catering: Cookie Platter']
				]
			);
			return false;
		});
	});
});

$(function() {
	$(".catering_index").each(function(){
		$(this).click(function() {
			return true;
		});
	});
});

$(function() {
	$(".sandwich_platter_previous").each(function(){
		$(this).click(function() {
			$('#product_sandwich_platter').hide();
			$('#product_giant_subs').hide();
			$('#product_cookie_platter').show();
			trackOmniPageView(
				[
					['pageName','Catering: Cookie Platter'],
					['products',';Catering: Cookie Platter'],
					['events','event7'],
					['prop14','Catering: Cookie Platter'],
					['eVar16','Catering: Cookie Platter']
				]
			);
			return false;
		});
	});
});
	$(function() {
		$(".sandwich_platter_next").each(function(){
			$(this).click(function() {
				$('#product_sandwich_platter').hide();
				$('#product_giant_subs').show();
				$('#product_cookie_platter').hide();
				trackOmniPageView(
					[
						['pageName','Catering: Giant Subs'],
						['products',';Catering: Giant Subs'],
						['events','event7'],
						['prop14','Catering: Giant Subs'],
						['eVar16','Catering: Giant Subs']
					]
				);
				return false;
			});
		});
	});


	$(function() {
		$(".giant_subs_previous").each(function(){
			$(this).click(function() {
				$('#product_sandwich_platter').show();
				$('#product_giant_subs').hide();
				$('#product_cookie_platter').hide();
				trackOmniPageView(
					[
						['pageName','Catering: Sandwich Platter'],
						['products',';Catering: Sandwich Platter'],
						['events','event7'],
						['prop14','Catering: Sandwich Platter'],
						['eVar16','Catering: Sandwich Platter']
					]
				);
				return false;
			});
		});
	});
		$(function() {
			$(".giant_subs_next").each(function(){
				$(this).click(function() {
					$('#product_sandwich_platter').hide();
					$('#product_giant_subs').hide();
					$('#product_cookie_platter').show();
					trackOmniPageView(
						[
							['pageName','Catering: Wrap Platter'],
							['products',';Catering: Wrap Platter'],
							['events','event7'],
							['prop14','Catering: Wrap Platter'],
							['eVar16','Catering: Wrap Platter']
						]
					);
					return false;
				});
			});
		});


		$(function() {
			$(".wrap_platter_previous").each(function(){
				$(this).click(function() {
					$('#product_sandwich_platter').hide();
					$('#product_giant_subs').show();
					$('#product_cookie_platter').hide();
					trackOmniPageView(
						[
							['pageName','Catering: Giant Subs'],
							['products',';Catering: Giant Subs'],
							['events','event7'],
							['prop14','Catering: Giant Subs'],
							['eVar16','Catering: Giant Subs']
						]
					);
					return false;
				});
			});
		});
			$(function() {
				$(".wrap_platter_next").each(function(){
					$(this).click(function() {
						$('#product_sandwich_platter').hide();
						$('#product_giant_subs').hide();
						$('#product_cookie_platter').show();
						trackOmniPageView(
							[
								['pageName','Catering: Cookie Platter'],
								['products',';Catering: Cookie Platter'],
								['events','event7'],
								['prop14','Catering: Cookie Platter'],
								['eVar16','Catering: Cookie Platter']
							]
						);
						return false;
					});
				});
			});
					
	$(function() {
		$(".cookie_platter_previous").each(function(){
			$(this).click(function() {
				$('#product_sandwich_platter').hide();
				$('#product_giant_subs').show();
				$('#product_cookie_platter').hide();
				trackOmniPageView(
					[
						['pageName','Catering: Wrap Platter'],
						['products',';Catering: Wrap Platter'],
						['events','event7'],
						['prop14','Catering: Wrap Platter'],
						['eVar16','Catering: Wrap Platter']
					]
				);
				return false;
			});
		});
	});
		$(function() {
			$(".cookie_platter_next").each(function(){
				$(this).click(function() {
					$('#product_sandwich_platter').show();
					$('#product_giant_subs').hide();
					$('#product_cookie_platter').hide();
					trackOmniPageView(
						[
							['pageName','Catering: Sandwich Platter'],
							['products',';Catering: Sandwich Platter'],
							['events','event7'],
							['prop14','Catering: Sandwich Platter'],
							['eVar16','Catering: Sandwich Platter']
						]
					);
					return false;
				});
			});
		});
		
		
//Script to control the fade timer of the catering headers
(function($) {

$.fn.innerfade = function(options) {

	this.each(function(){ 	
		
		var settings = {
			animationtype: 'fade',
			speed: 'normal',
			timeout: 2000,
			type: 'sequence',
			containerheight: 'auto',
			runningclass: 'innerfade'
		};
		
		if(options)
			$.extend(settings, options);
		
		var elements = $(this).children();
	
		if (elements.length > 1) {
		
			$(this).css('position', 'relative');
	
			$(this).css('height', settings.containerheight);
			$(this).addClass(settings.runningclass);
			
			for ( var i = 0; i < elements.length; i++ ) {
				$(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute');
				$(elements[i]).hide();
			};
		
			if ( settings.type == 'sequence' ) {
				setTimeout(function(){
					$.innerfade.next(elements, settings, 1, 0);
				}, settings.timeout);
				$(elements[0]).show();
			} else if ( settings.type == 'random' ) {
				setTimeout(function(){
					do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( current == 0 )
					$.innerfade.next(elements, settings, current, 0);
				}, settings.timeout);
				$(elements[0]).show();
			}	else {
				alert('type must either be \'sequence\' or \'random\'');
			}
			
		}
		
	});
};


$.innerfade = function() {}
$.innerfade.next = function (elements, settings, current, last) {

	if ( settings.animationtype == 'slide' ) {
		$(elements[last]).slideUp(settings.speed, $(elements[current]).slideDown(settings.speed));
	} else if ( settings.animationtype == 'fade' ) {
		$(elements[last]).fadeOut(settings.speed);
		$(elements[current]).fadeIn(settings.speed);
	} else {
		alert('animationtype must either be \'slide\' or \'fade\'');
	};
	
	if ( settings.type == 'sequence' ) {
		if ( ( current + 1 ) < elements.length ) {
			current = current + 1;
			last = current - 1;
		} else {
			current = 0;
			last = elements.length - 1;
		};
	}	else if ( settings.type == 'random' ) {
		last = current;
		while (	current == last ) {
			current = Math.floor ( Math.random ( ) * ( elements.length ) );
		};
	}	else {
		alert('type must either be \'sequence\' or \'random\'');
	};
	setTimeout((function(){$.innerfade.next(elements, settings, current, last);}), settings.timeout);
};
})(jQuery);





// Let's set the stage:
$(document).ready(function() {
	$('#menu_options').autoreveal();
	$('#product_detail_image').hide();
	$('#product_sandwich_platter').hide();
	$('#product_giant_subs').hide();
	$('#product_cookie_platter').hide();
});