var msgTemplate=function(a,c,b){
  return $('<div class="notification"><div class="notification-body"><img src="/images/'+a+'" class="icon" /><h3>'+c+"</h3><p>"+b+'</p></div><div class="notification-bottom"></div></div>')
};
var App={Config:{Purr:{removeTimer:6000}}};
var onLoadForgotPasswordForm=function(a){
  $("#modal-form-wrapper").dialog("open").dialog("option","title","Forgot Password ?")
};
var onLoadSignupForm=function(a){
  $("#modal-form-wrapper").dialog("open").dialog("option","title","Sign Up")
};
var onLoadLoginForm=function(a){
  $("#modal-form-wrapper").dialog("open").dialog("option","title","Log in")
};
var onLoadCommentForm=function(b){
  var a=$(b).find("form");
  $("#modal-form-wrapper").dialog("open").dialog("option","title","Post comment").dialog("option","top","100")
};
var onLoadReportAbuseForm=function(b){
  var a=$(b).find("form");
  $("#modal-form-wrapper").dialog("open").dialog("option","title","Report abuse").dialog("option","top","100")
};
var onLoadPostHelpForm=function(b){
  var a=$(b).find("form");
  $("#modal-form-wrapper").dialog("open").dialog("option","title","I WANT TO HELP!").dialog("option","top","100")
};
var onLoadCompleteWishForm=function(b){
  var a=$(b).find("form");
  $("#modal-form-wrapper").dialog("open").dialog("option","title","Complete wish").dialog("option","top","100")
};
var loadLoginForm=function(a){
  $("#modal-form-wrapper").load($(this).attr("href"),onLoadLoginForm);
  return false
};
var loadSignupForm=function(a){
  $("#modal-form-wrapper").load($(this).attr("href"),onLoadSignupForm);
  return false
};
var loadForgotPasswordForm=function(a){
  $("#modal-form-wrapper").load($(this).attr("href"),onLoadForgotPasswordForm);
  return false
};
var loadCommentForm=function(b){
  var a=$("#comment-container").attr("rel").replace("wish-","");
  $("#modal-form-wrapper").load("/wishes/"+a+"/comment_form",onLoadCommentForm);
  return false
};
var loadReportAbuseForm=function(b){
  var a=$(this);
  $("#modal-form-wrapper").load("/wishes/"+a.attr("id").replace("cmd-report-abuse-for-","")+"/abuse",onLoadReportAbuseForm);
  return false
};
var loadPostHelpForm=function(b){
  var a=$(this);
  $("#modal-form-wrapper").load("/wishes/"+a.attr("id").replace("cmd-post-help-for-","")+"/want_help",onLoadPostHelpForm);
  return false
};
var loadCompleteWishForm=function(b){
  var a=$(this);
  $("#modal-form-wrapper").load("/wishes/"+a.attr("id").replace("cmd-complete-wish-for-","")+"/complete",onLoadCompleteWishForm);
  return false
};
function formToAjax(){
  $("#modal-form-wrapper form").submit(function(b){
    var c={},a=$(this);
    a.find("input[type=text], input[type=hidden], input[type=password], input[type=submit], textarea").each(function(){
      c[this.name||this.id||this.parentNode.name||this.parentNode.id]=this.value}).end().find("input[type=checkbox]").each(function(){
        if(this.checked){ c[this.name||this.id||this.parentNode.name||this.parentNode.id]=this.value }
      });
      $.post($(this).attr("action"),c,function(d){
      $("#modal-form-wrapper").html(d)
    });
    b.preventDefault();
    return false
  });
}
function ieFormToAjax(){
  $("#modal-form-wrapper form").submit(function(b){
    var c={},a=$(this);
    a.find("input[type=text], input[type=hidden], input[type=password], input[type=submit], textarea").each(function(){
      c[this.name||this.id||this.parentNode.name||this.parentNode.id]=this.value}).end().find("input[type=checkbox]").each(function(){
        if(this.checked){ c[this.name||this.id||this.parentNode.name||this.parentNode.id]=this.value }
      });
      $.post($(this).attr("action"),c,function(d){
      $("#modal-form-wrapper").html(d)
    });
    b.preventDefault();
    return false
  });
}
$(document).ready(function(){
  $("#modal-form-wrapper").dialog({modal:true,autoOpen:false,width:350,height:550});
  $(".cmd-login").live("click",loadLoginForm);
  $(".cmd-signup").live("click",loadSignupForm);
  $(".cmd-forgot-password").live("click",loadForgotPasswordForm);
  $(".cmd-add-comment").live("click",loadCommentForm);
  $(".cmd-report-abuse").live("click",loadReportAbuseForm);
  $(".cmd-post-help").live("click",loadPostHelpForm);
  $(".cmd-complete-wish").live("click",loadCompleteWishForm);
  $(".notification").purr(App.Config.Purr).show();
  $("#modal-form-wrapper form").live("submit",function(b){
    var c={},a=$(this);
    a.find("input[type=text], input[type=hidden], input[type=password], input[type=submit], textarea").each(function(){
      c[this.name||this.id||this.parentNode.name||this.parentNode.id]=this.value}).end().find("input[type=checkbox]").each(function(){
        if(this.checked){ c[this.name||this.id||this.parentNode.name||this.parentNode.id]=this.value }
      });
      $.post($(this).attr("action"),c,function(d){
        $("#modal-form-wrapper").html(d)
      });
      return false
  });
  $("#searchform").submit(function(b){
    var a=$("#_search");
    return(a.val()!=a.attr("note"))
  });
  $("#searchform input[type=reset]").click(function(a){
    window.location="/";
    return false
  });
  $("#_search").blur(function(){
    var a=$(this);
    if(!a.val()&&a.attr("note")){
      a.val(a.attr("note")).addClass("input-note")
    }
  }).focus(function(){
    var a=$(this);
    if(a.val()==a.attr("note")){
      a.val("").removeClass("input-note")
    }
  })
});

