function topic_1(){
  $("#open").html("close");
  $("#open_str").css("background", "url(/imgs/close_str.jpg)");
  if($("#topic_middle").css("display") == "none"){
    $(".topic_content_1").css("display", "block");
    $("#topic_middle").slideDown("slow");
  } else {
    if($(".topic_content_1").css("display") == "none"){
      $("#topic_middle").slideUp("slow", function(){
        $(".topic_content_2").css("display", "none");
        $(".topic_content_3").css("display", "none");
        $(".topic_content_1").css("display", "block");
        $("#topic_middle").slideDown("slow");
      });
    }
  }
}

function topic_2(){
  $("#open").html("close");
  $("#open_str").css("background", "url(/imgs/close_str.jpg)");
  if($("#topic_middle").css("display") == "none"){
    $(".topic_content_2").css("display", "block");
    $("#topic_middle").slideDown("slow");
  } else {
    if($(".topic_content_2").css("display") == "none"){
      $("#topic_middle").slideUp("slow", function(){
        $(".topic_content_1").css("display", "none");
        $(".topic_content_3").css("display", "none");
        $(".topic_content_2").css("display", "block");
        $("#topic_middle").slideDown("slow");
      });
    }
  }
}

function topic_3(){
  $("#open").html("close");
  $("#open_str").css("background", "url(/imgs/close_str.jpg)");
  if($("#topic_middle").css("display") == "none"){
    $(".topic_content_3").css("display", "block");
    $("#topic_middle").slideDown("slow");
  } else {
    if($(".topic_content_3").css("display") == "none"){
      $("#topic_middle").slideUp("slow", function(){
        $(".topic_content_1").css("display", "none");
        $(".topic_content_2").css("display", "none");
        $(".topic_content_3").css("display", "block");
        $("#topic_middle").slideDown("slow");
      });
    }
  }
}

function close_all_topics(){
  $("#open").html("open");
  $("#open_str").css("background", "url(/imgs/open_str.jpg)");
  if($("#topic_middle").css("display") != "none"){
    $("#topic_middle").slideUp("slow", function(){
      $(".topic_content_1").css("display", "none");
      $(".topic_content_2").css("display", "none");
      $(".topic_content_3").css("display", "none");
    });
  }
}



$(document).ready(function(){
  pic1 = new Image(1017,410);	pic1.src = "/imgs/topic_bg.jpg";
  pic2 = new Image(243,288);	pic2.src = "/imgs/topic_r_box.jpg";
  pic3 = new Image(8,4);	pic3.src = "/imgs/close_str.jpg";

  $("#follow_us").click(function(){
    window.open("http://twitter.com/global_church/");
  });
  $("#facebook").click(function(){
    window.open("http://www.facebook.com/globalchurch");
  });
  $("#ban_1").click(function(){
    topic_3();
  });
  
  $("#ban_2").click(function(){
    topic_1();
  });
  $("#ban_3").click(function(){
    topic_2();
  });
  $("#open").click(function(){
    if($(this).html() == "open"){
      topic_1();
    } else {
      close_all_topics();
    }
  });
  $("#open_str").click(function(){
    if($("#open").html() == "open"){
      topic_1();
    } else {
      close_all_topics();
    }
  });
  $("#learn_more").click(function(){
    topic_1();
  });
  
  $("#follow_us").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  });
  
  $("#facebook").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  });
  
  $("#give").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  })
  
  $("#learn_more").hover(function(){
    $(this).css("color", "#FAA328");
  }, function(){
    $(this).css("color", "#FFF");
  });
  
  $("#ban_1").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  });
  
  $("#ban_2").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  });
  
  $("#ban_3").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  });
  
  $("#giving_form_1").submit(function(){
    if(!$("#radio1_1").is(":checked") && !$("#radio1_2").is(":checked") && !$("#radio1_3").is(":checked") && !$("#radio1_4").is(":checked")){
      alert("Please, select amount");
      return false;
    }
    if($("#radio1_4").is(":checked") && $("#radio1_5").attr("value") == ""){
      alert("Please, enter amount");
      return false
    }
    if(!$("#radio2_1").is(":checked") && !$("#radio2_2").is(":checked") && !$("#radio2_3").is(":checked")){
      alert("Please, select giving frequency");
      return false;
    }
  });
  
  $("#give_submit").hover(function(){
    $(this).css("background-position", "bottom");
  }, function(){
    $(this).css("background-position", "top");
  });
  
  $("#card_type_select").change(function(){
    if($(this).attr("value") == 'Paypal'){
      $("#give_option").slideUp("slow");
    } else {
      if($("#give_option").css("display") == 'none'){
        $("#give_option").slideDown("slow");
      }
    }
  });
  
  $("#givingForm").submit(function(){
    var i = 0;
    $(".mandatory1").each(function(){
      if($(this).attr("value") == ""){
        i++;
      }
    });
    if(i > 0){
      alert("All mandatory fields must be field in");
      return false;
    }
    if($("#card_type_select").attr("value") != 'Paypal'){
      var j = 0;
      $(".mandatory2").each(function(){
        if($(this).attr("value") == ""){
          j++;
        }
      });
      if(j > 0){
        alert("All mandatory fields must be field in");
        return false;
      }
      if($("#exp_month_sel").attr("value") == "" || $("#exp_year_sel").attr("value") == ""){
        alert("All mandatory fields must be field in");
        return false;
      }
    }
    var email = $("#email_input").attr("value");
    if(email != ''){
      var pos1 = email.indexOf("@");
      var pos2 = email.indexOf(".");
      if(pos1 == -1 || pos_2 == -1){
        alert("Please enter a valid email address");
        return false;
      }
    }
  });
  
  $("#cvv_desc").click(function(){
    $("#cvv_popup").slideDown("slow");
  });
  
  $("#popup_close").click(function(){
    $("#cvv_popup").slideUp("slow");
  });
  
  
  
  
})

