// javascript for adigi's site
// asnyc inner page loading and lightbox using jQuery

var g = {
  frame_id: "#content",
  frame_link_id: ".framelink",
  frame_default_url: "about.html",
  hover_id: ".hover",
  hover_suffix: "-hover.",
  on_resize: function() {
    $("#content").css("height", window.innerHeight-300);
  },
  on_load_frame: function() {
    $('a[@rel*=modalPanel]').modalPanel();
  }
};

function load_frame (url) {
  if(!url) {
    url = g.frame_default_url;
  } else {
    if("#" === url[0]) // strip leading hash
      url = url.substr(1);
  }
  $.ajax({
    method: "get",
    url: url,
    success: function(response) {
      document.location.hash = "#" + url;
      $(g.frame_id).html(response);
      if(g.on_load_frame)
	g.on_load_frame();
    }});
};

$(document).ready(function() {
  if(g.on_resize)
    g.on_resize();
  load_frame(document.location.hash ? document.location.hash : undefined);
});

$(window).resize(function(){
  if(g.on_resize)
    g.on_resize();
});

$(function() {
  $("img").filter(g.hover_id).hover(function() {
    $(this).attr("src", $(this).attr("src").split(".").join(g.hover_suffix));
  },
  function() {
    $(this).attr("src", $(this).attr("src").split(g.hover_suffix).join("."));
  });

  $("a").filter(g.frame_link_id).click(function(event) {
    load_frame($(this).attr("href"));
    event.preventDefault();
  });
});



