// hide all elements that need hidden to start
$(document).ready(function() {
  $('.hide').css('display', 'none');
});
// Add/Remove Poll Option
$(document).ready(function() {
  $('.add_option').click(function() {
    $(this).addPollOption();  
    return false;
  });
});
$(document).ready(function() {
  $('.remove_option').click(function() {
    console.log(this);
  });
});
//Poll Header Mouseover to Results effect
$(document).ready(function() {
  $('#poll_header').mouseover( function() {
    $('#poll_components').css({'top' : -232});
  });
  $('#poll_components_wrap').bind('mouseleave', function() {
    $('#poll_components').css({'top' : 0});
  });
});
// This is the IE6 Js hack for submit button rollovers
$(document).ready(function() {
  $('form .submitbtn').hover(function() {
    $(this).css({"background": "url('../images/submit_button.png') 0px 0px no-repeat"});
    $(this).css({"background": "url('../images/submit_button.png') 0px -42px no-repeat"});
  },
  function() {
    $(this).css({"background": "url('../images/submit_button.png') 0px -42px no-repeat"});
    $(this).css({"background": "url('../images/submit_button.png') 0px 0px no-repeat"});
  });
});
// This is the calculator method
$(document).ready(function() {
  var my_calc_input = $('#calc_input');
  var member_count = 0;
  my_calc_input.bind('keyup', function() {
    member_count = parseInt(my_calc_input.val());
    return member_count;
  });
  
  var my_calc_button = $('#calc_button');
  my_calc_button.bind('click', function() {
    if (member_count <= 0) {
      jAlert('You need to enter the number of members', 'Calculator Error');
    } else {
      var calculation = (parseInt(member_count) * 800);
      $('#calc_return_value').html('$' + calculation + '.00 per year');
      return false;
    }
  });
});
// This is the Flash Notice piece
$(document).ready(function () {
  var flash = $('#flash');
  flash.animate({opacity: '1.0'}, '5000').fadeOut(1000);
});
// This is the Timer for the home page banners
// $(document).everyTime(15000, function () {
//   $('#banner_scroll_r').trigger('click');
// });
// Sets the Main Nav Current Page Selection Tab
$(document).ready(function() {
  var url = location.pathname;
  var current_link = $('#main_nav ul li a[href$="' + url + '"]');
  if (url == "/") {
     current_link.removeClass('active');
     $('.home').addClass('active');
   } else {
   current_link.addClass('active');
   }
});
// Sets the Main Nav Current Page Selection Tab
$(document).ready(function() {
  var url = location.pathname;
  if (url == "/documents") {
    $('#tab3').removeClass('selected');
    $('#tab2').removeClass('selected');
    $('#tab1').addClass('selected');
   } else if (url == "/health-care-fraud-prevention-tools") {
     $('#tab1').removeClass('selected');
     $('#tab3').removeClass('selected');
     $('#tab2').addClass('selected');
   } else if (url == "/health-care-fraud-prevention-links"){
     $('#tab2').removeClass('selected');
     $('#tab1').removeClass('selected');
     $('#tab3').addClass('selected');
   } else {
     $('#tab1').addClass('selected');
   }
});
// This is the tabs for the Resources Page
// $(document).ready(function() {
//   my_tab1 = $('#tab1');
//   my_tab2 = $('#tab2');
//   my_tab3 = $('#tab3');
//   my_pane1 = $('#pane1');
//   my_pane2 = $('#pane2');
//   my_pane3 = $('#pane3');
//   
//   my_pane1.show();
//   my_pane2.hide();
//   my_pane3.hide();
//   
//   my_tab1.bind('click', function() {
//     my_pane1.show();
//     my_tab1.addClass('selected');
//     my_pane2.hide();
//     my_tab2.removeClass('selected');
//     my_pane3.hide();
//     my_tab3.removeClass('selected');
//     return false;
//   });
//   
//   my_tab2.bind('click', function() {
//     my_pane1.hide();
//     my_tab1.removeClass('selected');
//     my_pane2.show();
//     my_tab2.addClass('selected');
//     my_pane3.hide();
//     my_tab3.removeClass('selected');
//     return false;
//   });
//   
//   my_tab3.bind('click', function() {
//     my_pane1.hide();
//     my_tab1.removeClass('selected');
//     my_pane2.hide();
//     my_tab2.removeClass('selected');
//     my_pane3.show();
//     my_tab3.addClass('selected');
//     return false;
//   });
// });
// This is the tabs in the Admin Section
$(document).ready(function() {
  var tabContainers = $('div#admin_tabs > div');
  tabContainers.hide().filter(':first').show();
  
  $('div#admin_tabs ul.admin_nav a').click(function() {
    tabContainers.hide();
    tabContainers.filter(this.hash).show();
    $('div#admin_tabs ul.admin_nav li').removeClass('selected');
    $(this).parent().addClass('selected');
    return false;
  }).filter(':first').click();
});
// Setup modals with jQuery (lightboxes)
$(document).ready(function() {

  // buttons
  main_login_button = $('#login_button');
  whistle_button = $('#whistle_banner_btn');
  victim_button = $('#victim_banner_btn');
  join_button = $('#join_fight_banner_btn');
  sub_blow_button = $('#blow_the_whistle');
  sub_spread_word = $('#spread_the_word');
  counter = $('#counter_box');
  // divs
  my_login_box = $('#login_box');
  my_whistle_box = $('#whistle_box');
  my_join_box = $('#join_box');
  
  my_login_box.hide();
  my_whistle_box.hide();
  my_join_box.hide();
  
  // div setups
  my_login_box.dialog({width: 400, modal: true, resizable: false, autoOpen: false});
  my_whistle_box.dialog({width: 500, modal: true, resizable: false, autoOpen: false});
  my_join_box.dialog({width: 500, modal: true, resizable: false, autoOpen: false});
  
  // actions
  
  main_login_button.click(function() {
    my_login_box.dialog("open");
    return false;
  });
  
  whistle_button.click(function() {
    counter.hide();
    my_whistle_box.dialog("open");
    return false;
  });
  
  victim_button.click(function() {
    counter.hide();
    my_join_box.dialog("open");
    return false;
  });
  
  join_button.click(function() {
    counter.hide();
    my_join_box.dialog("open");
    return false;
  });
  
  sub_blow_button.click(function() {
    counter.hide();
    my_whistle_box.dialog("open");
    return false;
  });
  
  sub_spread_word.click(function() {
    counter.hide();
    my_join_box.dialog("open");
    return false;
  });
});

// Jquery fix for modals
$(document).ready(function() {
  $('.ui-dialog').bgiframe();
  $('.ui-icon-closethick').click(function() {
    $('#counter_box').show();
  })
});

// This is the reviews insertion on create that posts to the database
jQuery.ajaxSetup({
 "beforeSend": function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});
$(document).ready(function() {
  $('#new_review').submit(function() {
    $.post($(this).attr("action"), $(this).serialize(), null, "script");
    return false;
  });
});
// This is the Add Poll field for admin page
jQuery.fn.addPollOption = function() {
  $("#poll_options").append(
    "<p class='poll_option'>Option: <input id='topic_topic_option_attributes__option' type='text' size='30' name='topic[topic_option_attributes][][option]'/> </p>"
    );
  };