// return the relative root of the site, such as '../..'
function findSiteRoot() {
  // find the first script tag embedded on the page
  var scripts = document.getElementsByTagName("script");
  if (!scripts || !scripts.length) return '';
  var src = scripts[0].getAttribute("src");

  if (src.search(/\/js/) !== -1) {
    src = src.replace(/\/js.*/, '');
  } else {
    src = ".";
  }

  return src;
}

// are we using relative pathing, or absolute pathing?
function isRelative() {
  return (findSiteRoot() !== '');
}


$(function() {
  // Set a cookie so we won't see the splash page in future.
  $.cookie('seen_splash', true);

  // If we find the placeholder map (contact page), replace it with Google map
  var static_map = $('#staticContactMap');
  if (static_map.size() > 0) {
    var live_map = $('<iframe width="482" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Second+Story,+Portland&amp;sll=37.0625,-95.677068&amp;sspn=49.490703,81.914062&amp;ie=UTF8&amp;cid=3442432815194950935&amp;ll=45.551894,-122.672868&amp;spn=0.012021,0.020685&amp;z=15&amp;iwloc=A&amp;output=embed"></iframe>');
    static_map.replaceWith(live_map);
  }

  // Bind mouse handlers for homepage project rollovers
  $(".playlist_overview_thumbs a").bind("mouseenter",function(){
    var element_id = this.id.replace(/workthumb/g,'worklist');
    $("a#" + element_id).addClass("highlight");
  }).bind("mouseleave",function(){
    var element_id = this.id.replace(/workthumb/g,'worklist');
    $("a#" + element_id).removeClass("highlight");
  });
  $(".playlist_overview_list a").bind("mouseenter",function(){
    var element_id = this.id.replace(/worklist/g,'workthumb');
    $("a#" + element_id).addClass("highlight");
  }).bind("mouseleave",function(){
    var element_id = this.id.replace(/worklist/g,'workthumb');
    $("a#" + element_id).removeClass("highlight");
  });

  // only include custom tooltips on IE if we have version 7+
  if (!$.browser.msie || ($.browser.version >= 7)) {
    // Bind mouse handlers for project finder THUMB toolips
    $(".projects .project_thumb_item").bt({
      contentSelector: '$("#tooltip_" + $(this).attr("id")).html()',
      fill: "#3d3f38",
      spikeLength: 15,
      spikeGirth: 0,
      strokeWidth: 0,
      cornerRadius: 0,
      trigger: ['hoverIntent'],
      hoverIntentOpts: {
        interval: 100,
        timeout: 250
      },
      closeWhenOthersOpen: true,
      positions: ['right', 'left']
    });

    // Bind mouse handlers for project finder LIST toolips
    $(".projects .row").bt({
      contentSelector: '$("#tooltip_" + $(this).attr("id")).html()',
      fill: "#3d3f38",
      spikeLength: 20,
      spikeGirth: 0,
      strokeWidth: 0,
      cornerRadius: 0,
      trigger: ['hoverIntent'],
      hoverIntentOpts: {
        interval: 100,
        timeout: 250
      },
      closeWhenOthersOpen: true,
      positions: ['top', 'bottom'],
      width: '400px',
      cssClass: 'project_list_tooltip'
    });
  }

  // Bind mouse handlers for slideshow image rollovers
  $(".ssDetail .ssImage").bind("mouseenter",function(){
    $("h3.record_summary").addClass("record_summary_highlight");
    $(".ssText .link_1").addClass("link_1_highlight");
  }).bind("mouseleave",function(){
    $("h3.record_summary").removeClass("record_summary_highlight");
    $(".ssText .link_1").removeClass("link_1_highlight");
  });

  // For ie6, bind handler for rollovers of next and prev buttons
  if ($.browser.msie && ($.browser.version < 7)) {
    $(".btnNext").bind("mouseenter", function() {
      $(this).addClass("btnNextActivate");
    }).bind("mouseleave",function(){
      $(this).removeClass("btnNextActivate");
    });

    $(".btnPrev").bind("mouseenter", function() {
      $(this).addClass("btnPrevActivate");
    }).bind("mouseleave",function(){
      $(this).removeClass("btnPrevActivate");
    });

  }


});
