/*
 * (c) der heisse draht 2008
 */
var commentCaretPos;jQuery(document).ready(function(){CommentInitialize();jQuery(document).ajaxSuccess(function(){CommentInitialize();activateEventHandlersForAjaxableItems()});if(typeof document.selection!="undefined"){jQuery("#writeNewComment textarea").click(function(){storeCommentCaretPos()}).change(function(){storeCommentCaretPos()}).select(function(){storeCommentCaretPos()}).keyup(function(){storeCommentCaretPos()})}});function storeCommentCaretPos(){commentCaretPos=document.selection.createRange().duplicate()}function CommentInitialize(){var a="";a=jQuery("#writeNewComment form input[name=PHPSESSID]").val();if(a){a="?PHPSESSID="+a}else{a=""}jQuery("#writeNewComment form").unbind("submit").submit(function(){jQuery("#writeNewComment, #writeNewCommentBt").toggle();jQuery.ajax({type:"POST",url:comments_json_url,data:jQuery("#writeNewComment form").serialize(),dataType:"json",global:false,success:function(b){jQuery("#writeNewComment ~ div.dummy:first").clone(true).insertAfter("#writeNewComment ~ div.dummy:first").show().find("a._profile").attr("href",b.user_profile_url+""+a).end().find("a.delete_comment").attr("id","comment-"+b.id).end().find("a > img").attr("src",b.avatar).attr("alt",b.username_html).end().find("._username").removeClass("_username").html(b.username).end().find("._date").removeClass("_date").html(b.nicedate).end().find("._content").removeClass("_content").html(b.contents_html).end().removeClass("dummy");jQuery(".cmt_max").html(parseInt(jQuery(".cmt_max").text())+1);jQuery(".cmt_total").html(parseInt(jQuery(".cmt_total").text())+1);jQuery("#writeNewComment textarea").get(0).value="";if(false===b.is_brand_owner&&"never"!=readCookie("show_matzinger_notice")){jsBox("/ajax/crossdomain/dtw/profile/guestbookNotice.php","ajax")}},error:function(){jQuery("#writeNewComment, #writeNewCommentBt").toggle();alert(comments_error_save)}});return false});jQuery("a.delete_comment").unbind("click").click(function(){var e=jQuery(this).attr("id").replace(/comment-/,"");var d=jQuery("#writeNewComment form :input[name=item_id]").val();var c=jQuery("#writeNewComment form :input[name=type_id]").val();var b=jQuery("#writeNewComment form :input[name=owner]").val();jsConfirm(comments_msg_delete,function(){CommentDeleteComment(e,d,c,b)})});jQuery(".userUploads").data("items",{}).unbind("rehide").bind("rehide",function(){jQuery(this).hide();jQuery("#addNewImageBt").show()}).unbind("reveal").bind("reveal",function(){jQuery(this).data("nextpage",1).trigger("refresh").show();jQuery("#addNewImageBt").hide()}).unbind("noUploads").bind("noUploads",function(){jQuery(this).find(".useUploaded").hide()}).unbind("refresh").bind("refresh",function(){$this=jQuery(this);if($this.data("nextpage")){var c=$this.data("nextpage");var d=$this.data("items");if(d[c]){var d=$this.data("items");var b=d[c];$this.data("myitems",b);if(b.next==0){$this.find(".next").css("visibility","hidden")}else{$this.find(".next").css("visibility","visible")}if(b.prev==0){$this.find(".prev").css("visibility","hidden")}else{$this.find(".prev").css("visibility","visible")}$this.find("div.rem").remove();jQuery.each(b.items,function(e,f){$this.find("div.img:hidden:last").clone(true).insertBefore(".userUploads div.img:last").find("img").attr("src",b.path+f.up_id+"_thumb."+f.ext).end().addClass("rem").show()});return}jQuery.ajax({type:"GET",url:comments_json_url,dataType:"json",global:false,data:{task:"get_viewers_uploads",page:c},error:function(){var f=$this.data("items");var e=$this.data("nextpage");f[e]={};$this.data("items",f);$this.trigger("noUploads")},success:function(e){if(e&&e.page){var f=$this.data("items");f[e.page]=e;$this.data("items",f);if(e.items&&e.items.length){$this.trigger("refresh")}else{$this.trigger("noUploads")}}else{$this.trigger("noUploads")}}})}}).find(".prev > img").unbind("click").click(function(){var b=jQuery(".userUploads").data("myitems");jQuery(".userUploads").data("nextpage",b.prev).trigger("refresh")}).end().find(".next > img").unbind("click").click(function(){var b=jQuery(".userUploads").data("myitems");jQuery(".userUploads").data("nextpage",b.next).trigger("refresh")}).end().find(":button[name=img_bt]").unbind("click").click(function(){var b=jQuery(this).siblings(":text[name=img_url]").val();if(b!=jQuery(this).siblings(":text[name=img_url]").attr("title")){b="[img]"+b+"[/img]";CommentAddToTextarea(b)}}).end().find(".close_bt img").unbind("click").click(function(){jQuery(".userUploads").trigger("rehide")}).end().find(".img > img").unbind("click").click(function(){$img=jQuery(this);var b="[img]"+$img.attr("src")+"[/img]";CommentAddToTextarea(b);$img.animate({opacity:0.4},100).animate({opacity:1},200)})}function CommentAddToTextarea(a){jQuery("#writeNewComment").find("textarea").each(function(){var b=this.jquery?this[0]:this;return(("selectionStart" in b&&function(){b.value=b.value.substr(0,b.selectionStart)+a+b.value.substr(b.selectionEnd,b.value.length);return this})||(typeof document.selection!="undefined"&&function(){if(commentCaretPos){range=commentCaretPos}else{range=document.selection.createRange().duplicate()}range.text=a;b.focus();return this})||function(){b.value+=a;return this})()})}function CommentToggleImages(){jQuery(".userUploads").trigger("reveal");return}function CommentToggleWrite(){if(comments_loggedin!=1){document.location.href=comments_login_url}else{jQuery("#writeNewComment, #writeNewCommentBt").toggle()}return}function CommentDeleteComment(d,c,b,a){var e=d;jQuery.ajax({type:"POST",url:comments_json_url,data:{id:e,task:"del_comment",global:false,item_id:c,type_id:b,owner:a},dataType:"json",success:function(f){jQuery("#comment-"+e).parents("div.comment").hide("slow",function(){jQuery(this).remove();jQuery(".cmt_max").html(parseInt(jQuery(".cmt_max").text())-1);jQuery(".cmt_total").html(parseInt(jQuery(".cmt_total").text())-1)})},error:function(){alert(comments_error_save)}})}function readCookie(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf(e)==0){return f.substring(e.length,f.length)}}return null};