$.ajaxSetup({'beforeSend':function(xhr){xhr.setRequestHeader("Accept","text/javascript");}});$(document).ajaxSend(function(event,request,settings){if(settings.type=='GET'||settings.type=='POST')return;if(typeof(AUTH_TOKEN)=="undefined")return;settings.data=settings.data||"";settings.data+=(settings.data?"&":"")+"authenticity_token="+encodeURIComponent(AUTH_TOKEN)});function _ajax_request(url,data,callback,type,method){if(jQuery.isFunction(data)){callback=data;data={};}return jQuery.ajax({type:method,url:url,data:data,success:callback,dataType:type});};
jQuery.extend({put:function(url,data,callback,type){return _ajax_request(url,data+"&authenticity_token="+encodeURIComponent(AUTH_TOKEN),callback,type,'PUT');},delete_:function(url,data,callback,type){return _ajax_request(url,data+"&authenticity_token="+encodeURIComponent(AUTH_TOKEN),callback,type,'DELETE');}});
jQuery.fn.submitWithAjax=function(callback){this.unbind('submit',false);this.submit(function(){if($(":input[type=textarea]").val()==""||$(":input[type=textfield]").val()==""){alert("Your input is empty. Try again.");return false;}var thisElementHtml=$(":input[type=submit]").parent().html();var element=$(":input[type=submit]").parent();element.html("<div style='margin:0 auto;width:25px;height:25px;'><img src='/images/loading.gif' /></div>");$.post(this.action,$(this).serialize(),function(){$("#stream_text").val('');element.html(thisElementHtml);callback();},"script");return false;});return this;};


jQuery.fn.getWithAjax=function(){this.unbind('click',false);this.live("click",function(){var thisElementHtml=$(this).html();var element=$(this);$(this).children("img").hide();$(this).append("<div style='margin:0 auto;width:25px;height:25px;'><img src='/images/loading.gif' /></div>");$.get($(this).attr("href"),$(this).serialize(),function(){element.html(thisElementHtml);},"script");return false;});return this;};jQuery.fn.postWithAjax=function(){this.removeAttr('onclick');this.unbind('click',false);this.live("click",function(){$.post($(this).attr("href"),$(this).serialize()+"&authenticity_token="+encodeURIComponent(AUTH_TOKEN),null,"script");return false;});return this;};jQuery.fn.putWithAjax=function(){this.removeAttr('onclick');this.unbind('click',false);this.live("click",function(){$.put($(this).attr("href"),$(this).serialize(),null,"script");return false;});return this;};jQuery.fn.deleteWithAjax=function(){this.removeAttr('onclick');this.unbind('click',false);this.live("click",function(){$.delete_($(this).attr("href"),$(this).serialize(),null,"script");return false;});return this;};function ajaxLinks(){$('a.post,a.put,a.delete').removeAttr("onclick");$('.ajaxForm').submitWithAjax();$('a.get').getWithAjax();$('a.post').postWithAjax();$('a.put').putWithAjax();$('a.delete').deleteWithAjax();}


$(document).ready(function(){$("#form_inner :input[type='text']").tooltip({position:['center','right'],offset:[0,10],effect:'toggle',opacity:0.8});ajaxLinks();$(".hide_flash").live("click",function(){$(".flash_wrapper").hide().remove();});$("ul.css-tabs").tabs("div.panes > div");var triggers=$("a.modalInput").overlay({expose:{color:"#111",loadSpeed:200,opacity:0.9},closeOnClick:false});$("ul.css-tabs").tabs("div.panes > div");$(".remote_overlay[rel]").overlay({onBeforeLoad:function(){var wrap=this.getContent().find("div.wrap");wrap.html("<div style='margin:0 auto;width:25px;height:25px;'><img src='/images/loading.gif' /></div>");wrap.load(this.getTrigger().attr("href"));},expose:{color:"#111",loadSpeed:200,opacity:0.9},closeOnClick:false});$(".table_inner").live("click",function(){$(this).tablesorter({sortList:[[0,0]]});});$(".table_inner tr,.table_inner_no_sort tr,#streams_all_ol li").live("mouseover",function(){$(this).addClass("hoverme");});$(".table_inner tr,.table_inner_no_sort tr,#streams_all_ol li").live("mouseout",function(){$(this).removeClass("hoverme");});$('#main-nav').superfish({delay:500,animation:{opacity:'show',height:'show'},speed:'fast',autoArrows:false,dropShadows:false});$('.paginate a').getWithAjax();$(".ajax_button").live("click",function(){$(this).submitWithAjax(null);});});