// handle flash telling us to show, passing it's size metrics
function slideshowShow(visible, width, height){

}

function onProjectDetail() {
  var pathname = window.location.pathname;
  if (pathname.indexOf('/portfolio/lists') !== -1) {
    return false;
  } else {
    return true;
  }
}

// handle a click on a slideshow; method triggered by slideshow player
function slideshowClick(alias) {
  if (alias == 'studio-profile') return;
  var site_root = findSiteRoot();
  var url = site_root + '/portfolio/works/' + alias;
  if (window.location.pathname.search(/[.]html$/) !== -1) {
    url += ".html";
  }
  if (! onProjectDetail() ) {
    window.location = url;
  }
}

// handle a hover event on a slideshow; method triggered by slideshow player
function slideshowHover(alias) {
}

function embedSlideshows() {
  var site_root = findSiteRoot();

  // determine whether we are on a 'project detail' or not using path
  var projectDetail = onProjectDetail();
  var isRelativeRoot = isRelative();

  // Activate any slideshows on the page
  $('.player').each(function() {
    var player_id = this.id;
    var work_alias = player_id.replace('player_', '');
    var width = $('.ssDetail').width();

    var baseUrl = site_root;
    if (baseUrl !== '') {
      baseUrl = site_root + "/srv";
    }

    var flashvars = {
      baseUrl: baseUrl,
      dataUrl: site_root + "/srv/works/" + work_alias + ".xml",
      configUrl: site_root + "/player/config.xml",
      projectDetail: projectDetail,
      isRelative: isRelativeRoot
    };
    var params = {
      menu: "false",
      bgcolor: "#000000",
      wmode: 'opaque',
      allowScriptAccess: "always"
    };
    var swf_path = site_root + "/player/slideshowplayer.swf";
    swfobject.embedSWF(swf_path, player_id, width, 365, "9.0.0", "expressInstall.swf", flashvars, params);
  });
}

function revealSlideshow() {
  $('.poster').hide();
}

// called by flash slideshow when it is ready to be displayed
function slideshowReady() {
  revealSlideshow();
}

// called by flash slideshow when thinks it has been viewed
function slideshowComplete() {
  $('.listDetail .btnNext').addClass('btnNextActivate');
}

// if the user clicks a link with target=_blank, pause the slideshow
function pauseSlideshowOnExternalLinks() {
  $('a[target="_blank"]').click(function () {
    pauseSlideshow();
  });
}

// use externalinterface to pause the slideshow
function pauseSlideshow() {
  var swfs = $('.playerContainer object');
  if (swfs.length && swfs[0].pauseSlideshow) {
    swfs[0].pauseSlideshow();
  }
}

$(function() {

  // regrettable hack: adding border fixes peekaboo flash bug in Firefox Mac
  if (navigator && navigator.userAgent) {
    var userOSAgent = navigator.userAgent.toLowerCase();
    jQuery.platform = {
      mac: /mac/.test(userOSAgent),
      osx: /mac os x/.test(userOSAgent),
      win: /win/.test(userOSAgent),
      linux: /linux/.test(userOSAgent)
    };

    if ($.browser.mozilla && $.platform.mac) {
      $('.poster img, img.poster').css('border-bottom', '1px solid black');
    }
  } // end regrettable hack

  setTimeout('embedSlideshows()', 100);
  pauseSlideshowOnExternalLinks();
});

