$(document).ready(function(){if($("body").data("is_index_page")!=true){apply_tooltip("short_word_info");}else{apply_tooltip();}
$("#word_info").hover(function(){$("#word_info").attr("mouse_over","mouse_over");},function(){if($("#word_info").attr("comment_on")!="comment_on"){$("#word_info").removeAttr("mouse_over");$("#word_info, #word_pointer").hide();}});$("#word_pointer").hover(function(){$("#word_info").attr("mouse_over","mouse_over");});});function apply_tooltip(template){$(".word[tooltipped!='true']").each(function(){$(this).attr("tooltipped","true");$(this).hoverIntent({over:function(){if($("#word_info").attr("comment_on")=="comment_on"){return true;}
var word=$(this);var word_pointer=$("#word_pointer");var word_info=$("#word_info");word_info.html("<div id='word_info_content'>Loading <img src='/includes/images/front/index/load.gif' /></div>");word_info.addClass("word_info_loading").show();open_word_info(word,word_pointer,word_info);if(typeof(template)=="undefined"){template="word_info";};$.put("/index.php",{action:"get_word_info",word_id:$(this).attr("id").replace("word_",""),"template":template},null,function(call){if(call.response=="success"){word_info.removeClass("word_info_loading");word_info.html("<div id='word_info_content'>"+call.word_info_html+"</div>");word_info.find(".comments").corner();word_info.find(".view_cloud_link").corner("5px");word_info.find(".comment_link").corner("5px").hover(function(){$(this).addClass("comment_link_over");},function(){$(this).removeClass("comment_link_over");});open_word_info(word,word_pointer,word_info);}});},out:function(){close_word_info();},timeout:100});});}
function open_word_info(word,word_pointer,word_info){if($("#word_info").attr("comment_on")=="comment_on"){return true;}
word_pointer.show();word_info.show().corner("15px");if(word.hasClass("top_word")){word_info.addClass("top_word_info");}else{word_info.removeClass("top_word_info");}
win_height=$(window).height();win_width=$(window).width();word_top=word.offset().top;word_bottom=word_top+word.outerHeight();word_left=word.offset().left;word_right=word_left+word.outerWidth();dist_top=word_top;dist_bottom=win_height-word_bottom;dist_left=word_left;dist_right=win_width-word_right;tt_height=word_pointer.outerHeight()+word_info.outerHeight();tt_width=word_pointer.outerWidth()+word_info.outerWidth();word_info.css({height:"auto",top:0,left:0});word_pointer.css({top:0,left:"15px"});var room_on_top=dist_top>=tt_height;var room_on_bottom=dist_bottom>=tt_height;var room_on_right=dist_right>=tt_width;var room_on_left=dist_left>=tt_width;if(room_on_bottom==true&&room_on_right==true){word_pointer.attr("class","word_pointer_below");word_pointer.offset({top:word_bottom,left:word_left+word.width()/2});word_info.offset({top:word_bottom+word_pointer.height(),left:word_left+word.width()/2-word_info.width()/2+word_pointer.width()/2});}else if(room_on_top==true&&room_on_right==true){word_pointer.attr("class","word_pointer_above");word_pointer.offset({top:word_top-word_pointer.height(),left:word_left+word.width()/2});word_info.offset({top:word_top-tt_height,left:word_left+word.width()/2-word_info.width()/2+word_pointer.width()/2});}else{if(tt_height>win_height){$("#word_info_content").height(($(window).height()*0.95)-30);$("#word_info_content").css("overflow","auto");spec_height=$("#swc").length>0?$(window).height():$(document).height();word_info.offset({top:((spec_height-word_info.outerHeight())/2)});}else{$("#word_info_content").css("overflow","hidden");word_info.offset({top:(word_top+word.outerHeight()/2-(word_info.outerHeight()/2))});}
if(room_on_right==true){word_pointer.attr("class","word_pointer_right");word_pointer.offset({top:word_top+word.outerHeight()/2-(word_pointer.outerHeight()/2),left:word_right});word_info.offset({left:word_right+word_pointer.width()});}else{word_pointer.attr("class","word_pointer_left");word_pointer.offset({top:word_top+word.outerHeight()/2-(word_pointer.outerHeight()/2),left:word_left-word_pointer.outerWidth()});word_info.offset({left:word_left-word_info.outerWidth()-word_pointer.outerWidth()});}}
setFacebookLike(word);}
function close_word_info(){if($("#word_info").attr("comment_on")=="comment_on"){return true;}
if($("#word_info").attr("mouse_over")!="mouse_over"){$("#word_pointer, #word_info").hide();}}
function setFacebookLike(word){load_facebook(function(){var fb_url='http://cloudley.com/'+word.parent().attr("href");fb_like='<div class="fb_recommend" style="margin:10px 5px 0 10px"><fb:like href="'+fb_url+'" layout="standard" show_faces="false" action="like" colorscheme="light" width="330"></fb:like></div>';$("#word_info").append(fb_like);});}
