$(function(){$.form("blog/blog_entries","blog/blog_categories","blog_category_id","blog_shared_category_id",[{name:"title",text:"Title"}]);if($.url.param("id")!=undefined){$.getJSON("http://demo.firerift.com/api/blog/blog_entries?include=blog_category&id="+$.url.param("id"),function(data){var opts={blog_category_id:data.items[0].blog_category[0].id};if(data.items[0].user_id!=$.session.user.id){opts.shared="YES";$("#shared").parent().remove();$("#category_id").parent().parent().remove();}
$.breadcrumbs("blog/blog_entries","Blogs",data.items[0].blog_category[0].name,data.items[0].title,opts,$.url.param("id"));});$.getJSON("http://demo.firerift.com/api/blog/blog_entry_comments/count?blog_entry_id="+$.url.param("id"),function(data){$("#panel-title-replace span").text(data);});}else{$("div.change-datetime").remove();}
$(".form-holder form").css("display","block");$("#live_preview").fancybox({'zoomSpeedIn':300,'zoomSpeedOut':300,'frameWidth':700,'frameHeight':400,'overlayShow':true});var iframe=document.getElementById("iframe");if($.session.user.message_type=="html"){iframe.style.display="none";$("#frm-text").show();$("#msg-opts").hide();$("#msg_type").val($.session.user.message_type);$("#msg-type-update").text($("#msg_type option:selected").text());}
$("#live_preview").mouseover(function(event){if($("#iframe:visible").length>0){$("#frm-text").val(iframe.contentWindow.document.body.innerHTML);}
$(this).attr("href","http://demo.firerift.com/app/core/shared/preview?title="+escape($("input[name=title]").val()));return false;})
$("#use_title_link").click(function(){if($(this).hasClass("check-on")){$(this).removeClass("check-on");$(this).addClass("check-off");$("input[name=use_title_link]").val("NO");$("#custom_linked").addClass("check-off");$("#custom_linked").removeClass("check-on");$("input[name=custom_linked]").val("NO");$("#custom_linked").attr("disabled",true);$("input[name=title_link]").attr("disabled",true);}else{$(this).removeClass("check-off");$(this).addClass("check-on");$("input[name=use_title_link]").val("YES");$("#custom_linked").attr("disabled",false);}
return false;});$("#custom_linked").click(function(){if($("#use_title_link").hasClass("check-on")){if($(this).hasClass("check-on")){$(this).removeClass("check-on");$(this).addClass("check-off");$("input[name=custom_linked]").val("NO");$("input[name=title_link]").attr("disabled",true);}else{$(this).removeClass("check-off");$(this).addClass("check-on");$("input[name=custom_linked]").val("YES");$("input[name=title_link]").attr("disabled",false);}}
return false;});$("#frm-fullscreen").click(function(event){if($("#iframe:visible").length>0){$("#frm-text").val(iframe.contentWindow.document.body.innerHTML);}
fullscreen($("#frm-text").val());return false;});function fullscreen(text){$("body").append("<div id='fs-overlay'></div>");$("body").append("<div id='fs-holder' ></div>");$("#fs-holder").append("<div id='fs-body'></div>");$("#fs-body").append("<div id='fs-close'></div>");$("#fs-body").append("<textarea id='fs-text' style='resize:none;'>"+text+"</textarea>");$("#fs-body").append("<div id='fs-bottom'></div>");$("#fs-bottom").append("<div id='fs-save' class='btn-save'></div>");$("#fs-text").keyup(function(){$.createLink("#fs-text","#dropdown-holder");});$("#fs-save").click(function(){$("#frm-text").val($("#fs-text").val());iframe.contentWindow.document.body.innerHTML=$("#fs-text").val();fadefs();return false;});$("#fs-close").click(function(){fadefs();return false;});$("#fs-overlay").css({"opacity":"0","display":"block"}).fadeTo("normal",0.6);$("#fs-holder").show("scale",{percent:100},"normal",function(){$('#fs-text').focus();$('#fs-text')[0].setSelectionRange(text.length,text.length)});}
function fadefs(){$("div#fs-overlay").fadeOut(function(){$(this).remove();});$("div#fs-holder").hide("scale",{},"normal",function(){$(this).remove();});}
$("#msg_type").change(function(){var val=$(this).val();if(val=="html"){$("#frm-text").val(iframe.contentWindow.document.body.innerHTML);$("#iframe, #msg-opts").hide();$("#frm-text").show();$("#frm-insert-link").unbind().click(function(){$("#dropdown-holder").html($("#add_link_dropdown").html()).show("slide",{direction:'up'},function(){$("#dropdown-holder input[name=name]").focus();$("#dropdown-holder input[name=new_window]").val("NO");});$("#dropdown-holder form").submit(function(){$.addlinks();return false;});return false;});}else{var content=$("#frm-text").val();content=content.replace(/{\{base_url}\}/g,"http://demo.firerift.com/");iframe.contentWindow.document.body.innerHTML=content;$("#frm-text").hide();$("#iframe, #msg-opts").show();$("#frm-insert-link").unbind().click(function(){var mylink=prompt("Enter a URL:","http://");if((mylink!=null)&&(mylink!="")){iframe.contentWindow.document.execCommand("CreateLink",false,mylink);}
return false;});}
$("#msg-type-update").text($(this).children(":selected").text());return false;});$("#msg-opts a.btn-bold").click(function(){iframe.contentWindow.document.execCommand('bold',false,null);return false;});$("#msg-opts a.btn-italic").click(function(){iframe.contentWindow.document.execCommand('italic',false,null);return false;});$("#msg-opts a.btn-underline").click(function(){iframe.contentWindow.document.execCommand('underline',false,null);return false;});$("#msg-opts a.btn-ul").click(function(){iframe.contentWindow.document.execCommand('insertunorderedlist',false,null);return false;});$("#msg_heading").change(function(){var headval=$(this).val();if(headval!="null"&&headval!=""){if(headval=="normal"){iframe.contentWindow.document.execCommand('formatblock',false,"P");}else{iframe.contentWindow.document.execCommand('formatblock',false,headval);}}
$("#msg-heading-update").text($(this).children(":selected").text());return false;});});