// JavaScript Document

$(document).ready(function(){

// My Quizzes & MY Results Section
	if($("#quiz_detailed_data .quiz_paging a").length>0){
		$("#quiz_detailed_data .quiz_paging a").live("click", function(e){
			$("#quiz_detailed_data .quiz_paging .loadingtext").html("<strong>Loading...</strong>&nbsp;&nbsp;&nbsp;");
			var _url = $(this).attr("href");
			$("#quiz_detailed_data").load(_url);
			return false;
		});
	}
	
	
// Public Profile Section
	if($("#created_quiz .quiz_paging a").length>0){
		$("#created_quiz .quiz_paging a").live("click", function(e){
			$("#created_quiz .quiz_paging .loadingtext").html("<strong>Loading...</strong>&nbsp;&nbsp;&nbsp;");
			var _url = $(this).attr("href");
			$(".created_list").load(_url);
			return false;
		});
	}
	
    if($("#quiz_taken .quiz_paging a").length>0){
        $("#quiz_taken .quiz_paging a").live("click", function(e){
            $("#quiz_taken .quiz_paging .loadingtext").html("<strong>Loading...</strong>&nbsp;&nbsp;&nbsp;");
            var _url = $(this).attr("href");
            $(".taken_list").load(_url);
            return false;
        });
    }
    
	if($("#quiz_comment .quiz_paging a").length>0){
		$("#quiz_comment .quiz_paging a").live("click", function(e){
			$("#quiz_comment .quiz_paging .loadingtext").html("<strong>Loading...</strong>&nbsp;&nbsp;&nbsp;");
			var _url = $(this).attr("href");
			$(".commented_list").load(_url);
			return false;
		});
	}
	
	var _bio='';
	if($("#gplayer_bioajx").length>0){
		$("#gplayer_biohover").live("mouseover", function(e){
			$(this).css("background-color", "#FFE900");
		});	
		$("#gplayer_biohover").live("mouseout", function(e){
			$(this).css("background-color", "#fff");	
		});	
		
		$("#gplayer_biohover").live("click", function(e){
			_bio = $(this).text();
			$("#gplayer_bioajx").html("<input type='text' maxlength='255' value='"+_bio+"' name='update_bio' id='update_bio' style='width:300px;' /> <span id='biobtn'><input type='submit' id='btnbioupdate' value='Update' />&nbsp;<a href='#cancel' id='btn_cancelbio' style='text-decoration:underline; font-size:12px;'>cancel</a></span>");
			
			if($("#update_bio").val() == "What are you doing right now..."){
				$("#update_bio").select();	
			}
			$("#update_bio").focus();
		});
		
		$("#btnbioupdate").live("click", function(){
			$("#biobtn").html("<strong>updating...</strong>");
			$.ajax({
			  url: "/quiz-school/ajx_updatebio.php",
			  type: "POST",
			  data: ({uid: $("#bio_userid").val(), bio: $("#update_bio").val()}),
			  cache: false,
			  async: true,
			  success: function(data){
				$("#gplayer_bioajx").html("<span id='gplayer_biohover'>"+data+"</span>");
			  }
			});
		});
		
		$("#update_bio").live("keypress", function (e) {  
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
				$('#btnbioupdate').click();  
				return false;  
			} else {  
				return true;  
			}  
		});
		
		$("#btn_cancelbio").live("click", function(){
			$("#gplayer_bioajx").html("<span id='gplayer_biohover'>"+_bio+"</span>");
			return false;
		});
	}
});
