$(function() {

  // tab slider for feedback form
	$('.feedback-panel').tabSlideOut({
	     tabHandle: '.feedback-handle',                              //class of the element that will be your tab
	     pathToTabImage: '../pornmail/images/tab_feedback.png',          //path to the image for the tab (optionaly can be set using css)
	     imageHeight: '100px',                               //height of tab image
	     imageWidth: '35px',                               //width of tab image
	     tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
	     speed: 300,                                        //speed of animation
	     action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
	     topPos: '210px',                                   //position from the top
	     fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
	 });

  // tab slider for newsletter subscribe form
     $('.subscribe-panel').tabSlideOut({
	     tabHandle: '.subscribe-handle',                              //class of the element that will be your tab
	     pathToTabImage: '../pornmail/images/tab_emailnews.png',          //path to the image for the tab (optionaly can be set using css)
	     imageHeight: '100px',                               //height of tab image
	     imageWidth: '35px',                               //width of tab image
	     tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
	     speed: 300,                                        //speed of animation
	     action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
	     topPos: '320px',                                   //position from the top
	     fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
	 });

  $('.close-feedback').click(function(){$('.feedback-handle').click();});
  $('.close-subscribe').click(function(){$('.subscribe-handle').click();});

  // general form functions
	$('.error').hide();
	$('input.text-input').css({backgroundColor:"#FFFFFF"});
	$('input.text-input').focus(function(){
		$(this).css({backgroundColor:"#FFDDAA"});
	});
	$('input.text-input').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
	});

  // action for feedback form
  $(".but_feedback").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();

	  var em_name = $("input#em_name").val();
		if (em_name == "") {
      $("label#em_name_error").show();
      $("input#em_name").focus();
      return false;
    }
		var em_email = $("input#em_email").val();
		if (em_email == "") {
      $("label#em_email_error").show();
      $("input#em_email").focus();
      return false;
    }
        var em_msg = $("textarea#em_msg").val();
		if (em_msg == "") {
      $("label#em_msg_error").show();
      $("textarea#em_msg").focus();
      return false;
    }

    var em_ip = $("#em_ip").val();
    var em_sitename = $("#em_sitename").val();
    var em_username = $("#em_username").val();

    var dataString = 'em_name=' + em_name + '&em_email=' + em_email + '&em_ip=' + em_ip + '&em_sitename=' + em_sitename + '&em_username=' + em_username + '&em_msg=' + em_msg;
		//alert (dataString);return false;

		$.ajax({
      type: "POST",
      url: "pornmail/postfeedback.php",
      data: dataString,
      success: function() {
        $('#feedback_form').html("<div id='feedback_message'></div>");
        $('#feedback_message').html("<h2>Feedback Sent!</h2>")
        .hide()
        .fadeIn(1500, function() {
          $('#feedback_message');
        });
      }
     });
    return false;
	});

  // action for newsletter subscribe form
  $(".but_subscribe").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();

		var em_subemail = $("input#em_subemail").val();
		if (em_subemail == "") {
      $("label#em_subemail_error").show();
      $("input#em_subemail").focus();
      return false;
    }

    var em_formtype = $("#em_formtype").val();

    if ($('#em_opt_daily').attr('checked')) {
      var em_opt_daily =1;
    }
    else
      var em_opt_daily =0;

    if ($('#em_opt_news').attr('checked')) {
      var em_opt_news =1;
    }
    else
      var em_opt_news =0;

    var em_ip = $("#em_ip").val();
    var em_sitename = $("#em_sitename").val();
    var em_username = $("#em_username").val();

    var dataString = 'em_subemail=' + em_subemail + '&em_ip=' + em_ip + '&em_sitename=' + em_sitename + '&em_username=' + em_username + '&em_formtype=' + em_formtype + '&em_opt_daily=' + em_opt_daily + '&em_opt_news=' + em_opt_news;
		//alert (dataString);return false;

		$.ajax({
      type: "POST",
      url: "pornmail/postsubscribe.php",
      data: dataString,
      success: function() {
        $('#subscribe_form').html("<div id='subscribe_message'></div>");
        $('#subscribe_message').html("<h2>Thank you for Subscribing!</h2>")
        .append("<p>A confirmation email with a verification link has been sent to your email address. Please click the link in the email to complete this subscription process.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#subscribe_message');
        });
      }
     });
    return false;
	});

});