jQuery(document).ready(function($) {
   // used for the admin_suite_announcements flash messages
   $('#flash_email, #flash_announcement').dialog({
      bgiframe: true,
      modal: true,
      resizable: false,
      width: 700,
   }).removeAttr('id');
   
   // dynamic state list on country change (classes asCountries, asStates)
   $('.asCountries').change(function(){
      $.get('/admin_suite/admin_suite_users/state_list/' + $(this).val(), function(data) {
         $('.asStates').html(data);
      });
   });
   
   // radio button toggles below divs - used in payment method update
   // @todo jad move it to billing suite
   $('input.toggle').change(function() {
      $('div.toggle').attr('style', 'display:none');
      $('div#' + $(this).val()).attr('style', 'display:block');
   });

   // everything below this line requires the jQuery UI library
   $('.jsHide').hide();
   $('.jsHighlight').effect('highlight', {}, 3000, function(){});

   $('.contextual > span > a').click(function() {
      $($(this).attr('href')).show();
   })
   $(".tabbedContent > ul").tabs();

   // Exit popup
   // @see http://dev.jquery.com/ticket/4106
   window.onbeforeunload = function () { 
      if ($('._conditional').attr('style') == '' && $('.exitPopup').text() && !$('.orderbtn').hasClass('clicked')) {
         // confirms ONLY when conditions are met
         return $('.exitPopupMessage').text();
      }
   }
   $(window).bind("beforeunload", function(){
      // alert($.ajax({url:"http://google.com"}));
      if ($('._conditional').attr('style') == '' && $('.exitPopup').text() && !$('.orderbtn').hasClass('clicked')) {
         $('.ui-dialog-overlay-bg').attr('style', '');
         window.location = $('.exitPopup').attr('href');
      }
   });
   $('.orderbtn').click(function(){
      $('.orderbtn').addClass('clicked');
   })
});