var publicationId=0;jQuery(document).ready(function(){$(".tiped").tooltip({showBody:" - ",showURL:false,delay:500,top:-30});$(".tabs").tabs();var isBookOfTheDay=eval($("#isBookOfTheDay").val());if(isBookOfTheDay){jQuery("#menu li").removeClass("active");jQuery("#menu li#bookoftheday").addClass("active")}publicationId=jQuery("#publicationId").val();checkIfFavorited();checkIfWatched();checkIfInLibrary();showAllComments(publicationId);showAllReviews(publicationId);initBookmarks();initModalWindow();getRelatedPublications()});function initModalWindow(){$("#discount_message").jqm({trigger:"#message_trigger",overlay:0,onShow:function(a){a.w.css("opacity",0.92).slideDown()},onHide:function(a){a.w.slideUp("slow",function(){if(a.o){a.o.remove()}})}})}google.load("books","0");function showElement(b){jQuery(b).removeClass("hidden")}function hideElement(b){jQuery(b).addClass("hidden")}function markAsFavorite(){jQuery.post(CONTEXT_PATH+"/pub/mark/favorite",{id:publicationId},function(b){if(b=="ok"){hideElement("#markFav");showElement("#unmarkFav")}else{alert("Unauthorized operation!")}})}function unmarkAsFavorite(){jQuery.post(CONTEXT_PATH+"/pub/unmark/favorite",{id:publicationId},function(b){if(b=="ok"){hideElement("#unmarkFav");showElement("#markFav")}else{alert("Unauthorized operation!")}})}function checkIfFavorited(){jQuery.post(CONTEXT_PATH+"/pub/check/favorite",{id:publicationId},function(b){if(b=="yes"){showElement("#unmarkFav")}else{showElement("#markFav")}})}function addWatch(){jQuery.post(CONTEXT_PATH+"/pub/watch/add",{id:publicationId},function(b){if(b=="ok"){hideElement("#watch");showElement("#unwatch")}else{alert("Unauthorized operation!")}})}function removeWatch(){jQuery.post(CONTEXT_PATH+"/pub/watch/remove",{id:publicationId},function(b){if(b=="ok"){hideElement("#unwatch");showElement("#watch")}else{alert("Unauthorized operation!")}})}function checkIfWatched(){jQuery.post(CONTEXT_PATH+"/pub/check/watch",{id:publicationId},function(b){if(b=="yes"){showElement("#unwatch")}else{showElement("#watch")}})}function addToLibrary(){jQuery.post(CONTEXT_PATH+"/pub/library/add",{id:publicationId},function(b){if(b=="ok"){hideElement("#libAdd");showElement("#libRemove")}else{alert("Unauthorized operation!")}})}function removeFromLibrary(){jQuery.post(CONTEXT_PATH+"/pub/library/remove",{id:publicationId},function(b){if(b=="ok"){hideElement("#libRemove");showElement("#libAdd")}else{alert("Unauthorized operation!")}})}function checkIfInLibrary(){jQuery.post(CONTEXT_PATH+"/pub/check/library",{id:publicationId},function(b){if(b=="yes"){showElement("#libRemove")}else{showElement("#libAdd")}})}function showAllComments(b){jQuery("div#commentsHolder").empty();jQuery.getJSON(CONTEXT_PATH+"/pub/comment/list",{publicationId:b},function(a){jQuery("span#comments_tab_title").empty().append("Comments ("+a.length+")");if(a.length>0){jQuery.each(a,function(f,e){appendCommentEntry(e,f)})}else{jQuery("div#commentsHolder").append("<p>Currently there are no comments for this publication. Be the first to add one!</p>")}})}function appendCommentEntry(f,d){var e="";if(d%2==0){e+='<p class="alternate">'}else{e+="<p>"}e+='<span class="text">'+f.body+"</span>";if(f.isAuth){e+='<a href="javascript:;" class="button btn_delete" onclick="deleteComment(this,'+f.id+')"><span>Delete</span></a>'}e+='<span class="right comment_'+f.id+'"> '+f.dateCreated+' &bull; <a href="'+CONTEXT_PATH+"/profile/"+f.poster.id+"/"+f.poster.processedName+'">'+f.poster.name+"</a></span></p>";jQuery("div#commentsHolder").append(e);if(f.poster.jbbUsername!=null&&f.poster.jbbUsername!=""){jQuery.get(CONTEXT_PATH+"/jbb/belt",{username:f.poster.jbbUsername,size:"small"},function(a){jQuery("span.comment_"+f.id).append(a)})}}function addComment(){var c=jQuery("#publicationId").val();var d=jQuery("#txt_addcomment").val();if(d!=null&&d.length>0){jQuery.post(CONTEXT_PATH+"/pub/comment/add",{publicationId:c,content:d},function(){jQuery("#txt_addcomment").val("");showAllComments(c)})}}function deleteComment(d,e){var f=$(d).parent();if(confirm("Are you sure you want to delete the comment?")){jQuery.post(CONTEXT_PATH+"/pub/comment/delete",{commentId:e},function(a){if(a=="ok"){f.find("span.text").html("Comment removed by author.")}else{alert("Unauthorized operation!")}})}else{f.fadeTo(100,1)}}function showAllReviews(b){jQuery("div#reviewsHolder").empty();jQuery.getJSON(CONTEXT_PATH+"/pub/review/list",{publicationId:publicationId},function(a){jQuery("span#reviews_tab_title").empty().append("Reviews ("+a.length+")");if(a.length>0){jQuery.each(a,function(f,e){appendReviewEntry(e,f)})}else{jQuery("div#reviewsHolder").append("<p>Currently there are no reviews for this publication. Be the first to add one!</p>")}})}function appendReviewEntry(f,h){var g="";if(h%2==0){g+='<p class="alternate">'}else{g+="<p>"}var e="";if(f.backLink!=null&&f.backLink!=""){e=f.backLink}else{e=CONTEXT_PATH+"/review/"+f.id+"/"+f.title}g+='<span class="text">'+f.shortContent+'</span><a target="_blank" href="'+e+'" class="button btn_view"><span>View</span></a>';if(f.isAuth){g+='<a href="'+CONTEXT_PATH+"/review/edit/"+f.id+'" class="button btn_edit"><span>Edit</span></a><a href="javascript:;" class="button btn_delete" onclick="deleteReview(this,'+f.id+')"><span>Delete</span></a>'}g+='<span class="right review_'+f.id+'"> '+f.dateCreated+' &bull; <a href="'+CONTEXT_PATH+"/profile/"+f.reviewerId+"/"+f.reviewerProcessedName+'">'+f.reviewer+"</a></span></p>";jQuery("div#reviewsHolder").append(g);if(f.jbbUsername!=null&&f.jbbUsername!=""){jQuery.get(CONTEXT_PATH+"/jbb/belt",{username:f.jbbUsername,size:"small"},function(a){jQuery("span.review_"+f.id).append(a)})}}function deleteReview(d,e){var f=$(d).parent();if(confirm("Are you sure you want to delete the review?")){jQuery.post(CONTEXT_PATH+"/pub/review/delete",{id:e,ajax:true},function(a){if(a=="ok"){f.fadeTo(0,0.6);f.slideUp(250,function(){$(d).remove()})}else{alert("Unauthorized operation!")}})}else{f.fadeTo(100,1)}}function getRelatedPublications(){jQuery.get("/pub/related",{id:jQuery("#publicationId").val(),categoryId:jQuery("#categoryId").val()},function(b){jQuery("#related").empty().append(b)})}function initGoogleBookPreview(){var d=$("#isbn").val();var c=new google.books.DefaultViewer(document.getElementById("canvas"));c.load("ISBN:"+d)}function checkAvailability(){var c=$("#isbn").val();var d=document.createElement("script");d.src="http://books.google.com/books/feeds/volumes?q="+encodeURIComponent(c)+"&min-viewability=partial&alt=json-in-script&callback=handleResults";d.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(d)}function handleResults(d){var f=d.feed;var e=f.entry||[];if(e.length>0){$("#canvas").css("height","500px");initGoogleBookPreview()}else{$("#canvas").empty().css("height","30px").html("No preview is available at this time.")}}function click(c,d){jQuery.post(CONTEXT_PATH+"/pub/click",{from:c,to:d})};