$('.active').next('.sub-list').fadeIn('slow');
		
		$('.main-link > a').bind('click', function() {
			$('.active').removeClass('active');
			$('.sub-list').hide();
			$(this).parent().prevAll().detach().appendTo('.main-list');
			$(this).addClass('active');
			$(this).parent().children('.sub-list').show();
			$(this).css({
				'-webkit-animation': '',
				'-moz-animation': '',
				'animation': ''
			});
		});
		
		function yes(data) {
			(function() {
				$('.side.front').empty().append('<div class="animation">' + data + '</div>');
				
				if(!($('form').is('*'))) {
					$('.side.right').empty().append($('.animation').clone()).children(function() {
						$(this).css({
							'-webkit-animation': 'slide-right 0.6s 1 linear',
							'animation': 'slide-right 0.6s 1 linear'
						});
					});
				}
				$('.logo').css({
					'-webkit-animation': 'rotate-cw .23s 1 linear',
					'-moz-animation': 'rotate-cw .23s 1 linear',
					'animation': 'rotate-cw .23s 1 linear'
				});
				$('.main-link .active').css({
					'-webkit-animation-name': 'bounce-left',
					'-moz-animation-name': 'bounce-left',
					'animation-name': 'bounce-left'
				});
			})();
		};
		
		var checkBrowser = function() {
		
			CFInstall.check({ mode: "overlay" });
			
			// if ($.browser.webkit) {
				$('.side').delegate('.animation', 'webkitAnimationEnd webkitAnimationEnd animationend', function() {
					if($(this).hasClass('right')) {
						$(this).empty();
					}
					$(this).css({
						'-webkit-animation-name': '',
						'-moz-animation-name': '',
						'animation-name': '',
					});
				});
			// } else {
			// 	//Display the 'unsupported browser' message
			// 	$.ajax({
			// 		url: 'unsupported.html',
			// 		success: function(data) {
			// 			$('body').append(data);
			// 			$('.u').animate({'top':'-37px' }, function() {
			// 				$('.ignore').click(function() {
			// 					$('.u').animate({'top':'-589px'}, function() {
			// 						$(this).remove();
			// 					});
			// 				});
			// 			});
			// 		}
			// 	});
				
			//}
			//Fix the twitter css
			$(document).ready(function () {
				twitter.cycleTweets();
			})
		};
		
		var twitter = {
			
			addFollowButton: function() {
				//Add the "Follow Me" link to the twitter box
				$('.twitter-box').prepend('<a class="btn followme" target="_blank" href="http://twitter.com/#!/johnkreitlow">Follow Me!</a>');
			},
			
			cycleTweets: function() {
				var tweets = document.getElementById('twitter_update_list');
				var thisTweet = tweets.childNodes[0];

				if (typeof thisTweet !== 'undefined') {

					var nextTweet = function (e) {
						this.style.webkitAnimationName = '';
						this.style.mozAnimationName = '';
						this.style.animationName = '';
						this.removeEventListener('webkitAnimationEnd', nextTweet, true);
						this.removeEventListener('mozAnimationEnd', nextTweet, true);
						this.removeEventListener('animationend', nextTweet, true);
						tweets.appendChild(tweets.childNodes[0].cloneNode(true));
						tweets.removeChild(tweets.childNodes[0]);
						twitter.cycleTweets();
					}


					if (!thisTweet.hasOwnProperty('nextTweetHandler')) {
						thisTweet.nextTweetHandler = function (e) {
							return nextTweet.apply(thisTweet, arguments);
						};
					}

					thisTweet.style.webkitAnimationName = 'twitterfade';
					thisTweet.style.animationName = 'twitterfade';

					thisTweet.addEventListener('webkitAnimationEnd', thisTweet.nextTweetHandler, true);
					thisTweet.addEventListener('mozAnimationEnd', thisTweet.nextTweetHandler, true);
					thisTweet.addEventListener('animationend', thisTweet.nextTweetHandler, true);
				}


				/* $('#twitter_update_list').delegate('li:first-child', {
					'webkitAnimationEnd mozAnimationEnd': function() {
						console.log('hello');
						$(this).css({
							'-webkit-animation-name': '',
							'-moz-animation-name': '',
						}).detach().appendTo('#twitter_update_list', function() {
							twitter.cycleTweets();
						});
					},
					
					'mouseover': function() {
						$(this).css({
							'-webkit-animation-play-state': 'paused',
							'-moz-animation-play-state': 'paused',
							'animation-play-state': 'paused'
						});
					},
					
					'mouseout': function() {
						$(this).css({
							'-webkit-animation-play-state': 'running',
							'-moz-animation-play-state': 'running',
							'animation-play-state': 'running'
						});
					}
				}).css({
					'-webkit-animation-name': 'twitterfade',
					'-moz-animation-name': 'twitterfade',
					'animation-name': 'twitterfade'
				}); */
			}
		}
		
		var init = function() {
			checkBrowser();
			twitter.addFollowButton();
		}
		
		init();
		
		
		
		
		
		
		
		
		
		
/* Animation bindings */

$('.sub-link').delegate("a", "click", function() {
	$('.main-link > .active').css({
		'-webkit-animation-name': '',
		'-moz-animation-name': '',
		'animation-name': ''
	});
	$('.sub-link').removeClass('active');
	$(this).parent('.sub-link').addClass('active');
});

$('.right-sidebar').delegate('.active','webkitAnimationEnd animationend', function() {
	//Reset the animation name so the next call will function properly
	$(this).css({
		'-webkit-animation-name': '',
		'-moz-animation-name': '',
		'animation-name': ''
	});
});



$('.logo').bind('webkitAnimationEnd animationend', function(e) {
	//Continue rotating counter-clockwise after the quick spin
	$(this).css({
		'-webkit-animation': 'rotate-cc 9s linear infinite',
		'-moz-animation': 'rotate-cc 9s linear infinite',
		'animation': 'rotate-cc 9s linear infinite'
	});
});
