function resizeImage() {
  // var wrapper = $$('div.section_image').first();

  var titleImage = $('title_image');
  if (!titleImage){
   return; 
  }
  
  if (titleImage.width > 300) {
    var perc = 300.0 / titleImage.width;
    var h = (titleImage.height * perc) + 'px'
    var w = (titleImage.width * perc) + 'px'
    titleImage.setStyle({'height' : h, 'width' : w})
  }

  // the height must be explicitely set to grab it from the style
  // and it needs to be set in pixels as far as i'm concerned
  // wrapper.height = parseInt(wrapper.getStyle('height'));
  // wrapper.width = parseInt(wrapper.getStyle('width'));
  // 
  // var pic = $$('div.section_image img').first();
  // var diff = parseInt(pic.height) - wrapper.height;
  // var widthDiff = parseInt(pic.width) - wrapper.width;
  // 
  // var topMargin = (-1 * parseInt(diff/2)) + 'px';
  // var leftMargin = (-1 * parseInt(widthDiff/2)) + 'px';
  // 
  // // this will pretty much vertically center the picture
  // pic.setStyle( {'margin-top' : topMargin} );
  // pic.setStyle( {'margin-left' : leftMargin} );
}

function add_form() {
  if ($('ad_form')) { // make sure the form is actually on this page so we don't get an error
    Event.observe('ad_form', 'submit', function(e) {
      form = $('ad_form')
      if(form.ad_ad_type.value != 'text_only') {
          if(form.image_uploaded_data.value == '' && !$$('img.ad_image').first() ) {
              alert('A ' + form.ad_ad_type.value + ' ad requires an image');
              return false;
          }
      }
      if(form.ad_href.value == '') {
        alert('You must provide a valide link URL');
        return false;
      }
    });
  }
}

function get_random_ads() {
  // i need to get the ads after the page has already loaded so i don't have to worry about slowing everything down
  // look at::
  // Ajax.Updater on prototypejs.org/api
}


sfHover = function() {
	var sfEls = document.getElementById("admin_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

// trigger some events when the window loads
Event.observe(window, 'load', function() {
  add_form();
  resizeImage();
  get_random_ads();
});