$(function(){

	var stack = {
					'delay': 250,
					'actions': [],
					'run': function() {
						if (stack.actions.length) {
							stack.actions.shift()();
							setTimeout(stack.run, stack.delay);
						}
					}

				};

	$('#navigation-submenu li').each(function(){
		$(this).css('opacity', 0);
		var that = this;
		stack.actions.push(function(){
				$(that).animate({marginTop:'-12px',opacity:1.0}, 200, 'easeOutCubic');
				});
		});



	$('#navigation-submenu').css('width', 'auto').fadeIn('slow', function(){
		stack.run();
	});
	
	
	
	$('div.fp-items').cycle({fx:'scrollRight', speed:'slow', timeout: 8000, next:'a.next', prev: 'a.prev',slideExpr: $('.slide'), cleartypeNoBg: true});
	$('a.port').hover(function(){
		$(this).fadeTo(200, 0.5);
	}, function(){
		$(this).fadeTo(200, 1);
	});
	
	$('#port-disp').hover(function(){
		$('.port-title-fp').append('<div class = "port-title-over"><a href = "/portfolio">See the entire portfolio</a></div>');
	}, function(){
		$('.port-title-fp').find('.port-title-over').remove();
	});
	$('.blog-previews').hover(function(){
		$('.blog-title-fp').append('<div class = "blog-title-over"><a href = "/blog">See the full blog</a></div>');
	}, function(){
		$('.blog-title-fp').find('.blog-title-over').remove();
	});
	
	$('#twitter').hover(function(){
		$('.twit-title-fp').append('<div class = "twit-title-over"><a href = "http://www.twitter.com/mokargas">See more tweets</a></div>');
	}, function(){
		$('.twit-title-fp').find('.twit-title-over').remove();
	});
	
	$('#intro-text a.text').click(function(){
		$(this).parent().animate({marginLeft:'700px',opacity:0},500,'easeOutCubic',function(){
			$(this).css('display', 'none');
			window.location = $(this).attr(src);

		});
	});

	$('#twitter li:last').addClass('last');
	$('#twitter li span.field-content').each(function(){
		//store initial data
		$(this).data('oh', $(this).height());
		$(this).data('tweet', $(this).html());
		//console.log($(this).data('tweet').length);
		if($(this).data('tweet').length > 60){
		//console.log($(this).find('a').length);
			if($(this).find('a').length >= 1){
				//Case has links
	
				var no_links = $(this).clone();
				//contains no links
				no_links.find('a').remove();
			
				if(no_links.html().length > 40){
				//	console.log('true');
					//set to no links html
					//console.log(no_links.html().substr(0,40) + '<a href = "#">...</a>');
					var new_str = no_links.html().substr(0,50) + '<a class = "r" href = "#">...</a>';
					$(this).data('ns', new_str);
					$(this).html(new_str);
				}
			} else {
				//remove chars after 60th, add ellipses 
				var new_text = $(this).clone();
				//console.log('NEW TEXT' + new_text.html().substr(0,40));
				new_text.html().substr(0,40) + '<a class = "r" href = "#">...</a>';
				$(this).html(new_text);
				$(this).data('ns', new_text);

			}
		//case doesn't have links
		}
		
		//need case where text exceeds 80 characters...need to wrap text and remove links accordingly 
		$(this).data('h', $(this).height());
	});
	
	/*
	$('#twitter li').hover(function(){	
		$(this).addClass('socnet-over');
		if($(this).find('span.field-content').data('ns')){
			z =  $(this).find('span.field-content').data('oh');
			$(this).find('span.field-content').html($(this).find('span.field-content').data('tweet')).show();
		}
	}, function(){
		$(this).removeClass('socnet-over');
		
		if($(this).find('span.field-content').data('ns')){
			var v =  $(this).find('span.field-content').data('h');
			$(this ).find('span.field-content').html($(this).find('span.field-content').data('ns')).hide();

		}
	});
	*/

});
