$(document).ready(function() {

	// display the nav drop-down menus
	$('.drop-down-menu ul li').hover(
		function(){
			$(this).find('.drop-down').show();
			$(this).find('a:eq(0)').addClass('hover');
		},
		function(){
			$(this).find('.drop-down').hide();
			$(this).find('a:eq(0)').removeClass('hover');
		}
	);	
	
	// change the text size
	$('.decrease-size').click(function(){
		set_size('.story-text', 'minus');
		return false;
	});
	$('.increase-size').click(function(){
		set_size('.story-text', 'plus');
		return false;
	});
	
	$('.tabs a').click(function(){
		var id = $(this).attr('href');
		var li = $(this).parent();
		var ul = li.parent();
		var container = ul.parent().parent();
		
		var z = ul.find('li').length + 1;
		var i = z;
		ul.find('li').each(function(){
			$(this).css({ 'z-index' : i });
			i--;
		});
		
		ul.find('a').removeClass('active');
		
		li.css({ 'z-index' : z+1 });
		$(this).addClass('active');
		
		
		container.find('.tab').removeClass('tab-active');
		$(id).addClass('tab-active');
		
		return false;
		
	});

	// for closing floating divs
	$('.close').click(function(){
		$(this).parents('#newsletter-popup').hide('fast');
		$(this).parents('#login-popup').hide('fast');
	});

	// Share This functionality
	if(typeof(SHARETHIS) != "undefined"){
		var sharethisobject = SHARETHIS.addEntry({
		title:'share',
		summary: 'Sharing is good for the soul.'},
		{button:false});
	
		//Tie customized button to ShareThis button functionality.
		$('.sharethis').each(function(i){sharethisobject.attachButton(this);})
	}

	// show the login box
	$('.login-link').click(function(){
		$('#login-popup').show('fast');
		return false;
	});

	// show the newsletter box
	$('.newsletter-link').click(function(){
		 $(this).parent().append( $('#newsletter-popup') );
		$('#newsletter-popup').show('fast');
		return false;
	});

	// show the comment form
	$('.btn-leave-comment').click(function(){
		$('.comment-form').show('fast');
		$(this).hide('fast');
		return false;
	});


});

function set_size( el, what ){
	var element = $(el);
	var max = 20;
	var min = 8;
	
	var size = parseInt(element.css('font-size').replace('px', ''));

	if( what == 'plus' && size < max) {size++;}else if( what == 'minus' && size > min ) {size--;}
	
	element.css({ 'font-size' : size+'px', 'line-height': (size + 6)+'px' });
	
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

