﻿function init() {
    centraliza();
    $(window).resize(centraliza);

    browser = $.browser.browser();
    so = $.browser.OS();
    try { versao = $.browser.version.string(); } catch (e) { versao = ""; }

    //$(".so").html(so);
    $(".navegador").html(browser + " (" + versao + ")");

}
function centraliza(ev) { var escopo = ev ? ev.target : window, t = { w: $(escopo).width(), h: $(escopo).height() }, $e = $(".playVideo"), pos = { top: ((t.h - $e.height()) / 2), left: ((t.w - $e.width()) / 2) }; $e.css(pos); $(".resolucao").html(t.w + " x " + t.h); }
function getUrl(ev) { ev.preventDefault(); var referencia = $(ev.target).attr("id"), pars = { browser: $(".navegador").html(), so: $(".so").html(), referencia: referencia, resolucao: $(".resolucao").html() }; $.ajax({ data: JSON.stringify(pars), url: "http://www.sepi.unip.br/videointerativa/ws/wsLog.asmx/GetCaminhoVideo", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", cache: false, success: function(json) { if (json.d) referencia == "Silverlight" ? window.location = json.d : iniciaBandaLarga(); else alert("erro ao carregar o caminho do vídeo. Por favor, tente novamente."); }, error: function() { alert("Erro. Por favor, tente novamente!"); } }); }
var Url = {
    encode: function(string) { return escape(this._utf8_encode(string)); },
    decode: function(string) { return this._utf8_decode(unescape(string)); },
    _utf8_encode: function(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; },
    _utf8_decode: function(utftext) { var string = "", i = 0, c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; }
};

function iniciaBandaLarga() {
    var win = null;
    var nome = window.location.search;
    nome = nome.substr(nome.lastIndexOf("?") + 1);
    nome = nome.replace(/(&chat=[01])/gi, "");
    nome = Url.decode(nome);

    LeftPosition = (screen.width) ? (screen.width - 770) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - 500) / 2 : 0;

    settings = "height=500, width=770, top=" + TopPosition + " ,left=" + LeftPosition + " ,scrollbars=no, resizable=no"
    //if(nome.substr(0,3).toLowerCase()!="sei" && nome.substr(0,3).toLowerCase()!="sep") nome = "sepi/" + nome;
    if (!nome.match(/(\/)/)) nome = "sepi/" + nome;
    var idCurso = $(".valor").val();
    idCurso = idCurso.replace(/.{0,}(IdCurso=)(.{0,})(&URLVideo).{0,}$/gi, '$2');

    var linkVideo = "http://videoaula.sepi.unip.br/mediavideo.html?url=http://tvweb.unip.br/unip_interativa/&estreita=" + nome + "&larga=" + nome + "&idCurso=" + idCurso;
    //var linkVideo = "http://www.curso-objetivo.br/tvweb/mediavideo2.html?" + nome;
    //"http://www.curso-objetivo.br/tvweb/mediavideo2.html?url=http://tvweb.objetivo.br/videos/TVWEB/Objetivo/Curso/Atualidades_ONLINE/&estreita=" + nome + "&larga=" + nome;
    //alert(linkVideo);

    linkVideo = linkVideo.replace(/(ism\/manifest)/gi, "wmv");
    if (navigator.appName.indexOf("Microsoft") == 0) win = window.open(linkVideo, "janelaVideo", settings);
}

$(init);




