// detect IE
var _isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0) ? true : false;
// globals for Wistia Player
var _wLoaded = false;
var _wTimer = null;

// show a lightbox immediately
// params should be an object with any of the following properties:
//  id - the id of the thread or other content to show
//  type - the type of content to show
//  width - the width of the content (in pixels)
//  height - the height of the content (in pixels)
//  title - a title to display with the content
//  fancybox - an object containing additional options to pass to fancybox
function showLightBox(params) {
  // set default options
  title = params['title'];
  type = params['type'];
  if (type == undefined) type = 'swf';
  width = params['width'] || 800;
  height = params['height'] || 550;
  // get code for the contents
  html = embedCode(params['id'], type, width, height);
  // do setup for the Wistia player
  if ((type == 'wvideo') || (type == 'wvideo1'))
    loadWPlayer();
  // add default fancybox options
  options = {
    'hideOnContentClick': false,
    'titleShow': (title != undefined),
    'titleFormat': function() { return(title); }
  }
  moreOptions = params['fancybox'];
  for (var p in moreOptions) {
    options[p] = moreOptions[p];
  }
  // show the lightbox
  $("a#fblink", parent.document.body).fancybox(options);
  $('#fbcontent').html(html);
  $('#fblink', parent.document.body).click();
}

// compatibility interface for old lightbox code
function lightBox(id, unused, doc_text, embed_type, width, height) {
  showLightBox({
    'id': id,
    'type': embed_type,
    'width': width,
    'height': height,
    'title': doc_text
  });
}

function loadWPlayer() {
  
  src1 = document.createElement("script");
  src1.src = "http://static.wistia.com/playlists/playlist.js";
  src1.type = "text/javascript";
  append = document.body.appendChild(src1);
  src2 = document.createElement("script");
  src2.src = "http://embed.wistia.com/embeds/v.js";
  src2.type = "text/javascript";
  document.body.appendChild(src2);
  
	if (_wLoaded) return(false);
	try {
		if (Wistia) {
			src3 = document.createElement("script");
			src3.src = "http://app.wistia.com/embed/playlists/ab6c6a483a.js?theme=trim&playthrough=true&autoplay=true";
			document.body.appendChild(src3);
			clearTimeout(_wTimer);
		}
	} catch (e) {
		_wTimer = setTimeout(loadWPlayer, 20);
	}
}

// get embed code for lightbox content
function embedCode(id, embed_type, width, height) {
  
  // detect if plugin exists
  hasPlugin = detectPlugin(embed_type);
  
  if (!hasPlugin) {
    vt_embed_code = 'You do not have the '+embed_type+' plug-in installed or you have JavaScript disabled. '+
    'Please correct this error and try again.';
  }
  else if (embed_type == 'customFlash') {
    
    vt_embed_code = '<embed src="'+id+'" '+
    'type="application/x-shockwave-flash" wmode="transparent" quality="high" play="true" scale="showall" menu="true" devicefont="false" allowscriptaccess="sameDomain" '+
    'width="'+width+'" height="'+height+'" style="width:'+width+'px; height: '+height+'px;"><\/embed>';

  }
  else if (embed_type == 'quicktime') {
    vt_embed_code = '<embed src="'+id+'" '+
    'type="video/quicktime" autoplay="true"'+
    'width="'+width+'" height="'+height+'" cache="true" style="margin-top: 20px; width:'+width+'px; height: '+height+'px; background: transparent;"><\/embed>'; 
  }
  else if (embed_type == 'vimeo1') {
    vt_embed_code = '<iframe src="http://player.vimeo.com/video/'+id+'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff&amp;autoplay=1" '+
    'width="'+width+'" height="'+height+'" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'; 
  }
  else if (embed_type == 'image') {
    vt_embed_code = '<img src="'+id+'" style="width:'+width+'px; height: '+height+'px;" />';  
  }
  else if ((embed_type == 'flash') || (embed_type == 'swf')) {
    vt_embed_code = '<div style="padding: 10px 0 0 0; '+
      'width: '+width+'px; height: '+(height + 10)+'px; overflow: hidden;">'+
      '<object width="'+width+'" height="'+height+'">'+
        '<param name="movie" value="/book.swf?b='+id+'&autoplay=1"></param>'+
        '<param name="wmode" value="transparent"></param>'+
        '<embed src="/book.swf?b='+id+'&autoplay=1" '+
          'type="application/x-shockwave-flash" wmode="transparent" '+
          'width="'+width+'" height="'+height+'"></embed>'+
      '</object>'+
      '</div>';
  }
  else if (embed_type == 'wvideo1') {
    vt_embed_code = '<div id=\'slimlist_36702\' style=\'width:'+width+'px;height:'+height+'px;text-align:left;margin-top: 40px; margin-left: 25px;\'><span style=\'padding:.5em 1em;background:#fff;color:#bbb;font-size:12px;\'>Please wait while loading ...</span></div>';
  }
  else
    vt_embed_code = 'We could not load the content. We apologize for the inconvenience.';
    'width="'+width+'" height="'+height+'"><\/embed>';
                    
  // return the code
  return(vt_embed_code);
}

// detects if plugin is installed on system
function detectPlugin(ref) {
	ieTest = mozTest = null;
	if (ref == 'quicktime') {
		ieTest = 'QuickTimeCheckObject.QuickTimeCheck.1';
		mozTest = 'QuickTime';
	} else if ((ref == 'flash') || 
             (ref == 'swf') || 
             (ref == 'customFlash')) {
		ieTest = 'ShockwaveFlash.ShockwaveFlash.1';
		mozTest = 'Shockwave Flash';
    ref = 'flash';
	}
	else if (ref == 'image') {
		return(true);
	}
	else if (ref == 'wvideo1') {
		return(true);
	}
	else if (ref == 'vimeo1') {
		return(true);
	}
	if (_isIE) {
		return(true);
	}
	else if (navigator.plugins) {
		for (i=0; i < navigator.plugins.length; i++ ) {
			if (navigator.plugins[i].name.toLowerCase().indexOf(ref) >= 0)
				return(true);
		}
		return(false);
	}
	return(false);
}

-->

