
var siteUrl              = '';
var siteUrlClean         = '';
var userId               = '';
var blockDefaults        = {};
var newFriendStyles      = {};
var friendResponseStyles = {};
var defaultDialogue      = {};
var seconds              = -2;
var addingFriendId       = -1;
var controller           = '';

function run_onload(){
  //alert('document loaded');

  //begin event bindings
  $("#newAcctBttn").bind("click", new_acct_login);
  $("#loginBttn").bind("click", log_in);
  $("#logoutBttn").bind("click", log_out);
  $("#myStuffBttn").bind("click", my_stuff);
  $(".fpDeckQuiz").bind("click", go_to_link);
  $(".deckQuiz").bind("click", go_to_link);
  $(".menuLinkDiv").bind("click", go_to_link);
  $(".menuLinkDivJs").bind("click", js_menu);
  $(".quickClickLink").bind("click", quick_click);
  $("#goButton").bind("click", validate_account);
  $("#newUsername").bind("keyup", validate_username);
  $("#newPasswordOne").bind("keyup", validate_password_one);
  $("#newPasswordTwo").bind("keyup", validate_password_two);
  $("#newEmail").bind("keyup", validate_email);
  $("#newSchool").bind("keyup", show_school_results);
  $("#msgRecipient").bind("keyup", show_msg_recipients);
  $('#msgRecipient').blur(function() {
    //$('#recipientOptions').hide();
  });
  $("#schoolRadio").bind("click", school_deck_type);
  $("#miscRadio").bind("click", misc_deck_type);
  $("#beginButton").bind("click", begin_test);
  $(".formLabel").bind("mouseenter", form_instruct);
  $(".formLabel").bind("mouseleave", form_instruct_out);

  //BEGIN public deck binding
  $("#deckSearchInput").bind("keyup", display_deck_results);
  //END public deck binding
  
  $("#miscRadio").bind("click", misc_deck_type);

  //mystuff / friends bindings
  $(".friendDeny").bind("click", denyFriend);
  $(".friendAccept").bind("click", acceptFriend);
  $("#okResponse").bind("click", closeFriendResponse);

   friendResponseStyles = {
    message: $('#friendMade'),
    css: {
      border: '1px solid #aaa'
    },
    overlayCSS:  {
      backgroundColor: '#FFF',
      opacity:         0.6
    }
  }


  //form submit on enter
  bind_form_enter();

  //validate form
  $("#insertForm").validate();

  $("#newCardForm").validate({
    submitHandler: addCardAjax
  });

//start javascript timer
  timer();

//load variables out of header
  siteUrl      = $("#siteUrl").html();
  siteUrlClean = $("#siteUrlClean").html();
  userId       = $("#userId").html();
  controller   = $("#controller").html();

  //adjust page height
  $('#mainTable').height($(window).height());
  $('#containingDiv').height($("#containingTd").height());


  //set default values for block UI plugin
  blockDefaults = {
    message: get_loading_image(),
    fadeIn:  100,
    css: {
      border: '1px solid #aaa',
      color: '#777'
    },
    overlayCSS:  {
      backgroundColor: '#FFF',
      opacity:         0.5
    }
  }

  defaultDialogue = {
    message: $('#myDialogue'),
    css: {
      border: '1px solid #aaa',
      width: '325px'
    },
    overlayCSS:  {
      backgroundColor: '#FFF',
      opacity:         0.6
    }
  }

}

function bind_form_enter(code){
  $('form').bind("keypress", function(e){
    var code = (e.keyCode ? e.keyCode : e.which);
    if(code == 13) {
      if(code == undefined){
        this.submit();
      }
      else{
        eval(code);
      }
    }
  })
}

function timer(){
  seconds++;
  seconds++;
  $('#lawyer').val(seconds);
  //alert(seconds);
  if(seconds  > 30){
    
    if(controller == "mystuff") update_unread();
    seconds = 6;
  }
  setTimeout('timer()', 2000);
}

function update_unread(){
  $.post(siteUrl+'mystuff/getunreads', {}, function(data){
    var unread = data.split("::-:-::");
    var alerts = parseInt(unread[0]);
    var msgs   = parseInt(unread[1]);
    //alert("alerts: "+alerts+" messages: "+msgs);
    if(alerts > 0){
      $("#alertSpan").html(format_unread(alerts));
    }
    if(msgs > 0){
      $("#messagesSpan").html(format_unread(msgs));
    }
  })
}

function format_unread(str){
  return "("+str+")";
}

function silk_image(name){
  var url = siteUrlClean+'images/icons/'+name+'.png'
  return '<img src="'+url+'" alt="'+name+'">';
}

function bind_quiz_elements(){
  $("#cardBody").bind("mouseenter", update_instructions);
  $("#cardBody").bind("mouseleave", clear_instructions);
  $("#cardBody").toggle(show_answer, show_question);
  $("#quizNext").bind('click', show_next_card);
  $("#quizBack").bind('click', show_last_card);
  $("#quizBegin").bind("click", begin_test);
}

function new_acct_login(){
  $('#loginType').val('newAcct');
  url = $('#newAcctUrl').html();
  $('#loginForm').attr('action', url );
  $('#loginForm').submit();
}

function log_in(){
  $('#loginType').val('login');
  $('#loginForm').submit();
}

function log_out(){
  window.location=siteUrl+'login/logout/';
}

function my_stuff(){
  window.location=siteUrl+'myStuff/';
}

function go_to_link(){
  var url = $("a", this).attr('href');
  if(url != undefined){
    window.location=url;
  }
}

function go_to(url){
  window.location=url
}

function js_menu(){
  var executeCode = $(".menuJs", this).html();
  eval(executeCode);
}

function quick_click(){
  var url = $("div", this).html();
  window.location=url;
}

function instruct_error(str){
  //alert(str);
  str = '<span class="errorRed">'+str+'</span>';
  set_instruct(str);
}

function form_instruct(){
  var instructs = $(".labelInstruct", this).html();
  set_instruct(instructs)
}

function set_instruct(instructs){
  $("#formInstruct").html(instructs);
}

function form_instruct_out(){
  $("#formInstruct").html("&nbsp;");
}
/**
 *
 * Create Account Validation
 *
 */

function validate_account(){
  if( username_passed())
  {
    if(validate_password_one())
    {
      if(validate_password_two())
      {
        if(validate_email())
        {
          if(validate_firstname())
          {
            if(validate_school())
            {
              //wohoooo! we made it!
              //in here we will change the forms action attribute, which will
              //hopefully help with robots, and then submit the form via javascript.
              //users without javascript will just beo out of luck
              $('#insertForm').attr('action', siteUrl+'login/saveacct' );
              $('#insertForm').submit();
              return true;
            }
            else
            {
              instruct_error('School (4 or more characters) is Required for Students.');
              return false;
            }
          }
          else
          {
            instruct_error('You must enter your first name.');
            return false;
          }
          
        }
        else
        {
          instruct_error('Email is Not Valid');
          return false;
        }
      }
      else
      {
        instruct_error('Second Password field does not match');
        return false;
      }
    }
    else
    {
      instruct_error('First Password Field Not Valid');
      return false;
    }
  }
  else
  {
    instruct_error('Username not valid');
    return false;
  }
}

//for final validation, since the ajax was causing problems
function username_passed(){
  var val = $("#newUsername").val();
  if(val.length >= 4){
    var current_img = $("#newUsernameImg").html();
    var bad_image   = silk_image('cancel');
    if( current_img ==  bad_image ){
      return false;
    }
    else{
      $("#newUsernameImg").html(silk_image('accept'));
      return true;
    }
  }
  else{
    $("#newUsernameImg").html(silk_image('cancel'));
    return false;
  }
  
}

function validate_username(){
  var val = $("#newUsername").val();
  if(val.length >= 4){
    jQuery.post( siteUrl+'login/checkun/', {un: val}, function(rows){
      if(rows >= 1){
        $("#newUsernameImg").html(silk_image('cancel'));
        return false;
      }
      else{
        $("#newUsernameImg").html(silk_image('accept'));
        return true;
      }
    });
  }
  else{
    $("#newUsernameImg").html(silk_image('cancel'));
    return false;
  }
  return false;
}

function validate_firstname(){
  var val = $("#newFirstname").val();
  if(val.length >= 2){
    $("#newFirstnameImg").html(silk_image('accept'));
    return true;
  }
  else{
    $("#newFirstnameImg").html(silk_image('cancel'));
    return false;
  }
}

function validate_password_one(){
  var val = $("#newPasswordOne").val();
  if(val.length >= 4){
    $("#newPasswordOneImg").html(silk_image('accept'));
    return true;
  }
  else{
    $("#newPasswordOneImg").html(silk_image('cancel'));
    return false;
  }
}

function validate_password_two(){
  var val = $("#newPasswordTwo").val();
  if(val.length >= 4){
    if(val ==  $("#newPasswordOne").val()){
      $("#newPasswordTwoImg").html(silk_image('accept'));
      return true;
    }
    else{
      $("#newPasswordTwoImg").html(silk_image('cancel'));
      return false;
    }
  }
  else{
    $("#newPasswordTwoImg").html(silk_image('cancel'));
    return false;
  }
  return true;
}

function validate_email() {
  var val = $("#newEmail").val();
  if( (val.indexOf(".") > 2) && (val.indexOf("@") > 0) ) {
    $("#newEmailImg").html(silk_image('accept'));
    return true;
  }
  else{
    $("#newEmailImg").html(silk_image('cancel'));
    return false;
  }
  
}

function validate_school(){
  var val = $(".newStatusRadio:checked").val();
  if(val == 'general'){
    $("#newSchoolImg").html(silk_image('accept'));
    return true;
  }
  else{
    $('#schoolTable').css('display', 'block');
    val =  $("#newSchool").val();
    if(val.length >= 4){
      $("#newSchoolImg").html(silk_image('accept'));
      return true;
    }
    else{
      $("#newSchoolImg").html(silk_image('cancel'));
      return false;
    }
  }
}

function school_deck_type(){
  $('#schoolTable').css('display', 'block');
}

function misc_deck_type(){
  $('#schoolTable').css('display', 'none');
}


/**
 *
 * END Create Account Validation
 *
 */

function get_loading_image(){
  var img = '<img src="'+siteUrl+'images/ajaxSmall.gif" alt="loading">';
  return img;
}


function load_card(cardNum, deckNum){
  $('#quizDiv').block(blockDefaults);
  $('#quizDiv').load(siteUrl+'flash_cards/getcard/'+deckNum+'/'+cardNum+'/', function(){
    $('#quizDiv').unblock();
    bind_quiz_elements();
  });
}

function show_school_results(){
  validate_school();
  var val = $('#newSchool').val();
  $('#schoolOptions').css('display', 'block');
  $('#schoolOptions').load(siteUrl+'flash_cards/searchschool/', {'search': val}, function(){
    $(".schoolResDiv").bind("click", fill_ajax_input);
  });
}

function fill_ajax_input(){
  $('#newSchool').val($(this).text());
  $('#schoolOptions').css('display', 'none');
  if( $('#schoolChoices').html() != '' ){
    $.post(siteUrl+'mystuff/getschoolopts/', {name: $(this).text()}, function(data){
      $('#schoolChoices').html(data);
      bind_school_actions();
    });
  }
}

function show_msg_recipients(){
  var val = $('#msgRecipient').val();
  $('#recipientOptions').css('display', 'block');
  $('#recipientOptions').load(siteUrl+'mystuff/searchfriends/', {'search': val}, function(){
    $(".friendResDiv").bind("click", choose_message_recipient);
  });
}

function choose_message_recipient(){
  $('#selectedFriend').html($(this).html());
  $('#recipientOptions').css('display', 'none');
  $("#recipient").val($("#recipientId").text());
  $("#msgRecipient").val("");
}

function send_msg(){
  var msg = $('#messageTextArea').val();
  var uId =  $('#recipient').val();
  if(uId == "") my_alert("msgAlert", "No One Selected", "You must choose a recipient for the message before sending");
  else if(msg.length < 5) my_alert("contentAlert", "Nothing Written", "You must fill out the message a bit more");
  else{
    $.post(siteUrl+'mystuff/sendmessage', {message: msg, user_id: uId}, function(data){
      var message_opts = $.extend(defaultDialogue, {message: data})
      $.blockUI(message_opts);
      setTimeout('$.unblockUI();', 1500);
      setTimeout('go_to_inbox();', 1500);
    })
  }
}

function cancel_msg(){
  my_prompt("cancelMsg", "Cancel This Message?", "Do you really want to cancel sending this message and leave the page?", "go_to_inbox();");
}

function go_to_inbox(){
  window.location = siteUrl+'mystuff/messages';
}

function begin_test(){
  var deckId     = $('#thisDeck').html();
  var cardNumber = 1;
  load_card(cardNumber, deckId);
}

function show_next_card(){
  var deckId     = $('#thisDeck').html();
  var cardNumber = $('#thisCard').html();
  cardNumber++;
  load_card(cardNumber, deckId);
}

function show_last_card(){
  var deckId     = $('#thisDeck').html();
  var cardNumber = $('#thisCard').html();
  cardNumber--;
  load_card(cardNumber, deckId);
}

function shuffle_deck(){
  var deckId     = $('#thisDeck').html()
  $.post(siteUrl+'flash_cards/shuffle/'+deckId, {}, function(data){
    if(data == 1) my_alert("shuffle", "Success", "Deck Shuffled.");
    else my_alert("shuffle", "Error", "Error Shuffling deck");
    begin_test();
  });
  //alert(deckId);
}

function update_instructions(){
  $("#quizInstructions").html('Click to flip the card.');
}

function clear_instructions(){
  $("#quizInstructions").html('&nbsp;');
}

function not_implemented(){
  my_alert('notImp', 'Not Working', 'Sorry, but we havent added this feature yet. Check back soon.')
}

function addCardAjax(form){
  var data = {};
  $('#newCardForm input, #newCardForm textarea').each(function(){
    //alert(this.name+'=>'+$(this).val());
    data[this.name] = $(this).val();
  });
  $.post(siteUrl+"flash_cards/insertcards/", data, function(returned){
    $('#cardTot').html(returned);
    $('#totalCardsInput').val(returned);
  })
  $.post(siteUrl+"flash_cards/listcards/", data, function(returned){
    $('#currentCardsAdded').html(returned);
  })
  form.reset();
}

function show_answer(){
  $("#cardBody").html($('#answer').html());
}

function show_question(){
  $("#cardBody").html($('#question').html());
}

/*
 * BEGIN HOME PAGE functions
 */
function toggleNews(){
  var linkText = $('#newsToggler').html();
  var fullNews = $('#fullNews').html();
  var partNews = $('#partNews').html();
  if(linkText == 'Read Full Text'){
    $('#msgTd').html( fullNews );
    $('#newsToggler').html('Hide Full Text');
  }
  else{
    $('#msgTd').html( partNews );
    $('#newsToggler').html('Read Full Text');
  }
}
/*
 * END HOME PAGE functions
 */

/*
 *My stuff functions
 */

function showAlerts(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/alerts/out/'+t+'/', bind_alert_actions);
}

function bind_alert_actions(){
  $(".friendDeny").bind("click", denyFriend);
  $(".friendAccept").bind("click", acceptFriend);
  $("#okResponse").bind("click", closeFriendResponse);
  
  friendResponseStyles = {
    message: $('#friendMade'),
    css: {
      border: '1px solid #aaa'
    },
    overlayCSS:  {
      backgroundColor: '#FFF',
      opacity:         0.6
    }
  }
}

function denyFriend(){
  var friend_id = $('span', this).html();
  friendResponse('deny', friend_id);
}

function acceptFriend(){
  var friend_id = $('span', this).html();
  friendResponse('accept', friend_id);
}

function friendResponse(action, friend_id){
  $.post(siteUrl+'mystuff/friendrespond', {action: action, friend_id: friend_id }, function(data){
    $('#friendResponse').html(data);
    $.blockUI(friendResponseStyles);
  });
}

function closeFriendResponse(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/alerts/out/'+t+'/', bind_alert_actions);
  $.unblockUI();
}

function showMyDecks(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/decks/out/'+t+'/', bind_deck_actions);
}

function tagDeck(deckId){
  var body = '<form method="post" action="'+siteUrl+'flash_cards/tagdeck">'+
    '<input type="hidden" name="deckId" id="tagDeckId" value="'+deckId+'">'+
    'Type the Tag: <input type="text"  id="tagText" name="deckId" value="">'+
    '</form><br />';
  my_popup('tagForm', 'Tag This Deck', body, 'submit_tag();', 'Tag')
}

function submit_tag(){
  deckId  = $('#tagDeckId').val();
  tagText = $('#tagText').val();
  $.post(siteUrl+'flash_cards/tagdeck/', {deckId: deckId, tagText: tagText}, function(){
    $("#tagsDiv").load(siteUrl+'flash_cards/echo_tags/'+deckId);
    $.unblockUI();
  })
}

function commentDeck(deckId){
  if(userId >= 1){
    var body = '<form method="post" action="'+siteUrl+'flash_cards/addcomment">'+
    '<input type="hidden" name="deckId" id="commentDeckId" value="'+deckId+'">'+
    'Add your Comment:<br /> <textarea style="width:100%" type="text"  id="commentText" name="commentText" >'+
    '</textarea></form><br />';
    my_popup('commentForm', 'Comment', body, 'submitComment();', 'Submit')
    bind_form_enter('submitComment();');
  }
  else{
    my_alert('commentForm', 'Must Be Logged In', 'You have to be logged in to comment.')
  }
  
}

function submitComment(){
  var deckId      = $('#commentDeckId').val();
  var commentText = $('#commentText').val();
  $.post(siteUrl+'flash_cards/addcomment/', {deckId: deckId, commentText: commentText, userId: userId}, function(data){
    $("#commentContain").load(siteUrl+'flash_cards/echo_cmmnts/'+deckId);
    $.unblockUI();
  })
}

function vote(vote, deckId){
  if(userId >= 1){
    $("#votesSpan").load(siteUrl+'flash_cards/vote/'+deckId+'/'+vote);
  }
  else{
    my_alert('voteForm', 'Must Be Logged In', 'You have to be logged in to vote.')
  }

}

function bind_deck_actions(){
  $('.deckHead').corner("top");
  $(".deckQuiz").bind("click", go_to_link);
}

function showMyInfo(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/info/out/'+t+'/', bind_info_actions);
}

function bind_info_actions(){
  $('.showFriends').bind("click",showFriends);
  $('.showEditSchool').bind("click",showEditSchool);
}

function showUsers(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/users/out/'+t+'/', bind_user_actions);
}

function showEditSchool(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/editschool/out/'+t+'/', bind_school_actions);
}
/*
 * Function:     my_popup
 * Description:  Creates a more general and customizeable popup
 * Params:
 *      id - The id of the popup
 *   title - The title to display in the popup
 *    body - the html/body content in the popup
 *     yes - a string of javascript to execute if yes is clicked.
 * yes_txt - the text of the button doing action
 *  no_txt - the text of the button to close box
 */
function my_popup(id, title, body, yes, yes_txt, no_txt){
  if(no_txt == '' || no_txt == null || no_txt == undefined ) no_txt = 'Cancel';
  var html = '<div id="'+id+'" class="myPrompt hide"><span class="myPromptTitle">'+
              title+'</span><hr /><span class="myPromptText">'+
              body+'</span><div class="myPromptButtonDiv">';
  if(yes != false){
      html += '<button id="'+id+'yes">'+yes_txt+'</button>';
  }
      html += '<button id="'+id+'cancel">'+no_txt+'</button>'+
              '</div></div>';
  $('#headDiv').html(html);
  $("#"+id+"cancel").bind("click", function(){
    $.unblockUI();
  });
  $("#"+id+"yes").bind("click", function(){
    eval(yes);
  });
  var message_opts = $.extend(defaultDialogue, {message: $('#'+id)})
  $.blockUI(message_opts);
}
/*
 * Function:     my_prompt
 * Description:  Creates a prompt before executing an action
 * Params:
 *      id - The id of the prompt
 *   title - The title to display in the prompt
 *    text - the text or question to display
 *     yes - a string of javascript to execute if yes is clicked.
 */
function my_prompt(id, title, text, yes){
  var html = '<div id="'+id+'" class="myPrompt hide"><span class="myPromptTitle">'+
              title+'</span><hr /><span class="myPromptText">'+
              text+'</span><div class="myPromptButtonDiv"><button id="'+
              id+'yes">Yes</button><button id="'+
              id+'cancel">Cancel</button></div></div>';
  $('#headDiv').html(html);
  $("#"+id+"cancel").bind("click", function(){
    $.unblockUI();
  });
  $("#"+id+"yes").bind("click", function(){
    eval(yes);
  });
  var message_opts = $.extend(defaultDialogue, {message: $('#'+id)})
  $.blockUI(message_opts);
}

/*
 * Function:     my_alert
 * Description:  Creates nicer looking alert than the browser
 * Params:
 *      id - The id of the alert div
 *   title - The title to display in the alert
 *    body - the html/body content in the alert
 */
function my_alert(id, title, body){
  my_popup(id, title, body, false, false, 'Ok');
}

function bind_school_actions(){
  $("#newSchool").bind("keyup", show_school_results);
  $("#updateSchoolBttn").bind("click", submit_update_school);
  $("#addClassLink").bind("click", function(){
    $("#addClassDiv").toggle();
  });
  $("#addClass").bind("click", add_class);
  $('#myClasses').load(siteUrl+'/mystuff/listclasses', function(){
    $(".deleteClass").bind("click", delete_class);
  });
}

function delete_class(){
  var my_class = $('.myClassId', this).html();
  my_prompt('deltePrompt', 'Really Delete?', 'Are you sure you want to delete this class from your class list?', 'do_class_delete("'+my_class+'");');
}

function do_class_delete(my_class){
  $.post(siteUrl+'mystuff/removeclass/', {my_class: my_class}, function(){
    $('#myClasses').load(siteUrl+'/mystuff/listclasses', function(){
      $(".deleteClass").bind("click", delete_class);
    });
    $.unblockUI();
  })
  
}

function delete_deck(deck_id){
  my_prompt('deltePrompt', 'Really Delete?', 'Are you sure you want to delete this deck from the site permanently?', 'do_deck_delete("'+deck_id+'");');
}

function do_deck_delete(deck_id){
  $.unblockUI();
  $.post(siteUrl+'flash_cards/deletedeck/', {deck_id: deck_id}, function(data){
    if(data == 1){
      my_alert("deleteSuccess", "Success!", "Deck was Successfully Deleted!");
    }
    else{
      my_alert("deleteSuccess", "Error.", "Deck was not Successfully Deleted :-(");
    }
  })
}

function add_class(){
  var className = $('#className').val();
  var book      = $('#book').val();
  $.post(siteUrl+'mystuff/insertclass/', {name: className, book: book}, function(data){
    $('#myClasses').load(siteUrl+'/mystuff/listclasses', function(){
      $(".deleteClass").bind("click", delete_class);
      $('#className').val("");
    });
  })
}

function submit_update_school(){
  var val = $('.schoolRadio:checked').val();
  var uId = $('#uId').val();
  if(val != '' && val != undefined && val != null){
    $.post(siteUrl+'login/updateschool/', {school: val, user_id: uId}, function(){
      window.location = siteUrl+'mystuff/me/';
    });
  }
  else{
    instruct_error('You must choose a school.');
  }

}

function showFriends(){
  d = new Date();
  var t = d.getSeconds()+d.getMilliseconds();
  $('.rightColumn').load(siteUrl+'mystuff/friends/out/'+t+'/', bind_friend_actions);
}

function bind_friend_actions(){
  $('.messageLink').bind("click", message_dialogue);
  $('#cancelMsg').bind("click",   cancel_msg);
  $('#sendMsg').bind("click",     send_msg);
}

function bind_user_actions(){
  $(".newFriendLink").bind("click", promptFriend);
  $("#yesFriend").bind("click", addFriend);
  $("#noFriend").bind("click", dontAddFriend);

  newFriendStyles = {
    message: $('#friendPrompt'),
    css: {
      border: '1px solid #aaa'
    },
    overlayCSS:  {
      backgroundColor: '#FFF',
      opacity:         0.6
    }
  }
}

function promptFriend(){
  addingFriendId = $('.friendId', this).html();
  $.blockUI(newFriendStyles);
}

function addFriend(){
  var temp = addingFriendId;
  $.post(siteUrl+'mystuff/addfriend', {friend_id: addingFriendId}, function(data){
    $.unblockUI();
    $('#messageDiv').html(data);
    $('#messageDiv').show();
    setTimeout('$("#messageDiv").hide("slow")', 2000);
    var linkSelector = '#friendLink'+temp;
    $(linkSelector).hide("slow");
  })
  addingFriendId = -1;
}

function dontAddFriend(){
  addingFriendId = -1;
  $.unblockUI();
  return false;
}

 /*
 * End my stuff functions
 */


/*
 * BEGIN Public Deck functions
 */
function display_deck_results(){
  var query = $("#deckSearchInput").val();
  $.post( siteUrl+'flash_cards/search_decks/', {search: query}, function(data){
      if(data != ""){
        $("#deckResultDiv").html(data);
        return true;
      }
      else{
        $("#deckResultDiv").html("<span class=\"plainSpanMed\">Error With Query...</span>");
        return false;
      }
    });
}


function print_deck(deckId){
  window.open(siteUrl+'flash_cards/printdeck/'+deckId, "printDeck");
}
/*
 * END Public Deck functions
 */

