$(document).ready(function() {
  var starting_s, starting_e;
  
  $('.font10').click(function() {
    $('#content').css('fontSize', '13px');
  });
  
  $('.font12').click(function() {
    $('#content').css('fontSize', '14px');
  });
  
  $('.font14').click(function() {
    $('#content').css('fontSize', '15px');
  });
  
  if($.browser.opera) {
    $('body').css('fontSize', '12px');
  }
  
  if($.browser.msie && $.browser.version <= 6) {
    $('ul#suckerfishnav li').mouseover(function() {
      $(this).addClass('sfhover');
    }).mouseout(function() {
      $(this).removeClass('sfhover');
    });
  }
  $('#suckerfishnav li li:has(ul)').addClass('haschild');
  
  
  starting_s = $('#s').val();
  
  $('#s').focus(function() {
    if($(this).val() == starting_s) {
      $(this).val('');
    }
  });
  
  $('#s').blur(function() {
    if($(this).val() == '') {
      $(this).val(starting_s);
    }
  });
  
  starting_e = $('#newsemail').val();
  
  $('#newsemail').focus(function() {
    if($(this).val() == starting_e) {
      $(this).val('');
    }
  });
  
  $('#newsemail').blur(function() {
    if($(this).val() == '') {
      $(this).val(starting_e);
    }
  });
  
  $('.widget_rss a').attr("target", "_blank");
  
  $('.moreinfo li:has(ul)').addClass('haschildclosed').find('ul').addClass('closed');
  
  $('.moreinfo li.haschildclosed > a').live('click', function(event) {
    //var pos_x;
    
    //pos_x = event.offsetX ? (event.offsetX) : event.pageX - $(this).offsetLeft;
    
    //if(pos_x > 165) {
    
      $(this).parent().removeClass('haschildclosed').addClass('haschildopen')
      .children('ul').slideDown(500, function() {
        $(this).removeClass('closed').addClass('open');
      });

      return false; 
    //}
  });
  
  //open any closed parents of the current page
  $('.moreinfo .haschildclosed').has('.current_page_item').children('a').click();
  
  
  $('.moreinfo li.haschildopen > a').live('click', function(event) {
    //var pos_x;
    
    //pos_x = event.offsetX ? (event.offsetX) : event.pageX - $(this).offsetLeft;
    
    //if(pos_x > 165) {
    
      var $parent = $(this).parent();
      $parent.children('ul').slideUp(500, function() {
        $parent.removeClass('haschildopen').addClass('haschildclosed');
        //also close open children
        $parent.find('.haschildopen').each(function() {
          $(this).removeClass('haschildopen').addClass('haschildclosed');
        });
        $parent.find('.open').each(function() {
          $(this).removeClass('open').addClass('closed').hide();
        });
        $(this).removeClass('open').addClass('closed');
      });
      
      return false;
    //}
  });
  
  $('.gfield_checkbox label').html('I agree to Sunridge Medical Center\'s <a href="' + baseurl + '/terms-and-conditions" target="_blank">Terms and Conditions</a>');
  
  $('#newsletter .submit').mouseover(function() {
    $(this).css('backgroundImage', 'url(' + baseurl + '/wp-content/themes/medicaltheme/img/newslettersubmitbghover.jpg)').css('color', '#fff');
  });
  
  $('#newsletter .submit').mouseout(function() {
    $(this).css('backgroundImage', 'url(' + baseurl + '/wp-content/themes/medicaltheme/img/newslettersubmitbg.jpg)').css('color', '#102c40');
  });
  
  $('.gform_footer input').mouseover(function() {
    $(this).attr('src', baseurl + '/wp-content/themes/medicaltheme/img/getsstartedbuttonhover.jpg');
  });
  
  $('.gform_footer input').mouseout(function() {
    $(this).attr('src', baseurl + '/wp-content/themes/medicaltheme/img/getsstartedbutton.jpg');
  });
  
  $('.widget_rss li').each(function() {
    var $link;
  
    $link = $(this).children('.rsswidget').clone();
    $(this).children('.rssSummary').append(
      $link.addClass('morelink').html('more &gt;')
    );
  });
  
  $('#cmForm').ajaxForm(function() {
    $('#cmForm').replaceWith('<p style="text-align:center;height:22px">Thank you for subscribing!</p>'); 
  });
});