var LazyLoader = {}; //namespace
LazyLoader.timer = {};  // contains timers for scripts
LazyLoader.scripts = [];  // contains called script references
LazyLoader.load = function(url, callback) {
	// handle object or path
	 var classname = null;
	 var properties = null;
	 try {
     	// make sure we only load once
	  if ($A(LazyLoader.scripts).indexOf(url) == -1) {
     // note that we loaded already
     LazyLoader.scripts.push(url);
       var script = document.createElement("script");
       script.src = url;
       script.type = "text/javascript";
       $$("head")[0].appendChild(script);  // add script tag to head element
    
       // was a callback requested
       if (callback) {    
               // test for onreadystatechange to trigger callback
               script.onreadystatechange = function () {
                       if (script.readyState == 'loaded' || script.readyState == 'complete') {
                               callback();
                       }
               }                            
               // test for onload to trigger callback
               script.onload = function () {
                       callback();
                      return;
               }
               // safari doesn't support either onload or readystate, create a timer
               // only way to do this in safari
               if ((Prototype.Browser.WebKit && !navigator.userAgent.match(/Version\/3/)) || Prototype.Browser.Opera) { // sniff
                       LazyLoader.timer[url] = setInterval(function() {
                               if (/loaded|complete/.test(document.readyState)) {
                                       clearInterval(LazyLoader.timer[url]);
                                       callback(); // call the callback handler
                               }
                       }, 10);
               }
	           }
	   } else {
	           if (callback) { callback(); }
	   }
  } catch (e) {
          alert(e);
  }

}
document.observe('dom:loaded', shrinkImages);


function shrinkImages(){
	$$(".home .post p img").each(function(img){
		shrinkImage(img);
		img.observe("load", function(e){
			shrinkImage(img);
		});
	});
}
function shrinkImage(img){
	if(img.getWidth()>280) img.style.width = "280px";
}
function email(subject){
	alert("emailing about " + subject)
}
//document.observe('dom:loaded', function() {
//
//    // add prettyprint class to all <pre><code></code></pre> blocks
//    var prettify = false;
//    $$("code").each(function(block) {
//        block.addClassName('prettyprint');
//        prettify = true;
//    });
//		if ( prettify ) {
//		        LazyLoader.load("/javascripts/prettify.js", function() { prettyPrint() });
//		   }
//
//
//
//});
