$(function(){
	
	// binds
	$('.theme').bind('click', opentheme);
	$('.share-it').bind('click', openshare); 
	$('#learnMoreBtn1').bind('click', showRelated);
	$('#learnMoreBtn2').bind('click', showComments);
	$('#leave-comment-btn').bind('click', showLeaveComment); 
	var theResourceTitle = $('#resourceTitle').text();
	var recommendedTitle = $('#recommendedTitle').text();
	showRelated();
	checkTheme();
	
	function opentheme(e) {
		$('.browse-themes-list').fadeIn();
		$('.browse-themes-up').hide();
		$('.browse-themes-down').show();
		
		$('.theme').unbind();
		$('.theme').bind('click', closetheme);
	}
	
	function closetheme(e){
		$('.browse-themes-list').hide();
		$('.browse-themes-up').show();
		$('.browse-themes-down').hide();
		
		$('.theme').unbind();
		$('.theme').bind('click', opentheme);
	}
	
	function openshare(e) {
		$('.share-this-list').fadeIn();
		$('.share-this-up').hide();
		$('.share-this-down').show();
		
		$('.share-it').unbind();
		$('.share-it').bind('click', closeshare);
	}
	
	function closeshare(e){
		$('.share-this-list').hide();
		$('.share-this-up').show();
		$('.share-this-down').hide();
		
		$('.share-it').unbind();
		$('.share-it').bind('click', openshare);
	}
	
	function showRelated(e){
		$('#learnMoreBtn1').addClass('current');
		$('#learnMoreBtn2').removeClass('current');
		$('.recommended').fadeIn();
		$('.comments').hide();
		$('.switchLabel').text('If you liked '+theResourceTitle+', we thought you might also like '+recommendedTitle);
	}
	
	function showComments(e){
		$('#learnMoreBtn2').addClass('current');
		$('#learnMoreBtn1').removeClass('current');
		$('.comments').fadeIn();
		$('.recommended').hide();
		$('.switchLabel').text('Please give us your thoughts on '+theResourceTitle);
	}
	
	function showLeaveComment(e){
	    $('.leave-comment-container').fadeIn();
	    $('#leave-comment-btn').hide();
	}
	
	function checkTheme(){
		var isTheme = $('.browse-themes-list ul li.current').length;
		if(isTheme > 0){
			opentheme();
		}else{
			closetheme();
		}
	}
	
});


