// *** jQuery ready


// flavor page tabs
jQuery(function($) {
	
	// if ie6, load and call pngfix 
	if ($.browser.msie && $.browser.version < 7){
		png_fix_selectors = '.pngfix, .jScrollArrowUp, .jScrollArrowDown, .pf, .callout, #flavor-list li, #menu a, .slide-col-a h2, .slide-col-a aside a, .slide-col-b img, #callouts-b a, #callouts-b li div, .post-to, #col-a h2, #col-a h3, #nav-4 div, .share a, #callout-contents, .flavor-content, .flavor-description h2, #loading-flavor-contents, .tab-share a, #number-1, .flavor-tweet img, #callout-voted-pack, #interstitial h2, #interstitial a';
		$.getScript ('/js/DD_belatedPNG.js', function() {
			DD_belatedPNG.fix(png_fix_selectors);
		});
	}
	
	///////// stylish select, dropdowns on index	
	if ($.browser.msie && $.browser.version < 8){
	}else{
		$('#callout-contents select').sSelect({});
		$('#flavor-wall #sorts select').sSelect({});
	}
	
	/////////// 404
	
	$('#button-do-404').click(function() {
		// swap active classes
		$(this).addClass('active');
		$('#button-dont-do-404').removeClass('active');
		
		// show and hide divs
		$('#do-404').fadeIn();
		$('#dont-do-404').hide();
	});
	
	$('#button-dont-do-404').click(function() {
		// swap active classes
		$(this).addClass('active');
		$('#button-do-404').removeClass('active');
		
		// show and hide divs
		$('#dont-do-404').fadeIn();
		$('#do-404').hide();
	});
	
	
	///////////
	
	
		
	var nutritionIsShowing = false;
	
	// slide nutrition tab up or down when clicked
	$('.tab-nutrition').live('click', function(){
		
		// if the dropdown is not showing
		if (!nutritionIsShowing)
		{
			$(this).parents('.nutrition-dropdown').css('z-index', '2');
			$('.share-dropdown').css('z-index', '1');
		
			// slide down
			$(this).parents('.nutrition-dropdown').animate({
				top: 0
			}, 400, 'swing', function() {$(this).find('.tab-nutrition a').addClass('expanded');});
		}
		else
		{
			// slide up
			$(this).parents('.nutrition-dropdown').animate({
				top: -265
			}, 400, 'swing', function() {
				$(this).find('.tab-nutrition a').removeClass('expanded');
				
				// if share tab is showing, move nutrition tab behind it
				if (shareIsShowing)
				{
					$(this).css('z-index', '1');
					$('.share-dropdown').css('z-index', '2');
				}
			});
		}
		
		// toggle flag
		nutritionIsShowing = !nutritionIsShowing;
	});
	
	var shareIsShowing = false;
	
	// slide nutrition tab up or down when clicked
	$('.tab-share').live('click', function(){

		// if the dropdown is not showing
		if (!shareIsShowing)
		{
			// put share dropdown above nutrition dropdown
			$('.nutrition-dropdown').css('z-index', '1');
			$('.share-dropdown').css('z-index', '2');
			
			// slide down
			$(this).parents('.share-dropdown').animate({
				top: 0
			}, 400, 'swing', function() {$(this).find('.tab-share a').addClass('expanded');});
		}
		else
		{
			// slide up
			$(this).parents('.share-dropdown').animate({
				top: -131
			}, 400, 'swing', function() {
				$(this).find('.tab-share a').removeClass('expanded');
				
				// put share dropdown behind nutrition dropdown
				$('.nutrition-dropdown').css('z-index', '2');
				$('.share-dropdown').css('z-index', '1');
			});
		}
		
		// toggle flag
		shareIsShowing = !shareIsShowing;
	});

});

// section - faq 
jQuery(function($) {

	// faq page tabs
	$('#tab-faq').live('click',function() {
		
		// swap tab colors
		$(this).addClass('active');	
		$('#tab-user-questions').removeClass('active');
		
		// show faq content
		$('#tab-content-faq').fadeIn();
		
		// hide user question content
		$('#tab-content-user-questions').hide();
		
		// scroll hidden div back to top
		$('#tab-content-user-questions .scroll-pane')[0].scrollTo(0);
	})
	
	$('#tab-user-questions').live('click',function() {
		
		// swap tab colors
		$(this).addClass('active');	
		$('#tab-faq').removeClass('active');
		
		// show user question content
		$('#tab-content-user-questions').fadeIn();
		
		// hide faq content
		$('#tab-content-faq').hide();
		
		// scroll hidden div back to top
		$('#tab-content-faq .scroll-pane')[0].scrollTo(0);
	})
	
	// faq scroll pane
	$('#faq-question-content .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:14, arrowSize:18, scrollbarMargin:20});
	
	
	// hide faq tab initially
	$('#tab-content-faq').hide();
	
});

// section - @history
jQuery(function($) {

	$('#history-content-timeline').hide();
	$('#slide-history-pages').hide();
	
	$('#history-enter-link').live('click', function() {
		// hide welcome div
		$('#history-content-intro').fadeOut();
		
		// show timeline div and control div
		$('#history-content-timeline').fadeIn();
		$('#slide-history-pages').fadeIn();
	});
	
	// right arrow on timeline moves timeline forward one item
	$('#history-slide-button-right').live('click', function(){
				
		element_current = $('#history-nav-container .active-slide').parent().index();
		
		$('#history-nav-container ul li:nth-child(' + (element_current + 2) + ') a').trigger('click'); // +2 because unline index(), nth-child counting starts at 1, and we want 1 more than current element
	
		return false;
	});
	
	// left arrow on timeline moves timeline back one item
	$('#history-slide-button-left').live('click', function(){
				
		element_current = $('#history-nav-container .active-slide').parent().index();
		
		$('#history-nav-container ul li:nth-child(' + (element_current) + ') a').trigger('click'); // don't need to subtract from element_current because nth-child counting starts at 1, unline index()
	
		return false;
	});
	
	// last arrow on timeline moves timeline forward to final item
	$('#history-slide-button-last').live('click', function(){
		
		element_current = $('#history-nav-container .active-slide').parent().index();
		
		$('#history-nav-container ul li:nth-child(' + (10) + ') a').trigger('click'); // +2 because unline index(), nth-child counting starts at 1, and we want 1 more than current element
		
		return false;
	});
	
	// first arrow on timeline moves timeline back to beginning
	$('#history-slide-button-first').live('click', function(){
		
		element_current = $('#history-nav-container .active-slide').parent().index();
		
		$('#history-nav-container ul li:nth-child(' + (1) + ') a').trigger('click'); // don't need to subtract from element_current because nth-child counting starts at 1, unline index()
		
		return false;
	});
});
		

// section - general
	jQuery(function($) {
	
		if($.browser.webkit){
			the_top = 'body';
		}
		else {
			the_top = 'html';
		}
		
		// new window
		$('.new').attr("target","_blank");
	
		// deep link
		var deepLink;
		deepLink = jQuery.url.attr("anchor");
		if (deepLink == 'privacy-policy'){

		//  BEG needed to get this done quickly.

			var go_where = deepLink;
			var feature_height = '491px';
			var feature_top = '222';

			$('.flavor-image').removeClass('flavor-image-on');
			$('#slide-flavor li:eq(0)').removeClass();
			// removed .empty() before removeClass

			// default to homepage
			if(go_where == ''){
				go_where = 'slide';
				feature_height = '329px';
				feature_top = '-113';

				// reset panels
				$('#callouts-b').fadeOut();
				$('#callouts-a').fadeIn();
			}
			else{

				// reset panels
				$('#callouts-a').fadeOut();
				$('#callouts-b').fadeIn();
			}

			currentPanel();

			$(the_top).delay(250).animate({scrollTop:0}, 'slow',function(){
			
				$('#forms-form-register,#forms-form-login').hide('fast');
				$('#form-register,#form-login').slideUp();

				$('#feature').animate({
					height: feature_height
				}, 500,function(){
				
					$('#loading-flavor').removeClass().dialog({
						modal: true,
						position: ['center',feature_top],
						width: 191,
						height: 114
					});
					
					// load homepage, or other panels
					if(go_where == 'slide'){
						$('.ui-dialog').css("margin-top",feature_top + 'px');
						$('#slide').fadeIn();
						//oc: don't show the #slide-pages
						$('#slide-pages').show();
						$('#loading-flavor').dialog('close')
						panelLoading(go_where,current_panel_id);
					}
					else {
						
						$('#' + go_where).load('/' + go_where + '.php' + ' #page-' + go_where,function(){
							$('#loading-flavor').dialog('close');
							panelLoading(go_where,current_panel_id);
							$('#' + go_where).delay(500).fadeIn(function(){
								//$('#slide-' + go_where + '-pages').show();
								
								$('#privacy-entry,#legal-entry,#faq-question-content .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:14, arrowSize:18, scrollbarMargin:20});
								$('#tab-user-questions').trigger('click');
								
								windowWidth(go_where);
								
								if(go_where == 'history'){
									addShareLinks('#history', 'http://stridegum.com/history');
								};
								
								
								
							});
							
							
						});
						
						$('#slide').hide();
						$('#privacy-policy').show().delay(750).fadeIn(function(){
						
						$('#privacy-entry').jScrollPane({showArrows:true, scrollbarWidth:14, arrowSize:18, scrollbarMargin:20});
						
						});
						windowWidth(deepLink);
						
						
						
						
					}
				


				});



			});
		
		//  END needed to get this done quickly.
		
		}
	
		// functions
		current_panel_id = '';
		
		function currentPanel(){
			current_panel_id = $('.content-panel:visible').attr("id");
		}
		
		function panelLoading(not_this,current){

			if(not_this == ''){
				var not_this = 'null';
			}

			var panel_id = current;
			
				if(panel_id != 'slide'){	
					var panel_id_pg = 'slide-' + panel_id;
				}
				else{
					var panel_id_pg = panel_id;
				}

				if(panel_id != not_this){
					$('#' + panel_id + ',#' + panel_id_pg + '-pages').fadeOut('slow');
				}

			// if we are leaving the history section, reset it
			if (panel_id == 'history'){
				$('#history-content-timeline').hide();
				$('#history-content-intro').show();
				$('#slide-history-pages').hide();
				
				$('#history-nav-container #h-1 a').trigger('click');

			}
			// if we are leaving the faq section, reset it
			else if (panel_id == 'faq'){
				// hide faq tab
				$('#tab-content-faq').hide();
				
				// show user question tab
				$('#tab-content-user-questions').show();
				
				// scroll back to top
				$('#tab-content-faq .scroll-pane')[0].scrollTo(0);
				$('#tab-content-user-questions .scroll-pane')[0].scrollTo(0);
				
				// reset active tab
				$('#tab-faq').removeClass('active');
				$('#tab-user-questions').addClass('active');
			}
		}
	
		function moveSlides(type,which_container,which_container_p){
			//alert(type);
			var i = 0;

			if(type == 'animate'){

				for (i = 0; i < number_of_moves; i++){

					if(element_direction == 'f'){
						which_slide_to_move = element_current + i;
						slide_length = window_width;
					}
					else{
						which_slide_to_move = (element_current - 1) - i;
						slide_length = 0;
					}
					
					$('#' + which_container + ' li').eq(which_slide_to_move).animate({
						marginLeft: element_correct_offset + slide_length
					}, 750,function(){
					
						// double content, tricky	
						if(which_container == 'slide-flavor'){
							$('#slide-flavor ul').append('<li></li>');
							windowWidth('slide-flavor');
							$('#slide-flavor li:eq(0)').remove();
							
							//$('#slide-flavor li').removeClass(first_slide);
							
							
							//var double_content = $('#slide-flavor li:eq(1)').html();
							//var class_from_slide = $('#slide-flavor li:eq(1)').attr("class");
							
							//$('#slide-flavor li:eq(0)').addClass(class_from_slide).html(double_content).css("margin-left","0");
							$('#flv-2 a,#slide-flavor li:eq(1)').removeClass();
							$('#flv-1 a').addClass('active-slide');
							
						}
						
						
					});
				}
			}
			else if(type == 'move'){
			
				current_slide = $('#' + which_container_p + ' .active-slide').parent().index();
				for (i = 0; i < current_slide; i++){
				
					$('#' +  which_container + ' li').eq(i).css("margin-left",'-' + window_width + 'px')
				}
			}
			
			
		}
		
		function slidePages(which_container,which_container_b,which_container_p){
		
			$('#' + which_container + ' ul a').live('click', function(){
				start_calls = 'y';
				element_index = $(this).parent().index();
				element_current = $('#' + which_container + ' .active-slide').parent().index();

			
				$('#' + which_container + ' a').removeClass();
				$(this).addClass('active-slide');
				
				if (element_index != element_current){
					if(element_index > element_current){
						element_correct_offset = '-';
						element_direction = 'f';
					}
					else {
						element_correct_offset = '+';
						element_direction = '';
					}
					
					number_of_moves = Math.abs((element_index - element_current));
					
					moveSlides('animate',which_container_b,which_container_p);
	
				}
				return false;
			});
		}



		// *** ready ***
		
		
		// home link
		$('h1.pf a').hover(function(){
			$('h1.pf').animate({
				marginTop: '-22px'
			}, 200);
		},function(){
			$('h1.pf').animate({
				marginTop: '-28px'
			}, 200);
		});
		
		// flavor scroll 
		$('#nav-t-1').click(function($e){
				$e.preventDefault();
				$(the_top).delay(300).animate({scrollTop:376}, 'fast',function(){});
	
			return false;
		});
		
		// link/url parse
		$('.internal').live('click',function(){

			var go_where = $(this).attr("href").substring(1);
			var feature_height = '491px';
			var feature_top = '222';

			$('.flavor-image').removeClass('flavor-image-on');
			$('#slide-flavor li:eq(0)').removeClass();
			// removed .empty() before removeClass

			// default to homepage
			if(go_where == ''){
				go_where = 'slide';
				feature_height = '329px';
				feature_top = '-113';

				// reset panels
				$('#callouts-b').fadeOut();
				$('#callouts-a').fadeIn();
			}
			else{

				// reset panels
				$('#callouts-a').fadeOut();
				$('#callouts-b').fadeIn();
			}

			currentPanel();

			$(the_top).delay(250).animate({scrollTop:0}, 'slow',function(){
			
				$('#forms-form-register,#forms-form-login').hide('fast');
				$('#form-register,#form-login').slideUp();

				$('#feature').animate({
					height: feature_height
				}, 500,function(){
				
					$('#loading-flavor').removeClass().dialog({
						modal: true,
						position: ['center',feature_top],
						width: 191,
						height: 114
					});
					
					// load homepage, or other panels
					if(go_where == 'slide'){
						$('.ui-dialog').css("margin-top",feature_top + 'px');
						$('#slide').fadeIn();
						// oc: don't show the #slide-pages
						$('#slide-pages').show();
						$('#loading-flavor').dialog('close');
						panelLoading(go_where,current_panel_id);
					}
					else {
						$('#' + go_where).load('/' + go_where + '.php' + ' #page-' + go_where,function(){
							$('#loading-flavor').dialog('close');
							panelLoading(go_where,current_panel_id);
							$('#' + go_where).delay(500).fadeIn(function(){
								//$('#slide-' + go_where + '-pages').show();
								
								$('#privacy-entry,#legal-entry,#faq-question-content .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:14, arrowSize:18, scrollbarMargin:20});
								$('#tab-user-questions').trigger('click');
								
								windowWidth(go_where);
								
								if(go_where == 'history'){
									addShareLinks('#history', 'http://stridegum.com/history');
								};
								
								
								
							});
						});
					}
				


				});



			});
			
			return false;
		})
		
		number_of_moves = 1;
		
		// menu system
		$('#menu .sub-menu').mouseenter(function(){
			var which_menu = $(this).attr('id').substring(4,5);
			$(this).addClass('menu-active');
			$('#nav-' + which_menu + '-bg').slideDown(200);
			$(this).find('.nav-tab-links').show('slow');
		});
		
		
		$('#menu .sub-menu').mouseleave(function(){
			var which_menu = $(this).attr('id').substring(4,5);
			$(this).removeClass('menu-active');
			$('#nav-' + which_menu + '-bg').stop(true, true).slideUp(200);
			$(this).find('.nav-tab-links').stop(true, true).hide('fast');
		});
		
		function windowWidth(which_container){
			window_width = $(window).width();
			$('#' + which_container + ',#' + which_container + ' .ss > li').css("width",window_width + 'px');
			var number_of_slides = ($('#' + which_container + ' .ss > li').length) * (window_width);
			$('#' + which_container + ' .ss').css("width",number_of_slides + 'px');
		}
		
		// slideshow
		
		windowWidth('slide');
		windowWidth('slide-flavor');
		windowWidth('faq');
		windowWidth('history');
		windowWidth('four-oh-four');
		windowWidth('site-map');
		windowWidth('privacy-policy');
		windowWidth('legal');
		
		start_calls = '';
		
		$(window).resize(function() {
			windowWidth('slide');
			windowWidth('slide-flavor');
			windowWidth('faq');
			windowWidth('history');
			windowWidth('four-oh-four');
			windowWidth('site-map');
			windowWidth('privacy-policy');
			windowWidth('legal');
			if(start_calls == 'y'){
				moveSlides('move','slide','slide-pages');
				moveSlides('move','slide-flavor','slide-flavor-pages');	
				moveSlides('move','faq','faq-pages'); // (faq-pages doesn't exist)
				moveSlides('move','history-intro','history-intro-pages');
				moveSlides('move','history-timeline-list-wrapper','slide-history-pages');			
				moveSlides('move','four-oh-four','four-oh-four-pages'); // (four-oh-four-pages doesn't exist)
			}
		});
		
		slidePages('slide-pages','slide','');
		slidePages('slide-flavor-pages','slide-flavor','');
		slidePages('slide-history-pages','history','');

		smani = new Array();

		// Now make it an asssociative array
		smani["flash-always-mandarin"] = "flash-always-mandarin";
		smani["flash-always-mandarin-width"] = "469";
		smani["flash-always-mandarin-height" ] = "292";

		smani["flash-forever-fruit"] = "flash-forever-fruit";
		smani["flash-forever-fruit-width"] = "507";
		smani["flash-forever-fruit-height" ] = "254";

		smani["flash-mega-mystery"] = "flash-mega-mystery";
		smani["flash-mega-mystery-width"] = "370";
		smani["flash-mega-mystery-height" ] = "329";

		smani["flash-nonstop-mint"] = "flash-nonstop-mint";
		smani["flash-nonstop-mint-width"] = "643";
		smani["flash-nonstop-mint-height" ] = "491";

		smani["flash-shift-berry-to-mint"] = "flash-shift-berry-to-mint";
		smani["flash-shift-berry-to-mint-width"] = "437";
		smani["flash-shift-berry-to-mint-height" ] = "173";

		smani["flash-spearmint"] = "flash-spearmint";
		smani["flash-spearmint-width"] = "390";
		smani["flash-spearmint-height" ] = "254";

		smani["flash-sweet-cinnamon"] = "sweet-cinnamon";
		smani["flash-sweet-cinnamon-width"] = "54";
		smani["flash-sweet-cinnamon-height" ] = "114";

		smani["flash-sweet-peppermint"] = "sweet-peppermint";
		smani["flash-sweet-peppermint-width"] = "305";
		smani["flash-sweet-peppermint-height" ] = "185";

		smani["flash-uber-bubble"] = "flash-uber-bubble";
		smani["flash-uber-bubble-width"] = "150";
		smani["flash-uber-bubble-height" ] = "150";

		$('a.flavor-image').live('click',function(){
			if(!$(this).hasClass('flavor-image-on')){

				// vars
				first_slide = $('#slide-flavor li:eq(0)').attr("class");

				var change_class = 'flavor-' + $(this).attr("href").replace('/flavorwall/flavor/name/','');
				var load_class = 'load-' + $(this).attr("href").replace('/flavorwall/flavor/name/','');
				var flash_class = 'flash-' + $(this).attr("href").replace('/flavorwall/flavor/name/','');

				var which_page_to_load = $(this).attr("href");
				
				$('#slide-flavor #slide-flavor li:eq(1)').addClass(change_class);
				
				$('#loading-flavor').attr("class",load_class);
			
				// highlight selection
				$('.flavor-image').removeClass('flavor-image-on');
				$(this).addClass('flavor-image-on');
				
				// scroll to top of page --- might have to add in other methods
				$(the_top).delay(250).animate({scrollTop:0}, 'slow',function(){
					
					$('#forms-form-register,#forms-form-login').hide('fast');
					$('#form-register,#form-login').slideUp();
					
					currentPanel();
					
					$('#feature').animate({
						height: '491px'
					}, 500,function(){
						
						$('#loading-flavor').dialog({
							modal: true,
							position: ['center',222],
							width: 191,
							height: 114
						});

						//determine wether to load in wordpress or local php files
/*						var url = new String($(location).attr('href'));
						var loadUrl;
						//alert(url.indexOf("mode=wordpress"));
						if (url.indexOf("mode=wordpress") > 0) { 
							loadUrl = '/flavors/'+which_page_to_load;
						} else {
							loadUrl = which_page_to_load + '.php';
						}*/
						
						loadUrl = which_page_to_load;	
						$('#slide-flavor li:eq(1)').load(loadUrl + ' .flavor-single',function(){	
						
							if(smani[flash_class]){
								swfobject.embedSWF("/swf/" + flash_class + ".swf", change_class + '-animation', smani[flash_class + '-width'], smani[flash_class + '-height'], "9.0.0","expressInstall.swf", flashvars, params, attributes);
							}
							
							$('#slide-flavor').show();
							$('#loading-flavor').dialog('close');
							panelLoading('slide-flavor',current_panel_id);
							$('#slide-flavor-pages li:eq(1) a').trigger("click");
							
							// populate share links
							addShareLinks('.flavor-content', 'http://stridegum.com/' + which_page_to_load);

							// intialize add this again
							var scriptAddThis = 'http://s7.addthis.com/js/250/addthis_widget.js?domready=1#username=xa-4c2d2e603054dfd4';
							if (window.addthis){
								window.addthis = null;
							}
							$.getScript(scriptAddThis);
						});
						
						// change side panel
						$('#callouts-a').fadeOut();
						$('#callouts-b').fadeIn();
					});
	
				});
			
			};

			return false;
			
		});



		// flavor wall
		function wallPrevNext(which_way){

			function wallVars(){
				position = $('#flavor-list').css("margin-left").replace('px','');
				position_diff = (Math.abs(position) / 162);

				position_length = $('#flavor-list li').length;
				// stopping point
				the_end = Math.floor(position_length / 3) - 1;
				position_end = Math.abs(position) / the_end;
			}

			$('#' + which_way).live('click',function(){

				// prevent fast clicks

				if($(this).parent().attr("class") != 'disable-np'){
					$('#previous-next-prevent').show();
				}
				
				var stop_forward = '';

				wallVars();

				if(position_end == '162' && which_way != 'wall-previous'){
					var stop_forward = 'y';
				}

				if(which_way == 'wall-previous'){
					var position_total = Math.abs(position) - 162;

					if(position_end == '162'){
						$('#wpn-n').removeClass('disable-np');
					}

				}
				else{
					var position_total = (position_diff + 1) * 162;
					if(position_total == '0'){
						position_total = 162;
					}
				}

				if(stop_forward != 'y'){
					$('#flavor-list').animate({
						marginLeft: '-' + position_total + 'px'
					}, 200,function(){

						wallVars();

						if(position_end > '0'){
							$('#wpn-p').removeClass('disable-np');
						}
						else if(position_end == '0'){
							$('#wpn-p').addClass('disable-np');
						}

						if(position_end == '162'){
							$('#wpn-n').addClass('disable-np');
						}

					$('#previous-next-prevent').hide();

					});
				}

				return false;
			});
			
		}

		loadFlavorWall();
			
		$("#order-by").change(function() 
		{ 
			var sort = $("#order-by").val();

			$('#wpn-p').addClass('disable-np');
			$('#wpn-n').removeClass('disable-np');

			loadFlavorWall(sort);
		});

		function loadFlavorWall(sort){
			if (! sort) sort = "popular";
			$.ajax({ url: "/flavors/flavorwall?sort="+sort, context: document.body, success: function(data){
				$('#flavor-list-container').html(data);
				
				
				wallPrevNext('wall-previous');
				wallPrevNext('wall-next');
				
				var wall_count = Math.ceil($('#flavor-list li').length / 2) *  162;
		
				//$('#flavor-list').css("width",wall_count + 'px');

			}});
		}

		// interstitial
		$('.interstitial').live('click',function(){
			var stored_link = $(this).attr("href");

			$('#forms-form-register,#forms-form-login').hide('fast');
			$('#form-register,#form-login').slideUp();

			$(the_top).delay(250).animate({scrollTop:0}, 'slow',function(){

				$('#i-ok').attr("href",stored_link);

				if ($('#slide').is(":visible")) {
					var position_from_top = 80;
				}
				else{
					var position_from_top = 170;  
				}

				$('#form-register,#form-login').slideUp(function(){
				
					$('#interstitial').dialog({
						modal: true,
						position: ['center',position_from_top],
						width: 552,
						height: 256
					});
				
				});

				$('#i-ok,#i-cancel').click(function(){
					$('#interstitial').dialog('close');
				});

			});

			return false;

		})
		
		
		// sitemap
		$('#site-map-content a:not(.internal)').live('click',function(){
		
			var which_site_link = $(this).parent().attr("id").replace('sm-','f-');
			$('#' + which_site_link + ' > a').trigger("click");
			
			
			return false;
		});
		
		// history
		$('.history-slide .description a').live('click',function(){
		
			var which_site_link = $(this).attr("id").replace('hstry-','f-');
			$('#' + which_site_link + ' > a').trigger("click");
			
			return false;
		});
		
		//oc: todo: carousel updates here.
		// autoplay for home page
		$(window).load(
			function() {
				$('#find-us-on').animate({opacity: 1.0}, 6000,function(){
					$('#f-2 a').trigger("click");
					$('#find-us-on').animate({opacity: 1.0}, 6000,function(){
						$('#f-3 a').trigger("click");
						$('#find-us-on').animate({opacity: 1.0}, 6000,function(){
							$('#f-4 a').trigger("click");
							$('#find-us-on').animate({opacity: 1.0}, 6000,function(){
								$('#f-1 a').trigger("click");
							});
						});
					});
				});
			}
		);

		// what are you chewing?
			function cnvrt2Upper(str) {
				return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
				function cnvrt() {
					return arguments[0].toUpperCase();
				}
			}


		$('#chewing-selection').change(function(){
			var chew_value_twitter = $('#chewing-selection').val();
			
			chew_value_twitter = cnvrt2Upper(chew_value_twitter).replace('-','');
			
			if(chew_value_twitter == 'EternalMelon'){
				chew_value_twitter = 'Melon';
			}
			
			$('#post-to-twitter').attr("href","http://twitter.com/home?status=" + '%23StrideGum' + '%20I%20am%20chewing%20%23' + chew_value_twitter);
			$('#post-to-facebook').attr("href");
		})

		

		/* addthis share tab */

		function getShareLink(serviceName, linkText, url){
			return '<a class="addthis_button_' + serviceName + ' at300b new interstitial" href="http://api.addthis.com/oexchange/0.8/forward/' + serviceName + '/offer?url=' + url + '" title="' + linkText + '"><span class="at300bs at15t_' + serviceName + '"></span>' + linkText + '</a>';
		}
		
		function getShareLinkNoInter(serviceName, linkText, url){
			return '<a class="addthis_button_' + serviceName + ' at300b new" href="http://api.addthis.com/oexchange/0.8/forward/' + serviceName + '/offer?url=' + url + '" title="' + linkText + '"><span class="at300bs at15t_' + serviceName + '"></span>' + linkText + '</a>';
		}
		
		// will add share links to the .share-items element inside of 'container' which target 'url'
		function addShareLinks(container, url)
		{			
			//////////////////////////////////////////////////
			// use sharing endpoints instead of javascript
			// http://www.addthis.com/help/sharing-api
			
			// set up links
			var linkEmail = getShareLinkNoInter('email', 'Email', url);			
			//var linkPrint = getShareLink('print', 'Print', url);
			var linkDigg = getShareLink('digg', 'Digg', url);
			var linkMyspace = getShareLink('myspace', 'MySpace', url);
			var linkFacebook = getShareLink('facebook', 'Facebook', url);
			var linkTwitter = getShareLink('twitter', 'Twitter', url);
			var linkFavorites = getShareLinkNoInter('favorites', 'Favorites', url);
			var linkDelicious = getShareLink('delicious', 'Delicious', url);
			var linkGoogle = getShareLink('google', 'Google', url);
			var linkLive = getShareLink('live', 'Live', url);
			var linkStumbleUpon = getShareLink('stumbleupon', 'Stumble', url);
			//var linkMore = getShareLink('more', 'More', url);
			
			// add links to .share-items within 'container'
			$(container + ' .share-items').html(
				'<div class="addthis_toolbox"><div class="two_column"><div class="column1">' 
				+ linkEmail + linkDigg + linkMyspace + linkFacebook + linkTwitter 
				+ '</div><div class="column2">' 
				+ linkFavorites + linkDelicious + linkGoogle + linkLive + linkStumbleUpon 
				+ '</div></div></div>'
			);
			
		}
		
		// add share links for history section	
		addShareLinks('#slide', 'http://stridegum.com/');
	});
	
	$(document).ready(function() {

		// for username field
		$('.clearField').clearField();
		
		// for password field
		$('#password-clear').show();
		$('#password-password').hide();
		
		$('#password-clear').focus(function() {
		    $('#password-clear').hide();
		    $('#password-password').show();
		    $('#password-password').focus();
		});
		$('#password-password').blur(function() {
		    if($('#password-password').val() == '') {
		        $('#password-clear').show();
		        $('#password-clear').blur();
		        $('#password-password').hide();
		    }
		});
		
		if ($.browser.msie && $.browser.version < 8){
		}else{
		// for selects
		$('#state-select').sSelect({ddMaxHeight: '87px'});
		$('#sex-select').sSelect({ddMaxHeight: '87px'});

		$('#age-check-birthday-month-select').sSelect({ddMaxHeight: '87px'});
		$('#age-check-birthday-day-select').sSelect({ddMaxHeight: '87px'});
		$('#age-check-birthday-year-select').sSelect({ddMaxHeight: '87px'});
		}

		// wrap stylish select list item in scroll-pane div 
		//$('.newList').html('<li><ul class="scroll-pane">' + $('.newList').html() + '</ul></li>');
		
		// for checkbox
		$('a#opt-in-button').toggle(function() {
			//checked
			$('#opt-in').attr("value","I");
			$(this).css('backgroundPosition', 'top left');
		}, function() {
			//unchecked
			$('#opt-in').attr("value","O");
			$(this).css('backgroundPosition', 'bottom left');
		});


	

		// for logged in state
		
		
		/////// for testing logout button
		//$('#nav-6').hide();
		//$('#nav-7').hide();
		$('#nav-8').hide();
		$('#nav-9').hide();
		$('#nav-10').hide();
		
		$('#register-wrapper').hide();
		//$('#age-check-wrapper').hide();
		
		//add this email a friend

		addthis.addEventListener("addthis.menu.open", function() {
			if(!$('#ateml-disclaimer').length){
				$('#ateml').before('<div id="ateml-disclaimer">Information collected on this form is being collected temporarily and solely for the purpose of sending your message. Providing names on this page is not required to enter any promotion on the site and will not increase your chances of winning any promotions advertised on the site.</div>');
			}
		});

		
	});
	
		
