// MASTER JS
jQuery(document).ready(function($){
   var urlroot = ips.system.urlroot;
   var code = []; // Array for code pushes.
   $(document).keyup(function(event){
    if (code[1]) { // third esc will activate directedit
      var loc = window.location + "";
      if (loc.indexOf('edit') !== -1) {
         window.location = loc + ";nocache=true;";
         return;
      }
      if (loc.indexOf('?') !== -1) {
         window.location = loc + ";template=edit";
      } else {
         window.location = loc + "?template=edit;";
         return;
      }
    } else if (event.keyCode === 27) {
        code.push(event.keyCode);
    } 
   });

   // SEARCH FORM - jquery 1.3.3 supports event delegation on focus/blur/submit
   var $searchForm = $("#searchForm"), //CACHE
       $query = $searchForm.find(".query"),
       $label = $searchForm.find("label");
   if ($query.val() !== "") {$label.hide()}
   $searchForm.submit(function(){
   if ($query.val() === "") {return false}
   });
   $query.focus(function(){$label.hide()}).blur(function(){
     if ($(this).val() === "") {$label.show()}
   });
   $searchForm.find("label").click(function(){
    $query.focus();
   });
   // LOAD AJAX 
   $(".ajax").each(function(){
       var $this = $(this).addClass('loading').text('Loading...'),
           _rel = $this.attr('rel'),
           _get = _rel ? _rel : 'action',
           _url = $this.attr('href') + ";get=" + _get;
       $.get(_url, function(data){
           $this.replaceWith(data);
       });
   });
   // LOAD AJAX from click
   $(".live").live("click", function(event){
       event.preventDefault();
       var $this = $(this),_rel = $this.attr("rel"),_href=$this.attr("href");
       $(_rel).addClass("loading").load(_href + ";get=content;").removeClass("loading");
   });

   // EVENT DELEGATION - Not touching dom until click
    $(".externalLink").live("click", function(){
      $(this).attr("target", "_blank");
    });
});
jQuery(window).load(function(){
    function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
    }
    //Readjust height after images have loaded.
    equalHeight(jQuery(".height"));
});