// JavaScript Document

$(document).ready(function(){
	
	$('.story .content .text').each(function(){
		var height = $(this).height();
		//height = (height*1)+50;
		$(this).attr('rel',height);
		$('.sociable').fadeOut();
		if(height<=90){$(this).css('height','auto');}else{$(this).css('height',90);}
	})
	
	$('.open-story').live('click' , function(){
		var rel = $(this).attr('rel');
		var height = $('#post-'+rel+' .text').attr('rel');
		var img_height = $('#post-'+rel+' .story-image .mid img').height();
		$('#post-'+rel+' .story-image .mid').animate({height:img_height},2000);
		$('#post-'+rel+' .sociable').css('visibility','visible');
		$('#post-'+rel+' .sociable').fadeIn();
		if(height>=90){
			$('#post-'+rel+' .text').animate({height:height+'px'},2000);
		}
		$(this).html('<img src="/blog/wp-content/themes/headred/images/close-story.gif" />');
		$(this).addClass('close-story');
		$(this).removeClass('open-story');
		return false;	
	})	
	
	$('.close-story').live('click' , function(){
		var rel = $(this).attr('rel');
		var height = $('#post-'+rel+' .text').attr('rel');
		$('#post-'+rel+' .story-image .mid').animate({height:'100px'},2000);
		$('#post-'+rel+' .sociable').css('visibility','hidden');
		$('#post-'+rel+' .sociable').fadeOut();
		if(height<=90){
			$('#post-'+rel+' .text').animate({height:'auto'},2000);
		}else{
			$('#post-'+rel+' .text').animate({height:'90px'},2000);
		}
		$(this).html('<img src="/blog/wp-content/themes/headred/images/open-story.gif" />');
		$(this).addClass('open-story');
		$(this).removeClass('close-story');		
		return false;	
	})	
	
	var archive_height = $('#blog-sidebar #archive .mid').height();
	$('#blog-sidebar #archive .mid').css('height','193px');
	
	$('.expand-archive').live('click' , function(){
		$('#blog-sidebar #archive .mid').stop().animate({'height':archive_height},2000)
		$(this).addClass('close-archive');
		$(this).removeClass('expand-archive');
		$(this).html('<img src="/blog/wp-content/themes/headred/images/archive-close.gif" />');
		return false;	
	})
	$('.close-archive').live('click' , function(){
		$('#blog-sidebar #archive .mid').stop().animate({'height':'193px'},2000)
		$(this).addClass('expand-archive');
		$(this).removeClass('close-archive');
		$(this).html('<img src="/blog/wp-content/themes/headred/images/archive-expand.gif" />');
		return false;	
	})
})
