$(function(){
	$('#pop_register').livequery('click',function(event){
		window.location="/registration"
	});
	$("#pop_register").hover(function(){
		$(this).css('cursor','pointer');	
	},function(){
	$(this).css('cursor','normal');
	});
    
	
	
	$('#yelp_form').livequery('submit',function(event){
		$('#yelp-results').empty().html("<h4>Searching...</h4>");
		$.post($(this).attr('action'),$(this).serialize(),function(data){
			$('#yelp-results').empty().append(data);
		});
	return false;	
	});
	
	//alert('here')
	$tabs = $("ul#episode-menu").tabs();
	$('#episode-menu li').bind('tabsselect', function(event, ui) {
	});
	$('#chat-about-book').livequery('click',function(){
		$.scrollTo($('#chat-room'));
		return false;
	});
	$('#chat-about-book').livequery('click',function(){
		$.scrollTo($('#chat-room'));
		return false;
	});
	$('#share-it').livequery('click',function(){
		modalCall('/episodes/share/'+$(this).metadata({type:'class',name: 'params'}).url,264,520)
	});
	$('#subscribe-it').livequery('click',function(){
		window.open('http://feeds.feedburner.com/noveladventures');
	});
	$('.email-to-friend').livequery('click',function(){
		modalCall('/episodes/email/'+$(this).metadata({type:'class',name: 'params'}).value,300,500);
		return false;
	});
	
	//
	$('#comment-it').livequery('click',function(){
		    $tabs.tabs('select', 0); 
			window.setTimeout(function(){
				$.scrollTo($('#episode_comments'));
			},100);
	});
	$('.star-rating a').livequery('click',function(){
		var values = 'rating='+$(this).text();
		var p = $(this).parent().parent();
		var starvalue = $(this).text();

		for(var a=1; a<6; a++){
			if( a > starvalue){
				$('a.star-'+a).parent().addClass('noroll');
				$('a.star-'+a).attr('title','You have already rated this video');
			}else{
				$('a.star-'+a).parent().addClass('selected').addClass('');	
				$('a.star-'+a).attr('title','You have already rated this video');
			}
		}
		$.post(p.metadata('class','params').url,values,function(data){
			$('.star-rating a').expire('click');
		});
		return false;
	});
	

	initQuiz();
	

	//triggers();
});
function initQuiz() {
	$('#quiz ul li a').livequery('click',function(){
		
		submitQuiz(this); 
		$('#quiz ul li a').expire('click');
		$('#quiz ul li a').livequery('click',function(){
			return false;
		});
		return false;
	});
}
function submitQuiz(q) {
	if ($(q).parent().metadata('class','params').id !=$(q).parent().parent().metadata('class','params').id) {
		$(q).parent().addClass('incorrect');
		window.setTimeout(function(){
			//alert($(q).parent().parent().find('li').length)
			$(q).parent().parent().find('li').removeClass('incorrect');
			
			initQuiz();
		},1000);
	} else {
		
	
		$(q).parent().addClass('correct');
		var values = 'quiz_answer_id='+$(q).parent().metadata('class','params').id+'&quiz_question_id='+$(q).parent().parent().metadata('class','params').qq;
		$.post('/settings/quiz',values,function(data){
			$(q).parent().parent().parent().html('<h3>Book Club Quiz</h3><p>You\'ve answered this quiz correctly. You\'re also entered for another chance to win a Saturn adventure!<br />Watch more episodes and answer more questions to win! </p>');
		});
		

		
	}
}

function close_reg_pop(){
	$('#pop_register').remove();	
}