$(document).ready(function()
{
// user vars
var onload_auth;
var association_id;
var comment_type;
var tmp_this;
var id;
var login_pulled;
//move to top on click
$("a.to_top").click(function()
{
$('html, body').animate({scrollTop:0}, 'slow')
});
//show link_info data on click
$("a.link_info").click(function()
{
$(this).next().next("div.hide").toggle(300);
});
$('img#remove_new_here').click(function()
{
$(this).parent().parent().fadeOut(300);
});
onload_auth = $("input[name='onload_auth']#onload_auth").val();
if(onload_auth)
{
$("input[name='author']").val("");
$("input[name='from']").val("your name");
$("div.comment_form").children("div.message").hide();
$("div.comment_form").children("form.form_add_comment").show();
$("div#my_account").show();
$("div#register").hide();
$("div#login").hide();
bind_form_my_account();
}
else
{
$("div.comment_form").children("div.message").show();
$("div.comment_form").children("form.form_add_comment").hide();
}
if(onload_auth<3)
{
// enable the admin stylesheet
document.styleSheets[4].disabled = false;
}
else
{
// disable the admin stylesheet
document.styleSheets[4].disabled = true;
}
editor_tools();
// login jQuery pulldown
$("#btn_pulldown").click(function(){
$("div#panel").animate({
height: "310px"
})
.animate({
height: "275px"
}, "fast");
$("div.panel_button").toggle();
login_pulled = true;
});
$("#hide_button").click(function(){
$("div#panel").animate({
height: "310px"
})
.animate({
height: "275px"
}, "fast");
$("div.panel_button").toggle();
});
$("div#hide_button").click(function(){
$("div#panel").animate({
height: "0px"
}, "fast");
login_pulled = false;
});
// bind 'form_register' and provide a callback function
$('form#form_register').ajaxForm({
target: '#register_result',
success: function() {
$('#register_result').fadeIn(300,function()
{
$('#register_result').fadeOut(2000,function()
{
var auth;
var full_name;
var nickname;
id = "";
id = $("input[name='register_id']#register_id").val();
if(id)
{
//hide the login/register forms
$("div#login").fadeOut(300);
$("div#register").fadeOut(300,function()
{
//show the account form
$.get("index.php",{'ajax_form_my_account':id},
function(form_my_account)
{
//replace the my account div with the updated form content
$("div#my_account").html(form_my_account);
$("div#my_account").fadeIn(300);
// bind 'form_my_account' and provide a callback function
bind_form_my_account();
jQuery('.btn_facebox_change_img').facebox();
//recall functions that are unable to operate after new DOM element is added
change_to_pw();
clear_on_focus();
}
);
});
$('#btn_pulldown').html("
My Account");
// change page data to reflect logged-in status
$("input[name='author']").val(id);
$("input[name='from']").val(full_name);
$(".comment_form.message").hide();
$("div.comment_form").children("div.message").hide();
$("div.comment_form").children("form.form_add_comment").show();
if(auth<3)
{
// enable the admin stylesheet
document.styleSheets[4].disabled = false;
}
}
});
});
}
});
// bind 'form_login' and provide a callback function
$('form#form_login').ajaxForm({
target: '#login_result',
success: function() {
$('#login_result').fadeIn(300,function()
{
$('#login_result').fadeOut(2000,function()
{
id = "";
id = $("input[name='login_id']#login_id").val();
var auth = $("input[name='auth']#auth").val();
var full_name = $("input[name='full_name']#full_name").val();
var nickname = $("input[name='nickname']#nickname").val();
if(id)
{
//hide the login/register forms
$("div#login").fadeOut(300);
$("div#register").fadeOut(300,function()
{
//show the account form
$.get("index.php",{'ajax_form_my_account':id},
function(form_my_account)
{
//replace the my account div with the updated form content
$("div#my_account").html(form_my_account);
$("div#my_account").fadeIn(300);
// bind 'form_my_account' and provide a callback function
bind_form_my_account();
jQuery('.btn_facebox_change_img').facebox();
//recall functions that are unable to operate after new DOM element is added
change_to_pw();
clear_on_focus();
}
);
});
$('#btn_pulldown').html("
My Account");
// change page data to reflect logged-in status
$("input[name='author']").val(id);
$("input[name='from']").val(full_name);
$("div.comment_form").children("div.message").hide();
$("div.comment_form").children("form.form_add_comment").show();
if(auth<3)
{
// enable the admin stylesheet
document.styleSheets[4].disabled = false;
}
}
});
});
}
});
// bind 'form_contact' and provide a callback function
$('form#form_contact').ajaxForm({
target: '#contact_result',
success: function()
{
}
});
// bind 'form_add_comment' and provide a callback function
$('form.form_add_comment').ajaxForm(function()
{
$.get("index.php",{'ajax_comment_count':association_id, 'ajax_show_comments_type':comment_type},
function(comment_count)
{
$(tmp_this).prev("span.show_comments").html("
" + comment_count + " comments");
}
);
});
// bind 'form_share_this' and provide a callback function
$('form.form_share_this').ajaxForm({
success: function(responseText)
{
var to_email = $(tmp_this).parents().siblings("input[name='to_email']").val();
$(tmp_this).parents().siblings("span.share_this").html(responseText);
$(tmp_this).parents().siblings("span.share_this").fadeOut(2000,function()
{
$(tmp_this).parents().siblings("span.share_this").html("
share this");
$(tmp_this).parents().siblings("span.share_this").fadeIn(300);
});
}
});
$("button#btn_logout").live('click', function()
{
$.get("index.php",{'ajax_logout':'1'},
function()
{
// revert the My Account link to login/register
$("#btn_pulldown").hide();
$("#btn_pulldown").html("
Login or Register");
$("#btn_pulldown").fadeIn(300);
//change page data to reflect logout
onload_auth = undefined;
id = undefined;
// disable the admin stylesheet
document.styleSheets[4].disabled = true;
$('.editor_recover').remove();
$("div.comment_form").children("div.message").show();
$("div.comment_form").children("form.form_add_comment").hide();
$("div#my_account").fadeOut(300,function()
{
$("div#register").fadeIn(300);
$("div#login").fadeIn(300);
});
//reset the forms
$("form.form_add_comment").each(function()
{
this.reset();
});
$("form.form_share_this").each(function()
{
this.reset();
});
}
);
});
clear_on_focus();
//change class="change_to_pw" to revert the type to password instead of text
change_to_pw();
// when "read more" is clicked, hide "read more", show the rest of the article, and add "collapse" option
$(".read_more").click(function()
{
$(this).parent().toggle();
$(this).parent().next().fadeIn(300);
});
$(".collapse").click(function()
{
$(this).parent().toggle();
$(this).parent().prev().fadeIn(300);
});
// social share
$("span.share_this").click(function()
{
$(this).hide();
$(this).siblings("span.add_comment").fadeIn(300);
$(this).siblings("span.show_comments").fadeIn(300);
$(this).siblings("div.comment_form").hide();
$(this).siblings("div.comments").hide();
$(this).siblings("div.share_form").fadeIn(300);
});
$("span.add_comment").click(function()
{
$(this).hide();
$(this).siblings("span.share_this").fadeIn(300);
$(this).siblings("span.show_comments").fadeIn(300);
$(this).siblings("div.share_form").hide();
$(this).siblings("div.comments").hide();
$(this).siblings("div.comment_form").fadeIn(300);
comment_type = $(this).siblings("div.comment_form").children("form.form_add_comment").children("input[name='type']").val();
association_id = $(this).siblings("div.comment_form").children("form.form_add_comment").children("input[name='association_id']").val();
tmp_this = this;
});
$("span.show_comments").click(function()
{
$(this).hide();
$(this).siblings("span.add_comment").fadeIn(300);
$(this).siblings("span.share_this").fadeIn(300);
$(this).siblings("div.share_form").hide();
$(this).siblings("div.comment_form").hide();
comment_type = $(this).siblings("div.comment_form").children("form.form_add_comment").children("input[name='type']").val();
association_id = $(this).siblings("div.comment_form").children("form.form_add_comment").children("input[name='association_id']").val();
tmp_this = this;
$.get("index.php",{'ajax_show_comments':association_id, 'ajax_show_comments_type':comment_type},
function(comments)
{
$(tmp_this).siblings("div.comments").children("div.comment_data").html(comments);
jQuery('.comments_facebox').facebox();
}
);
$(this).siblings("div.comments").fadeIn(300);
});
$("button.negative.comment").click(function()
{
$(this).parents("div.hide").fadeOut(100);
$("span.add_comment").show();
});
$("button.positive.comment").click(function()
{
$(this).parents("div.hide").fadeOut(100);
$("span.add_comment").show();
$(tmp_this).prev("span.show_comments").html
(
"
comments"
);
});
$("button.negative.share").click(function()
{
$(this).parents("div.hide").fadeOut(100);
$("span.share_this").show();
});
$("button.positive.share").click(function()
{
$(this).parents("div.hide").fadeOut(100);
$(this).parents().siblings("span.share_this").html("
sharing...");
$(this).parents().siblings("span.share_this").show();
tmp_this = this;
});
$(".collapse_comments").click(function()
{
$(this).parent(".hide").fadeOut(100);
$("span.show_comments").show();
});
$("div.buttons button").live('click', function()
{
$(this).ajaxStart(function()
{
//when all page ajax functions start, do this:
if(jQuery("img", this).attr("src") != "images/ajax_loader_green.gif")
{
jQuery("img", this).data('prev_img',jQuery("img", this).attr("src"));
}
jQuery("img", this).attr("src","images/ajax_loader_green.gif");
});
$(this).ajaxComplete(function()
{
//when all page ajax functions stop, do this:
jQuery("img", this).attr("src",jQuery("img", this).data('prev_img'));
$(this).unbind("ajaxStart");
$(this).unbind("ajaxComplete");
});
});
jQuery('.btn_facebox').facebox();
jQuery('.btn_facebox_change_img').facebox();
$(document).bind('reveal.facebox', function() {
clear_on_focus();
bind_form_post_dream();
bind_form_share_dreams();
bind_form_fulfill_dream();
bind_form_change_user_img();
jQuery('.2nd_facebox').facebox();
});
$('a.facebox_login_required').click(function()
{
if(!onload_auth && !id)
{
$('html, body').animate({scrollTop:0}, 'slow', function()
{
if(!login_pulled)
{
$("div#panel").animate({
height: "310px"
})
.animate({
height: "275px"
}, "fast", function()
{
});
$("div.panel_button").toggle();
login_pulled = true;
}
$("div#login_required").fadeIn(2000,function()
{
$(this).fadeOut(4000); // change the login panel area to indicate the user must login to continue
});
});
}
else
{
var rel = $(this).attr("rel");
jQuery.facebox({ ajax: rel });
}
});
});
//these jquery functions exist because jquery is unable to see new DOM elements added after initial load
//these functions are called after new DOM elements are added
//live(); does not currently support important interactions like focus, blur, etc
function add_tinymce()
{
$('textarea.tinymce').tinymce(
{
// Location of TinyMCE script
script_url : 'js/tiny_mce/tiny_mce_gzip.js',
// General options
theme : "advanced",
skin : "thebigreason",
disk_cache : true,
debug : false,
plugins : "safari,advimage,advlink,iespell,inlinepopups,media,contextmenu,paste,fullscreen,visualchars,nonbreaking,xhtmlxtras",
// Theme options
theme_advanced_buttons1 : "formatselect,bold,italic,underline,strikethrough,|,bullist,numlist,blockquote,|,link,media,charmap,pasteword,code,fullscreen",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js"
});
}
function editor_tools()
{
// edit featured scholarship title
$('h1.editor_edit img.edit_this_featured_scholarship').live("click",function()
{
//hide other edits in process
$('.editor_edit:hidden').toggle();
$('.editor_edit:visible').prev('.edit_container').remove();
//title edit
var parent_id = $(this).parent().parent().attr('id');
parent_id = parent_id.split("id_");
var title = $(this).parent().html();
title = title.split("