$('document').ready(function(){  
  //Текст или ссылка на букмарк
  var ver = navigator.appName;
  var num = parseInt(navigator.appVersion);
  pic1 = new Image(50,25); pic1.src = "/img/bank_it_over.jpg";
  pic2 = new Image(209,26); pic2.src = "/img/get_prize_btn_over4.jpg";
  $(".bookmark").each(function() {
    url = $('a', $(this)).attr("href");
    title= $('a', $(this)).attr("title");

    if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
       $(this).html('<a href="javascript:window.external.AddFavorite(\''+url+'\', \''+title+'\')">Bookmark joke</a>');
    }else{
       
    }
  });

  //Подтверждение коментариев
  $('.aprove').live('click',function(){
    $.ajax({
      type: "GET",
      url: $(this).attr("href")
    });

    $(this).ajaxStop(function(){
      $("#msg").attr("class","display");
      $("#msg_txt").html("Comment approved");
      $("#main_center").load('/comments/unaproved #content_main')
      $("#extra").load('/comments/unaproved #extra ul')
    });

    return false;
  });

  //Удаление коментариев
  $('.delete').live('click',function(){
    if(confirm('Are you sure you want to delete comment?')) {
      $.ajax({
        type: "GET",
        url: $(this).attr("href")
      });

      $(this).ajaxStop(function(){
        $("#msg").attr("class","display");
        $("#msg_txt").html("Comment deleted");
        $("#main_center").load('/comments/unaproved #content_main')
        $("#extra").load('/comments/unaproved #extra ul')
      });
    }
    return false;
  });

  //Голосование за шутку
//  $('.bank').live('click',function(){
//    $.ajax({
//      type:"GET",
//      url: $(this).attr("href")
//    });
//
//    $(this).ajaxStop(function(){
//      $("#content").load('/categories/competing #content div');
//    });
//
//    return false;
//  });

  $('.abuse').live('click', function() {
    $.ajax({
      type:"GET",
      url: $(this).attr("href")
    });

    $(this).ajaxStop(function() {
      $("#msg").attr("class","display");
      $("#msg_txt").html("Report sent");
    });

    return false;
  });

  //Удаление шуток
//  $('.jokeDelete').live('click', function() {
//    if(confirm('Are you sure you want to delete joke?')) {
//      $.ajax({
//        type:"GET",
//        url: $(this).attr("href")
//      });

//      $(this).ajaxStop(function() {
//        $("#search_joke").css("display","block");
//        $("#msg").attr("class","display");
//        $("#msg_txt").html("Joke deleted");
//        $("#main_center").load("/admin/jokes/list #content_main");
//      });
//    }
//    return false;
//  });

  //Удаление пользователя
//  $('.userDelete').live('click', function() {
//    if(confirm("You are deleting the user. User's jokes and comments will also be deleted. Continue anyway?")) {
//      $.ajax({
//        type:"GET",
//        url:$(this).attr("href")
//      });

//      $(this).ajaxStop(function() {
//        $("#msg").attr("class","display");
//        $("#msg_txt").html("User deleted");
//        $("#content").load("/admin/users/list #content div");
//      });
//    }
//    return false;
//  });

  //Удаление категорий(шуток этой категории и соментов с этих шуток)
//  $('.categoryDelete').live('click', function() {
//    if(confirm("You are deleting the category. Category's jokes and comments will also be deleted. Continue anyway?")) {
//      $.ajax({
//        type:"GET",
//        url:$(this).attr("href")
//      });

//      $(this).ajaxStop(function() {
//        $("#msg").attr("class","display");
//        $("#msg_txt").html("Category deleted");
//        $("#navigation").load("/admin/categories/list #navigation ul");
//        $("#main_center").load("/admin/categories/list #content_main");
//      });
//    }
//    return false;
//  });

//  Активация категории
//  $('.categoryActive').live('click', function() {
//    $.ajax({
//      type:"GET",
//      url:$(this).attr("href")
//    });

//    $(this).ajaxStop(function() {
//        $("#msg").attr("class","display");
//        $("#msg_txt").html("Category active");
//        $("#menu_list").load("/admin/categories/list #menu_list ul");
//        $("#main_center").load("/admin/categories/list #content_main");
//    });
//    return false;
//  });

//  Деактивация категории
//  $('.categoryDeactive').live('click', function() {
//    $.ajax({
//      type:"GET",
//      url:$(this).attr("href")
//    });

//    $(this).ajaxStop(function() {
//        $("#msg").attr("class","display");
//        $("#msg_txt").html("Category deactive");
//        $("#menu_list").load("/admin/categories/list #menu_list ul");
//        $("#main_center").load("/admin/categories/list #content_main");
//    });
//    return false;
//  });

  $("#logo").click(function(){
    window.location.href = "/";
  });
  
  $("#menu_ul").children("li").hover(function(){
     $("this").children("a").css('color', "#6AA4BF");
  },
  function(){
     $("this").children("a").css('color', "#313131");
  });
  
  $(".winners_title_txt").hover(function(){
     $("this").children("a").css('color', "#6AA4BF");
  },function(){
     $("this").children("a").css('color', "#313131");
  });
  
  $(".joke_title_table").hover(function(){
     $("this").children("a").css('color', "#6AA4BF");
  },function(){
     $("this").children("a").css('color', "#313131");
  });
  
  $(".bank_it_img").hover(function(){
    $(this).attr("src","/img/bank_it_over.jpg");
  },
  function(){
    $(this).attr("src","/img/bank_it.jpg");
  });
  
  $("#UserSignupForm").submit(function(){
    if($("#UserId").attr('value') == ''){
      k = 0;
      $(".verify").each(function(){
         if($(this).attr('value') == ''){
           k = 1;
         }
      });
      if(k == 1){
        alert("All fields must be field in.");
        return false;
      } else {
        return true;
      }
    }
  });
  
  $("#JokeAddForm").submit(function(){
    if($("#add_title_field").attr('value') == ''){
      alert('Please enter a title.');
      return false;
    }

    if($("#JokeCategoryId").attr('value') == ''){
      alert('Please select a category.');
      return false;
    }
    if($("#add_text_field").attr('value')=='' && $("#add_video_field").attr('value')==''){
      alert('Please enter text or video.');
      return false;
    }
    return true;
  })
  
  $(".get_prize_btn").hover(function(){
    $(this).attr('src',"/img/get_prize_btn_over4.jpg");
  }, function(){
    $(this).attr('src',"/img/get_prize_btn.jpg");
  });

//  $("*").ajaxStart(function(){
//    $("#load").css('display', 'block');
//  });

//  $("*").ajaxStop(function(){
//    $("#load").css('display', 'none');
//  });
});











