﻿
var XXX = "xxx";

function RemoveClass(Elem) {
  document.getElementById(Elem).className = "";
}

function ClearText(Elem) {
  document.getElementById(Elem).value = "";
  RemoveClass(Elem);
}

var InsertMovie = function(memberid, sessionid, nodeid, file, logo, placeholder) {

  var currentPosition = 0;
  var currentState = null;
  var lastPing = new Date();
  var thePlayer;

  function hit(action, oldState, newState, position, message, placeholder) {
    var url = "/api/playstathit.ashx" +
      "?u=" + encodeURIComponent(memberid) +
      "&s=" + encodeURIComponent(sessionid) +
      "&g=" + encodeURIComponent(nodeid) +
      "&r=" + encodeURIComponent(file) +
      "&a=" + encodeURIComponent(action) +
      "&o=" + encodeURIComponent(oldState) +
      "&n=" + encodeURIComponent(newState) +
      "&p=" + encodeURIComponent(position) +
      "&e=" + encodeURIComponent(message);
    $.get(url,
      function(data) {
      }
    );
  }

  playerMediaError = function(e) {
    hit('error', e.oldstate, e.newstate, currentPosition, e.message);
  };

  playerMediaTime = function(e) {
    currentPosition = e.position;
    var now = new Date();
    if (now.getTime() - lastPing.getTime() > 10000) {
      hit('ping', currentState, currentState, e.position, '');
      lastPing = now;
    }
  };

  playerState = function(e) {
    currentState = e.newstate;
    hit('state', e.oldstate, e.newstate, currentPosition, '');
  }

  playerViewSeek = function(e) {
    hit('seek', '', '', e.position, '');
  }

  playerReady = function(player) {
    thePlayer = document.getElementById(player.id);
    if (thePlayer) {
      thePlayer.addModelListener('ERROR', 'playerMediaError');
      thePlayer.addModelListener('STATE', 'playerState');
      thePlayer.addControllerListener('SEEK', 'playerViewSeek');
      thePlayer.addViewListener('SEEK', 'playerViewSeek');
      thePlayer.addModelListener('TIME', 'playerMediaTime');
    }
  };

  var flashvars = {};
  flashvars.linkfromdisplay = "true";
  flashvars.autostart = "true";
  flashvars.controlbar = "bottom";
  flashvars.skin = "/flash/modieus.swf";
  flashvars.repeat = "false";
  flashvars.logo = logo;
  //flashvars.playerReadyCallback = this.playerReady;
  flashvars.file = encodeURIComponent(
    "http://rrr.sz.xlcdn.com/?account=exerto" +
    "&file=" + encodeURIComponent(file) +
    "&ref=" + encodeURIComponent(document.location.href) +
    "&type=streaming&service=wowza&protocol=rtmpt&port=80&output=xspf&playlist=xml");

  var params = {};
  params.wmode = "transparent";
  params.menu = "true";
  params.allowscriptaccess = "always";
  params.allowfullscreen = "true";
  params.scale = "exactfit";

  var attributes = {};
  attributes.id = 'jwplayer';
  attributes.name = 'jwplayer';

  swfobject.embedSWF("/flash/player.swf", placeholder, "980", "581", "10", "expressInstall.swf", flashvars, params, attributes);
};

//jQuery
$(document).ready(function () {
    //$("a#logIn").colorbox({ iframe: true, innerWidth: 375, innerHeight: 195 });
    $("a#logIn").colorbox({ innerWidth: 375, innerHeight: 195, inline: true, href: "#loginModal" });
    $("a#RegFree").colorbox({width: 500, height: 270, iframe: true});
});


