$(document).ready(function() {
	$("a.ttname").tooltip({
		bodyHandler: function() {
			return $($(this).attr("href")).html();
		},
		showURL: false,
		track: false,
		fixPNG: true,
		extraClass: "writerprofile",
		top: 15,
		left: -45
	});

	// Show quiz (requires js to function)
	$('.quiz').show();
	
	// Show "this day" on home page 
	$.getJSON($('.thisDay a.data').attr('href'), function(json) {
		if (json.year == "") return;
		$('.thisDay p').text(json.year + " - " + json.event);
		$('.thisDay').show();
	});

});

function vote(id){
	$('#votecount-' + id).load(voteLink, {id: id});
	$('#votelink-' + id).hide();
}
/* gallery prev/next function */
function onAfter(curr, next, opts) {
    var index = $(this).parent().children().index(this);
    $('#prev1')[index == 0 ? 'hide' : 'show']();
    $('#next1')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}

/* Quiz Answer */
function answerQuiz(id, pingPath){
	var checkedRadio = $('input:radio[@name=quiz-answer]:checked')[0];
	
	if(checkedRadio != undefined){
		$('#quiz2-answer-' + checkedRadio.value + '.neutral').addClass('incorrect');
		
		$('#quiz-answers-' + id).fadeOut('normal', function () {
			$(this).remove();
			$('#quiz2-answers-' + id).fadeIn('normal');
		});
		$('#quiz-link-' + id).fadeOut('normal', function () {
			$(this).remove();
			$('#quiz2-link-' + id).fadeIn('normal');
	    });
	    
	    // for log analysis...
		$.get(pingPath);
	}
}

/*************************************************************************************************************************************
 sharing with Facebook, Delicious... 
*************************************************************************************************************************************/
function getHref(){
	return encodeURIComponent(location.href);
}

function getTitle(){
	return escape(document.title);
}

/*facebook*/
function fbs_click() {
	url = 'http://www.facebook.com/sharer.php?u=' + getHref() +'&t=' + getTitle();
	window.open(url,'facebook','toolbar=0,status=0,width=626,height=436');
	return false;
}

/*reddit*/
function reds_click() {
	url = 'http://www.reddit.com/submit?url=' + getHref() + '&amp;title=' + getTitle();
	window.open(url, 'reddit','toolbar=0,status=0,width=626,height=436');
	return false;
}

/*delicious*/
function dels_click() {
	url = 'http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+ getHref() +'&amp;title='+ getTitle();
	window.open(url , 'delicious','toolbar=no,status=0,width=550,height=550');
	return false;
}
    
/*stumbleupon*/
function stum_click() {
	url = 'http://www.stumbleupon.com/submit?url='+ getHref() +'&amp;title=' + getTitle(); 
	window.open(url, 'stumbleupon','toolbar=no,status=0,width=550,height=550');
	return false;
}

$(document).ready(function() {
	$('.share').click(function() {
		$('#share-sites').css('display', 'block');
		return false;
	});
	
	$('#share-sites .close').click(function() {
		$('#share-sites').css('display', 'none');
		return false;
	});
});

/*************************************************************************************************************************************/
