$(document).ready(function(){
	
// hide top content
	$('#resume').hide();
	$('#details').hide();
	$('#video').hide();
	
//accordian          
	$('.resume').click(function() {
		var dets = $('#details');
		var vid = $('#video');

		if (dets.is(':visible') || (vid.is(':visible')) ) {
			$('#details').slideUp(300);
			$('#video').slideUp(300);
			$('#resume').delay(300).slideToggle(300);
		}
		else {
			$('#resume').slideToggle(300);
		}
	});
	
	$('.details').click(function() {
		var res = $('#resume');
		var vid = $('#video');

		if (res.is(':visible') || (vid.is(':visible')) ) {
			$('#resume').slideUp(300);
			$('#video').slideUp(300);
			$('#details').delay(300).slideToggle(300);
		}
		else {
			$('#details').slideToggle(300);
		}	
	});
	
	$('.about_top').click(function() {
		var res = $('#resume');
		var dets = $('#details');

		if (dets.is(':visible') || (res.is(':visible')) ) {
			$('#resume').slideUp(300);
			$('#details').slideUp(300);
			$('#video').delay(300).slideToggle(300);
		}
		else {
			$('#video').slideToggle(300);
		}	
	});

	$('a.close').click(function() {
		$('#details').slideUp(300);
		$('#resume').slideUp(300);
		$('#video').slideUp(300);
	});

	$('.twitter').click(function() {
		$('#details').slideUp(300);
		$('#resume').slideUp(300);
		$('#video').slideUp(300);
	});

	$('.contact').click(function() {
		$('#details').slideUp(300);
		$('#resume').slideUp(300);
		$('#video').slideUp(300);
	});
	
//scroll         
	$('.scroll_bottom').click(function() {
		if(this.className == 'scroll_bottom contact') {
			$('html,body').animate({
				scrollTop: $('#footer').offset().top
			}, 700, function() {
				$('.foot_block_last.contact').animate({
					'background-color': '#909090'
				}, 300, function() {
					$('.foot_block_last.contact').animate({
						'background-color': '#e2e2e2'
						}, 600)
					});
				})
		}else if(this.className == 'scroll_bottom twitter') {
			$('html,body').animate({
				scrollTop: $('#footer').offset().top
			}, 700, function() {
				$('#footer .twitter').animate({
					'background-color': '#909090'
				}, 300, function() {
					$('#footer .twitter').animate({
						'background-color': '#e2e2e2'
						}, 600)
					});
				})
			}
	});

	$('a.top').click(function() {
		$('html,body').animate({
			scrollTop: 0
		}, 700);	
	});
	
//img swap
	$(".color").fadeTo(1, 0);

	$(".color").hover(function(){
	$(this).stop().fadeTo(200, 1);		
	},function() {
	$(this).stop().fadeTo(2000, 0);
	});
	//external links
	function externalLinks() {   
		if (!document.getElementsByTagName) return;   
		var anchors = document.getElementsByTagName("a");   
		for (var i=0; i<anchors.length; i++) {   
			var anchor = anchors[i];   
			if (anchor.getAttribute("href") &&   
				anchor.getAttribute("rel") == "external")   
				anchor.target = "_blank";   
		}   
	}   
	window.onload = externalLinks;
	
//twitter
	getTwitters('tweet', { 
		id: 'twahlin', 
		count: 3, 
		enableLinks: true, 
		ignoreReplies: true, 
		clearContents: true,
		template: '"%text%" <a rel="external" href="http://twitter.com/%user_screen_name%/statuses/%id%/" class="time">%time%</a>'
	});
	
//process top bar
	(function() {
		var fadeSpeed = 200, fadeTo = 0.5, topDistance = 30;
		var topbarME = function() { $('#top_bar').fadeTo(fadeSpeed,1); }, topbarML = function() { $('#top_bar').fadeTo(fadeSpeed,fadeTo); };
		var inside = false;
		$(window).scroll(function() {
			position = $(window).scrollTop();
			if(position > topDistance && !inside) {
				topbarML();
				$('#top_bar').bind('mouseenter',topbarME);
				$('#top_bar').bind('mouseleave',topbarML);
				inside = true;
			}
			else if (position < topDistance){
				topbarME();
				$('#top_bar').unbind('mouseenter',topbarME);
				$('#top_bar').unbind('mouseleave',topbarML);
				inside = false;
			}
		});
	})();

});
