function glow() { // Set's Otto's 'e' to glow over 6 second cycle
	$("#qglow").animate({opacity: 1}, {duration: 3000})
		   .animate({opacity: 0}, {duration: 3000, complete: glow});
};
$(document).ready ( function() {
	$('#slider').cycle ({ // Initialize slider effects
		fx: 'scrollHorz',
		speed: 'fast',
		timeout: 5000,
		pager: '#slidernav',

		pagerAnchorBuilder: function(idx, slide) {
			return '<a href="#" id="sn-' + idx + '"></a>"';

		}
	});
	$('.topfancy').fancybox({ // This is for the narrow menu fancyboxes
		'titleShow'				: false,
		'hideOnContentClick'	: false,
		'overlayShow'			: false,
		'centerOnScroll'		: false,
		// Custom positioning code with plenty of redundancy for IE versions
		'onStart'		: function() {
			var offset = ($(window).height() / 2) - 210;
			$("#fancybox-outer").css({"margin-top": 0 - offset});
			$('.backward').hide();
			$('.forward').hide();
		},
		'onComplete'	: function() {
			$("#fancybox-outer").css({"top":"100px","position":"fixed","height":"auto","width":"auto","margin-top":""});
			var whichmenu = $("#fancybox-content > div > div").attr("id");
			if ( $('#' + whichmenu + '-scroll > .scroller').width()  >  $('#' + whichmenu + '-scroll').width() ) {
				$('#' + whichmenu + '-fwd').show();
			}
		},
		'onClosed'		: function() {
			$("#fancybox-outer").css({"position":"","top":"","height":"","width":"","margin-top":""});
		},
		'onCleanup'		: function() {
			$('.scrollshell').scrollLeft(0); // Reset scrolling when closing fancyboxes
		}

	});
	$('.bigfancy').fancybox({ // This is for the normal fancyboxes
		'titleShow'				: false,
		'hideOnContentClick'	: false,
		'overlayShow'			: false,
		'centerOnScroll'		: true,
		'scrolling'				: false,
		// Ensure that default positioning is in effect
		'onStart'		: function() {
			$("#fancybox-outer").css({"position":"","top":"","height":"","width":"","margin-top":""});
			$('.backward').hide();
			$('.forward').hide();
		},
		'onComplete'	: function() {
			var whichmenu = $("#fancybox-content > div > div").attr("id");
			whichmenu = whichmenu.replace(/-[^-]+$/, "");
			if ( $('#' + whichmenu + '-scroll > .scroller').width() - ( $('#' + whichmenu + '-scroll').scrollLeft() ) > ( $('#' + whichmenu + '-scroll').width() + 20 ) ){
				$('#' + whichmenu + '-fwd').show();
			}
		},
		'onCleanup'		: function() {
			$('.scrollshell').scrollLeft(0); // Reset scrolling when closing fancyboxes
		}
	});
	$('.forward').click(function() { // Scroll right on forward arrows for fancyboxes 
		var whichmenu = $(this).attr("id");
		whichmenu = whichmenu.replace(/-[^-]+$/, "");
		$('#' + whichmenu + '-scroll').animate({ scrollLeft: $('#' + whichmenu + '-scroll').scrollLeft() + 257 });
		$('#' + whichmenu + '-back').show('fast');
		if ( $('#' + whichmenu + '-scroll > .scroller').width() - ( $('#' + whichmenu + '-scroll').scrollLeft() + 257 ) <= $('#' + whichmenu + '-scroll').width() ) {
			$(this).hide('fast');
		}
	});
	$('.backward').click(function() { // Scroll backward for back arrows on fancyboxes
		var whichmenu = $(this).attr("id"); 
		whichmenu = whichmenu.replace(/-[^-]+$/, "");
		$('#' + whichmenu + '-scroll').animate({ scrollLeft: $('#' + whichmenu + '-scroll').scrollLeft() - 257 });
		if (( $('#' + whichmenu + '-scroll').scrollLeft() - 257 ) < 20) {
			$(this).hide('fast');
		}
		$('#' + whichmenu + '-fwd').show('fast');
	});
});
$(window).load(function () {
	glow(); // Set Otto's e glowing after everything else
});
