var attrib = {
  id:'player',
  width:'450',
  height:'392',
  movie:'http://content.fliqz.com/components/885ff52cd63341caa567f0e90d2dde02.swf',
  allowFullScreen:'true',
  type:'application/x-shockwave-flash',
  pluginspage:'http://www.macromedia.com/go/getflashplayer'
};

var vids = {
  standard: [{vid:'file=821b5481619f4a179d9704a336e4bc75&', caption:'Standard Video Tour'}],
  basic: [{vid:'file=4CEC6C3566B6793CD47A3E65BF2C4B28&', caption:'Basic Video Tour'}],
  about: [{vid:'file=392b3b7941cc7cde4349b465fe92475d&', caption:'MyNewPlace Video Tours'}]
};

function createPlayer(target, fv, caption) {
  var env = $(target);
  var flashSupport = getFlashSupport();

  if (flashSupport[0] < 9) {

    var msg = $E("p", {
      parentNode:env,
      className: "error",
      text: "Video Tours require Adobe Flash Player 9."
    });

  } else {
    var cptn = $E("div", {id:"caption",par: env});
    cptn.innerHTML = '<strong>Now Playing: ' + caption + '</strong>';

    if (MNP.Browser.IE) {
      var emed = $E("embed", {
        parentNode: env,
        attributes:{
          id: attrib.id,
          src: attrib.movie,
          width: attrib.width,
          height: attrib.height,
          allowFullScreen: attrib.allowFullScreen,
          wmode: attrib.wmode,
          flashvars: fv,
          type: attrib.type,
          pluginspage: attrib.pluginspage
        }});
    } else {
      var obj = $E("object", {
        parentNode: env,
        attributes: {
          id: attrib.id,
          data: attrib.movie + '?' + fv,
          width: attrib.width,
          height: attrib.height,
          type: attrib.type
        }});
      var param = $E("param", {
        parentNode: obj,
        attributes: {
          name: "movie",
          value: attrib.movie + '?' + fv
        }});

    }
  }
}


function popup(e) {
  Event.stop(e);
  var el = Event.findElement(e,"a");
  var i = el.vid;

  if (i) {
    var elpop = $E("div", {className:"playerEnv"});
    Mbox.show(elpop, {className:"abox",closer:true,screen: {cancel: true,opacity: .35},s_class: "smoke", autoSize:1,
      afterFinish: function() {
        createPlayer(elpop, i.vid, i.caption);
      } });
  }
}


function initPage() {
  var vidmap = [];
  for (vid in vids) {
    vidmap.push(vid);
  }

  var tds = $T("td", "playrow");
  for (var i = 0; i < tds.length; i++) {
    var td = tds[i];
    var vidtype = vids[vidmap[i]];
    for (ovid in vidtype) {
		        if (vidtype.hasOwnProperty(ovid)) {

      var vid = vidtype[ovid];
      var link0 = $E("a", {
        text: "View Sample",
        par: td,
        attributes:{
          href:"#"
        }});
      link0.vid = vid;
      Event.observe(link0, "click", popup);
				}
    }
  }

  var imgs = $T("img", "vidsample");
  for (var i = 0; i < imgs.length; i++) {
    var img = imgs[i];
    img.vid = vids[vidmap[i]][0];
    img.style.cursor = "pointer";
    Event.observe(img, "click", popup);
  }
  
  var hero = $("hero_image");
  if (hero) {
  	var heroLink = $T("a",hero)[0];
  	if (heroLink) {
		heroLink.vid = vids["about"][0];	
	}
  }

}


function getFlashSupport() {
  var ver = [0,0];
  if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
    var _d = navigator.plugins["Shockwave Flash"].description;
    if (typeof _d != "undefined") {
      _d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
      var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
      var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
      ver = [_m, _r];
    }

  } else if (window.ActiveXObject) {
    try {
      var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
      var _d = _a.GetVariable("$version");// bugs in fp 6.21/6.23
      if (typeof _d != "undefined") {
        _d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
        ver = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
      }
    }
    catch(e) {
    }
  }

  return ver;
}


if (MNP.Browser.script) {
  addLoadEvent(initPage);
}
