$(document).ready(function(){$("body").data("is_index_page",true);position_elements(true,"#words_container");$(window).resize(function(){position_elements(false,"#words_container");});var img=$("<img></img>");img.attr("src","/includes/images/front/index/submit_button_over.png").appendTo("#preload");$("#preload").hide();$("#logo").click(function(){window.location="/";});$("#word_textbox :input").attr("original_width",$("#word_textbox :input").css("width"));$("#definition_textbox :input").attr("original_height",$("#definition_textbox :input").css("height"));$("#definition_textbox :input").attr("original_width",$("#definition_textbox :input").css("width"));$(".field").corner();$("#usage_textbox :input").elastic().height(60);$("#definition_textbox :input").elastic().height(25);$("#main_message").corner();$("#main_message .close_button").click(function(){$.put("/index.php",{action:"hide_main_message"},null,null);$(this).parent().fadeOut("slow");});$(".vote_links a").live("click",function(){var js_word_id=$(this).attr("id").replace(/(up|down)_/,"");var js_vote_direction=RegExp.$1;$.put("/index.php",{action:"vote",word_id:js_word_id,vote_direction:js_vote_direction},this,function(call){if(call.response=="success"){var word_div=$("#word_"+js_word_id);var original_font_size=word_div.css("fontSize");$("#word_info, #word_pointer").hide().appendTo("body");word_div.replaceWith(call.word_html);var word_div=$("#word_"+js_word_id);var bigger_font_size=word_div.css("fontSize");word_div.css("fontSize",original_font_size);word_div.stop().animate({fontSize:bigger_font_size},"slow");apply_tooltip();}else if(call.response=="login_required"){load_login_register(null,null,"Casting Vote",function(){$(".vote_links a[id='"+js_vote_direction+"_"+js_word_id+"']").click();});}else if(call.response=="err"){cloud_flash(call.err,3000);}});});$("#more_comments_button").live("click",function(){document.location=$("#word_"+$("#word_info .word_id").html()).parent("a").attr("href")+"#comments";});$(".comment_link").live("click",function(){$("#word_info").attr("comment_on","comment_on");$("#word_pointer").hide();comments_height=$(window).height()-$("#word_info").height()-$("#comment_form").height()-30;if(comments_height<=50){comments_height=200;}
load_facebook(function(){$(".comments").html('<fb:comments xid="word_'+$("#word_info .word_id").html()+'" numposts="1" width="380" publish_feed="true" returnurl="http://cloudley.com'+$("#word_"+$("#word_info .word_id").html()).parent("a").attr("href")+'"></fb:comments>');})
$("#main_message").fadeOut("slow");$(".comments").show().animate({height:comments_height},"normal");$("#word_info").animate({height:$(window).height()-50,width:"400px",top:10,left:$(window).width()/2-200},"normal",function(){$("#close_comment").fadeIn("normal");});$(".comment_link").hide();$("#comment_textbox").corner("5px");apply_form_titles();});$("#close_comment").live("click",function(){$("#word_info").removeAttr("comment_on").fadeOut("normal",function(){$(this).width(315);$("#main_message").fadeIn("slow");});});$("#comment_button").live("click",function(){var params={"action":"create_comment","word_id":$(".word_id").html(),"comment":$(this).parent().find("[name='comment']").validateLabel()}
$.put("/words.php",params,this,function(call){if(call.response=="success"){$("[name='comment']").val($("[name='comment']").attr("original_value"));if($(".comments").attr("no_comments")!=undefined){$(".comments").html("");$(".comments").removeAttr("no_comments");}
$(".comments").prepend(call.comment_html);}else if(call.response=="login_required"){load_login_register(null,null,"Submitting Comment",function(){$("#comment_button").click();});}else if(call.response="err"){cloud_flash(call.err,3000);}});});$("#submit_word_button").hover(function(){$(this).addClass("submit_button_over");},function(){$(this).removeClass("submit_button_over");}).click(function(){submit_word();});$("#close_submit_cloud").click(close_submit_cloud);$(".close_error_cloud").live("click",close_cloud_flash);$("#part_of_speech li").click(function(){var pos=$("[name='part_of_speech']");if($(this).attr("selected")==undefined){$(this).addClass("part_of_speech_selected").attr("selected","selected");var pos_val=pos.val()+$(this).attr("id")+", ";}else{$(this).removeClass("part_of_speech_selected").removeAttr("selected");var pos_val=pos.val().replace($(this).attr("id")+", ","");}
pos.val(pos_val);});$(".actual_word_link").live("click",function(){$(".actual_word_definition_holder").remove();$("body").append("<div class='actual_word_definition_holder'>"+$(".actual_word_definition").html()+"</div>");$(".actual_word_definition_holder").modal(message_box_options);});$("#definition_textbox :input").keydown(function(){if($("#swc").attr("open")==undefined){submit_word();}});$("#page_links span").click(function(){$(this).parent().submit();});});function position_elements(initialize,cloud){if(cloud==undefined){cloud="#words_container";}
var wc=$(cloud);if(initialize==true){wc.attr("original_height",wc.height());}
var wc_height_ratio=wc.attr("original_height")/150;if(wc_height_ratio<1){wc_width=$(window).width()*wc_height_ratio;wc.width(wc_width);}else{wc.width($(window).width()*0.7);}
wc.css("top",$(window).height()/2-$("#words_container").height()/2);wc.css("left",$(window).width()/2-$("#words_container").width()/2);wc.show();$("#main_message").css("marginTop",-5);if($("#user_info").height()>110){$("#main_message").css("marginTop",20);}else{$("#main_message").css("marginTop",-5);}}
function submit_word(){if($("#swc").attr("open")==undefined){$("#swc").attr({"open":"open","original_height":$("#swc").height()});$("#swc").animate({"height":"326"},650,"easeInOutCubic",function(){is_animating=false;});$(".swc_bg").animate({"bottom":226},650,"easeInOutCubic",function(){swc_int=setInterval(function(){var cur_hgt=$("#swc").height();$("#swc").css("height","auto");optimal_hgt=$("#swc").height();$("#swc").css("height",cur_hgt);if(cur_hgt!=optimal_hgt&&!is_animating){is_animating=true;$("#swc").stop().animate({height:optimal_hgt},300,function(){is_animating=false;});$(".swc_bg").stop().animate({bottom:optimal_hgt-100},300);};},100);});$("#definition_textbox").addClass("bigger_definition","slow");$("#word_textbox :input").addClass("bigger_textbox_input","slow");$("#usage_textbox, #part_of_speech").fadeIn("slow");$("#close_submit_cloud").fadeIn("slow");}else{$("#submit_word_button").addClass("submit_button_down");$.put_inputs("/submit-word.php","#swc","#submit_word_button",function(call){$("#submit_word_button").removeClass("submit_button_down");if(call.response=="word_submitted"){close_submit_cloud();setTimeout(function(){var new_word=$(call.word_html).hide().appendTo("#words_container").show();new_word.attr("originalSize",new_word.css("fontSize")).css("fontSize","0.1em").animate({fontSize:new_word.attr("originalSize")},"slow");apply_tooltip();},700);}else if(call.response=="login_required"){$("#swc").attr("pending_submit","pending_submit");var additional_message="Submitting '"+$("#word_textbox :input").val()+"' to Cloudley";load_login_register(null,null,additional_message,submit_word);}else if(call.response=="err"){cloud_flash(call.err);}});}}
function close_submit_cloud(){if(typeof(swc_int)!="undefined"){clearInterval(swc_int);}
is_animating=true;$("#swc").removeAttr("open").animate({"height":$("#swc").attr("original_height")},650,"easeInOutCubic");$(".swc_bg").animate({"bottom":0},650,"easeInOutCubic");$("#word_textbox :input").removeClass("bigger_textbox_input","slow");$("#definition_textbox").removeClass("bigger_definition","slow");$("#definition_textbox :input").animate({"height":"25px"},"slow",function(){$("#word_textbox :input, #definition_textbox :input, #usage_textbox :input").val("").blur();$("#usage_textbox, #part_of_speech").hide();$("#part_of_speech li").removeClass("part_of_speech_selected").removeAttr("selected");$("[name='part_of_speech']").val("");is_animating=false;});$("#close_submit_cloud").fadeOut("slow");close_cloud_flash();}
function cloud_flash(err,timeout){if($("#error_cloud").is(":visible")){close_cloud_flash(function(){open_cloud_flash(err,timeout);});}else{open_cloud_flash(err,timeout);}}
function open_cloud_flash(err,timeout){if(typeof(close_cloud_flash_timeout)!="undefined"){clearTimeout(close_cloud_flash_timeout);}
$("#error_cloud_content").html(err);$("#error_cloud").show();var ec_height=$("#error_cloud_content").height()+130;if(ec_height>239){ec_height=239;}
$("#error_cloud").animate({"height":ec_height+"px"},650,"easeInOutCubic",function(){if(typeof(timeout)!="undefined"){close_cloud_flash_timeout=setTimeout(function(){close_cloud_flash();},timeout);}});}
function close_cloud_flash(callback){if($("#error_cloud").is(":visible")){$("#error_cloud").stop().animate({"height":"1px"},650,"easeInOutCubic",function(){$(this).children("#error_cloud_content").html("");$(this).hide();if(typeof(callback)=="function"){callback();}});}}
