﻿function OfertaMediaPlayer(_key) {
    this.keyAuth = _key; // Chave de Autenticação do WS
    this.mediaType = null; // Indica o Tipo de Media que Deve Tocar
    this.itemToPlay = 0; // Index do Item que Deve ser Executado
    this.totItemProdutos = 0; // Total de Itens que são considerados Produtos (Slide Show)
    this.playOnlyOnePhoto = false; // Indica se Deve tocar apenas 1 foto no slide Show
    this.playAllPhotos = false; // Indica se deve tocar todas as Fotos

    this.hasVideo = false; // Indica se Tem Video para Tocar (Produtos com Time Code quer dizer que tem Video)
    this.hasPhoto = false; // Indica se tem Fotos (Produtos sem Time Code)

    this.playerSlideShow = null;
    this.playerVideo = null;

    this.playerPlaylistClick = null; // Variavel de Controle de Click na playlist button next ou previus page

    // Indica o Tipo de Media que Deve Tocar
    this.SetMediaType = function(_mediaType) {
        this.mediaType = _mediaType;
    }

    this.SetItemToPlayByIdProduto = function(_idProduto) {
        var _indexItemToPlay = null;
        // Procura o Produto
        $('.playinfo').each(function(i) {
            if (_idProduto == $(this).find('#idAnuncioProduto').text()) {
                //_indexItemToPlay = Number($(this).find('#timecode').text());
                _indexItemToPlay = i;
                return false;
            }
        });

        // Mostra o Produto
        OfertaMediaPlayer.SetItemToPlay(_indexItemToPlay);
    }


    this.PlayerGetCurrentTime = function() {
        return this.playerVideo.GetCurrentTime();
    }
 
    // Indica para o Player de Media qual item (produto) deve tocar no momento
    this.SetItemToPlay = function(_index) {
        // Para o Slide Show Atual
        if (this.playerSlideShow != null) {
            this.Pause();
        }
        // Para o Play do Video
        if (this.playerVideo != null) {
            this.Pause();
        }
        this.itemToPlay = _index;
        this.ShowItemInfo(_index);
        // Esconde o Player
        $('#ctl00_content_playerVideoId').attr('style', 'visibility:hidden; position:absolute;');
        // Mostra o Div com as Fotos
        $('#ctl00_content_playerFotoID').attr('style', 'display:block; position:absolute;');
        // Indica que é para exibir todas as Fotos
        this.playAllPhotos = true;
        // Reseta os Totais
        this.ResetTotalItensProdutosEmVideo();
        this.playOnlyOnePhoto = true;
        this.mediaType = 2;
        // Seta a Acao do Botao
        $('#btVerFotosID').attr("href", "javascript: OfertaMediaPlayer.StopOnlyPhoto();");
        $('#btVerFotosID').html("Voltar para Vídeo");

        var idAnuncioProduto = $('.playinfo').eq(_index).find('#idAnuncioProduto').text();
        this.SaveLogProdutoClick(idAnuncioProduto);
        
        // Inicia o Slide Show Novamente
        this.Start();
    }

    // Exibe as Informacoes do item "Produto" indicado
    this.ShowItemInfo = function(_index) {
        // Busca as Informacoes da Imagem
        //var teaser = $('.playinfo').eq(_index).find('#teaser').text();
        var idAnuncioProduto = $('.playinfo').eq(_index).find('#idAnuncioProduto').text();
        var thumb = $('.playinfo').eq(_index).parent().find('img').attr('src');
        var nome = $('.playinfo').eq(_index).find('#nome').text();
        var texto = $('.playinfo').eq(_index).find('#texto').text();
        var preco = $('.playinfo').eq(_index).find('#preco').text();
        var textoPreco = $('.playinfo').eq(_index).find('#textoPreco').text();
        var compre = $('.playinfo').eq(_index).find('#compre').text();
        var timecode = $('.playinfo').eq(_index).find('#timecode').text();
        var categoriaProdutoId = $('.playinfo').eq(_index).find('#categoriaProdutoId').text();
        var categoriaProdutoNome = $('.playinfo').eq(_index).find('#categoriaProdutoNome').text();

        // Seta o Thumb de Imagem
        $('#boxInfoProdutoImg').attr("src", thumb);
        $('#boxInfoProdutoImg').attr("alt", nome + " [Erro ao carregar imagem]");
        $('#boxInfoProdutoImg').attr("title", nome);
        // Seta o Nome do Produto
        $('#boxInfoProdutoTitulo').html(nome);
        // Seta a Descricao do produto
        $('#boxInfoProdutoDescricao').html(texto);
        // Seta o Adicionar Desejo
        $('#boxInfoProdutoAddDesejo').attr("href", "/clubeNovoDesejoProduto.aspx?T=" + nome + "&PID=" + categoriaProdutoId + "&PN=" + categoriaProdutoNome);

        // Seta o Preco e o Botao de Compre Agora do Produto
        var htmlPreco = "";
        if (preco != "" && preco != ",00") {
            htmlPreco += "A partir de\n";
            htmlPreco += "<br />\n";
            htmlPreco += "<div class=\"preco\">\n";
            htmlPreco += "R$ <span class=\"txtAzul\">" + preco + "</span><span> " + textoPreco + "</span>\n";
            htmlPreco += "</div>";
        } else {
            htmlPreco += "<br />\n";
            htmlPreco += "<div class=\"preco\">\n";
            htmlPreco += "Preço sob Consulta\n";
            htmlPreco += "</div>";
        }
        if (compre != "") {
            // SaveLogCompreAgoraClick = function(pIdAnuncioProduto, pUrlDestino) {
            htmlPreco += "<a class=\"btCompreAgora\" onclick=\"javascript: OfertaMediaPlayer.SaveLogCompreAgoraClick('" + idAnuncioProduto + "', '/link.aspx?stShow=" + compre + "');\" href=\"/link.aspx?stShow=" + compre + "\" title=\"Compre Agora\" target=\"_blank\"></a>\n";
            //htmlPreco += "<a class=\"btCompreAgora\" href=\"/link.aspx?stShow=" + compre + "\" title=\"Compre Agora\" target=\"_target\"></a>\n";
        }
        $('#boxInfoProdutoPrecoCompre').html(htmlPreco);

        // Muda as Cores de Fundo
        $('.playinfo').parent().removeAttr("style");
        $('.playinfo').eq(_index).parent().attr("style", "background-color:#ffc600;");

        // Move o Scroll
        // Descobre em que Linha esta o Item
        var totalLinhasItem = Math.floor(_index / 6);
        var posicaoScroll = (totalLinhasItem * 61);
        if ($('.boxThumbsScroll').scrollTop() != posicaoScroll) {
            $('.boxThumbsScroll').animate({ scrollTop: posicaoScroll }, "fast");
        }

        this.SaveLogProdutoView(idAnuncioProduto);

        this.itemToPlay = _index;
    }

    this.AddNewTotalItensProdutosEmVideo = function() {
        this.totItemProdutos++;
    }
    this.ResetTotalItensProdutosEmVideo = function() {
        this.totItemProdutos = 0;
    }
    this.GetTotalItensProdutosEmVideo = function() {
        return this.totItemProdutos;
    }

    this.ResetSelectionProdutos = function() {
        $('.playinfo').parent().removeAttr("style");
    }
    
    // Busca Playlist de Fotos
    this.GetSlideShowPlaylist = function(_allImgs) {
        // Variavel que Recebe o Array com a Playlist
        var arraySlideShowPlaylist = new Array();
        var index = 0;

        // Busca o Array com a Lista de Imagens para Montar a PlayList
        $('.playinfo').each(function() {
            // Verifica se tem que usar todas as imagens
            if (_allImgs) {
                arraySlideShowPlaylist[index] = $('#teaser', this).text();
                //$(this).parent().find('img').fadeTo(0, 1);
                if ($('#timecode', this).text() == '') {
                    OfertaMediaPlayer.hasPhoto = true; // Indica se tem Fotos (Produtos sem Time Code)
                } else {
                    OfertaMediaPlayer.hasVideo = true; // Indica se Tem Video para Tocar (Produtos com Time Code quer dizer que tem Video)
                }
            } else {
                // Adiciona apenas as imagens sem time code
                if ($('#timecode', this).text() == '') {
                    arraySlideShowPlaylist[index] = $('#teaser', this).text();
                    //$(this).parent().find('img').fadeTo(0, 1);
                    OfertaMediaPlayer.hasPhoto = true; // Indica se tem Fotos (Produtos sem Time Code)
                } else {
                    OfertaMediaPlayer.AddNewTotalItensProdutosEmVideo();
                    // Escurece a imagem
                    //$(this).parent().find('img').fadeTo(0, 0.75);
                    OfertaMediaPlayer.hasVideo = true; // Indica se Tem Video para Tocar (Produtos com Time Code quer dizer que tem Video)
                }
            }
            index++;
        });
        return arraySlideShowPlaylist;
    }

    this.GetVideoProdutosPlaylist = function() {
        // Variavel que Recebe o Array com a Playlist
        var arrayVideoProdutosPlaylist = new Array();
        var index = 0;

        // Busca o Array com a Lista de Imagens para Montar a PlayList
        $('.playinfo').each(function() {
            arrayVideoProdutosPlaylist[index] = $('#timecode', this).text();
            index++;
            if ($('#timecode', this).text() == '') {
                //$(this).parent().find('img').fadeTo(0, 0.75);
                OfertaMediaPlayer.hasPhoto = true; // Indica se tem Fotos (Produtos sem Time Code)
            } else {
                //$(this).parent().find('img').fadeTo(0, 1);
                OfertaMediaPlayer.hasVideo = true; // Indica se Tem Video para Tocar (Produtos com Time Code quer dizer que tem Video)
            }
        });
        return arrayVideoProdutosPlaylist;
    }


    // Busca se tem mais Ofertas Para mostrar
    this.GetNextOfertaToPlay = function() {
        // Verifica se Tem mais de 1 Item na Playlist
        if ($('.containerThumbTitInterno > a').length > 1) {
            // Descobre qual esta tocando
            var keyAtual = $('.containerThumbTitInterno > a > .boxVendo').parent().attr('key');
            var indexAtual = 0;
            var index = 0;
            // Descobre o Proximo a tocar
            $('.containerThumbTitInterno > a').each(function() {
                // Verifica se Encontrou o Atual
                if ($(this).attr('key') == keyAtual) {
                    indexAtual = index;
                }
                index++;
            });
            // Verifica se Existe um Item apos o Atual
            if ($('.containerThumbTitInterno > a').eq(indexAtual + 1).attr('key') != undefined) {
                // Pergunta se quer Mudar para a Proxima Oferta
                if (confirm("Quer ver a Proxima Oferta?")) {
                    Util.submitLink($('.containerThumbTitInterno > a').eq(indexAtual + 1).attr('href'));
                }
            } else {
                // Pergunta se quer Mudar para a Proxima Oferta
                if (confirm("Quer ver a Proxima Oferta?")) {
                    Util.submitLink($('.containerThumbTitInterno > a').eq(0).attr('href'));
                }
            }

        }
    }


    this.SaveLogProdutoClick = function(pIdAnuncioProduto) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 1
        urlAtual = window.location;
        extra = "";

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;
        urlDestino = "";

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
            }
        });

        return false;
    }

    this.SaveLogProdutoView = function(pIdAnuncioProduto) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idViewType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var extra = new String();

        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idViewType = 1
        urlAtual = window.location;
        extra = "anuncioId=" + $('#infoLojaAnuncioId').val() + "|anuncioKey=" + $('#infoLojaAnuncioKey').val();

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdViewType=" + idViewType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveView";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
            }
        });

        return false;
    }

    this.SaveLogCompreAgoraClick = function(pIdAnuncioProduto, pUrlDestino) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 5
        urlAtual = window.location;
        extra = "";

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;
        urlDestino = pUrlDestino.replace("/link.aspx?stShow=", "");

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
                //window.open(pUrlDestino, "_blank");
            }
        });

        return false;
    }


    /*********************************************************
    * Ações do Player
    *********************************************************/
    // Toca Somente Como Fotos
    this.StartOnlyPhoto = function() {
        // Para o Slide Show Atual
        if (this.playerSlideShow != null) {
            this.Pause();
        }
        // Para o Play do Video
        if (this.playerVideo != null) {
            this.Pause();
        }
        // Limpa a Variavel de Controle
        this.playerSlideShow = null;
        // Esconde o Player
        $('#ctl00_content_playerVideoId').attr('style', 'visibility:hidden; position:absolute;');
        // Mostra o Div com as Fotos
        $('#ctl00_content_playerFotoID').attr('style', 'display:block; position:absolute;');
        // Indica que é para exibir todas as Fotos
        this.playAllPhotos = true;
        // Reseta os Totais
        this.ResetTotalItensProdutosEmVideo();
        this.itemToPlay = 0;
        this.playOnlyOnePhoto = false;
        this.mediaType = 2;

        // Seta a Acao do Botao
        $('#btVerFotosID').attr("href", "javascript: OfertaMediaPlayer.StopOnlyPhoto();");
        $('#btVerFotosID').html("Voltar para Vídeo");
        // Inicia o Slide Show Novamente
        this.Start();
        
    }
    // Toca Somente Como Fotos
    this.StopOnlyPhoto = function() {
        // Para o Slide Show Atual
        if (this.playerSlideShow != null) {
            this.Pause();
        }
        // Limpa a Variavel de Controle do SlideShow
        this.playerSlideShow = null;
        // Indica que é para exibir todas as Fotos
        this.playAllPhotos = false;
        // Reseta os Totais
        this.ResetTotalItensProdutosEmVideo();
        this.itemToPlay = 0;
        this.playOnlyOnePhoto = false;
        this.GetVideoProdutosPlaylist();
        this.mediaType = 1;
        // Esconde o Player
        $('#ctl00_content_playerVideoId').attr('style', 'visibility:visible; position:absolute;');
        // Mostra o Div com as Fotos
        $('#ctl00_content_playerFotoID').attr('style', 'display:none; position:absolute;');

        // Seta a Acao do Botao
        $('#btVerFotosID').attr("href", "javascript: OfertaMediaPlayer.StartOnlyPhoto();");
        $('#btVerFotosID').html("Ver apenas fotos");
        // Inicia o Slide Show Novamente
        this.Start();
        // Reseta para o Inicio
        this.playerVideo.ResetPlayerStartPoint();
        // Mostra o Item 0 da playlist de Produtos
        this.ShowItemInfo(0);
    }
    
    // Start no Play da Media
    this.Start = function() {
        switch (Number(this.mediaType)) {
            case 1:
                if (Util.IsIPhone() == false) {
                    if (this.playerVideo == null) {
                        this.playerVideo = new PlayerVideo('_LiquidPlayerObject');
                        this.playerVideo.Initialize(this.GetVideoProdutosPlaylist());
                        this.playerVideo.StartPlay(null);
                    } else {
                        this.playerVideo.StartPlay(this.itemToPlay);
                    }
                } else {
                    $("#_LiquidPlayerObject").attr("style", "display:none;");
                    $("#_PlayerIPhone").attr("style", "display:block;");
                }
                break;
            case 2:
                // Verifica se é a Primeira Vez que vai tocar
                if (this.playerSlideShow == null) {
                    this.playerSlideShow = new PlayerSlideShow(this.GetSlideShowPlaylist(this.playAllPhotos));
                    this.playerSlideShow.Initialize($('.playinfo').length, false);
                    if (this.playerVideo != null) {
                        if (this.itemToPlay != null) {
                            this.playerSlideShow.StartPlay(this.itemToPlay - this.GetTotalItensProdutosEmVideo(), this.playOnlyOnePhoto);
                        } else {
                            this.playerSlideShow.StartPlay(this.itemToPlay, false);
                        }
                    } else {
                        this.playerSlideShow.StartPlay(null, this.playOnlyOnePhoto);
                    }
                } else {
                    // Já não é a primeira vez
                    this.playerSlideShow.StartPlay(this.itemToPlay - this.GetTotalItensProdutosEmVideo(), this.playOnlyOnePhoto);
                }
                break;
        }
        // Verifica se tem o Botao Voltar Video
        if ($("#ctl00_content_playerVideoId").html() != "") {
            $("#btnSlideFotoVoltarVideoID").css("display", "block");
        } else {
            $("#btnSlideFotoVoltarVideoID").css("display", "none");
            $("#timeLineSlideFotoID").css("width", "210px");
        }

        // Verifica se tem que exibir o botao Exibir Apenas Fotos
        if (this.hasVideo) {
            $("#btVerFotosID").css("display", "block");
        } else {
            $("#btVerFotosID").css("display", "none");
        }
    }
    // Resume do Play de Media
    this.Resume = function() {
        switch (Number(this.mediaType)) {
            case 1:
                this.playerVideo.ResumePlay();
                break;
            case 2:
                this.playerSlideShow.ResumePlay();
                break;
        }
    }
    // Pause no Play da Media
    this.Pause = function() {
        switch (Number(this.mediaType)) {
            case 1:
                if (this.playerVideo != null) {
                    this.playerVideo.PausePlay();
                }
                break;
            case 2:
                if (this.playerSlideShow != null) {
                    this.playerSlideShow.PausePlay();
                }
                break;
        }
    }

    // Stop no Play de Media
    this.Stop = function() {
        switch (Number(this.mediaType)) {
            case 1:
                this.playerVideo.StopPlay();
                break;
            case 2:
                break;
        }
    }

    this.onVideoStop = function() {
        this.playerVideo.onStopPlay();
    }
    this.onVideoResume = function() {
        this.playerVideo.onResumePlay();
    }
    this.onVideoPause = function() {
        this.playerVideo.onPausePlay();
    }

    this.ReturnToVideo = function() {
        // Para o Slide Show
        this.Pause();
        this.SetMediaType(1);
        this.GetVideoProdutosPlaylist();
        this.ResetSelectionProdutos();
        // Esconde o Div com as Fotos
        $('#ctl00_content_playerFotoID').attr('style', 'display:none; position:absolute;');
        // Mostra o Player
        $('#ctl00_content_playerVideoId').attr('style', 'visibility:visible; position:absolute;');

        // Seta a Acao do Botao
        $('#btVerFotosID').attr("href", "javascript: OfertaMediaPlayer.StartOnlyPhoto();");
        $('#btVerFotosID').html("Ver apenas fotos");
        
        // Retorna a tocar o video
        this.playerVideo.ResumePlay();
    }

    /*********************************************************
    * Ações do Player de Video
    *********************************************************/
    this.TimeCodeLoop = function() {
        this.playerVideo.TimeCodeLoop();
    }


    /*********************************************************
    * Ações dos Botoes
    *********************************************************/
    this.ChangeAbaMaisSobre = function(changeTo) {
        switch (changeTo) {
            case 'Produtos':
                if ($('#abaMaisSobreProdutosId').attr("class") != "abaProdutosOv") {
                    $('#abaMaisSobreProdutosId').attr("class", "abaProdutosOv");
                    $('#abaMaisSobreAnunciosId').attr("class", "abaAnuncios");
                    $('#abaMaisSobreMateriasId').attr("class", "abaMaterias");
                    Produtos.GetProdutosAtivosByDepartamento($('#ctl00_content_maisSobreIdDepartamento').val(), $('#ctl00_content_maisSobreIdFranquia').val(), '1', '10', '', $('#ctl00_content_maisSobreLink').val());
                }
                break;
            case 'Anuncios':
                if ($('#abaMaisSobreAnunciosId').attr("class") != "abaAnunciosOv") {
                    $('#abaMaisSobreProdutosId').attr("class", "abaProdutos");
                    $('#abaMaisSobreAnunciosId').attr("class", "abaAnunciosOv");
                    $('#abaMaisSobreMateriasId').attr("class", "abaMaterias");
                    Anuncios.GetEmpresasAtivasByDepartamento($('#ctl00_content_maisSobreIdDepartamento').val(), $('#ctl00_content_maisSobreIdFranquia').val(), '0', '10', '', $('#ctl00_content_maisSobreLink').val())
                }
                break;
            case 'Materias':
                if ($('#abaMaisSobreMateriasId').attr("class") != "abaMateriasOv") {
                    $('#abaMaisSobreProdutosId').attr("class", "abaProdutos");
                    $('#abaMaisSobreAnunciosId').attr("class", "abaAnuncios");
                    $('#abaMaisSobreMateriasId').attr("class", "abaMateriasOv");
                }
                break;
            default:
                if ($('#abaMaisSobreProdutosId').attr("class") != "abaProdutosOv") {
                    $('#abaMaisSobreProdutosId').attr("class", "abaProdutosOv");
                    $('#abaMaisSobreAnunciosId').attr("class", "abaAnuncios");
                    $('#abaMaisSobreMateriasId').attr("class", "abaMaterias");
                    Produtos.GetProdutosAtivosByDepartamento($('#ctl00_content_maisSobreIdDepartamento').val(), $('#ctl00_content_maisSobreIdFranquia').val(), '1', '10', '', $('#ctl00_content_maisSobreLink').val());
                }
                break;
        }
    }

    //# INDIQUE
    this.SubmitIndique = function() {
        var enviar = true;

        // Informacoes do Produto Ativo no Momento
        /*var thumb = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).parent().find('img').attr('src');*/
        var thumb = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#teaser').text();
        var nome = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#nome').text();
        var texto = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#texto').text();
        var preco = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#preco').text();
        var textoPreco = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#textoPreco').text();
        var compre = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#compre').text();
        var timecode = $('.playinfo').eq(OfertaMediaPlayer.itemToPlay).find('#timecode').text();

        // Informacoes da Loja
        var infoLojaThumb = $('#infoLojaThumb').attr('src');
        var infoLojaNome = $('#infoLojaNome').text();
        var infoLojaDescricao = $('#infoLojaDescricao').text();
        var infoLojaSite = $('#infoLojaSite').text();
        var infoLojaEmail = $('#infoLojaEmail').text();

        // O que foi preenchido no Formulario
        var listEmailTo = new String();
        var emailFrom = new String();
        var mensagem = new String();
        var nameValue = new String();
        var extraInfo = new String();

        $("#indiqueListaAmigos > option").each(function() {
            listEmailTo += $.trim($(this).text()) + ';';
        });
        emailFrom = $.trim($("#indiqueSeuEmail").val());
        mensagem = $.trim($("#indiqueSuaMensagem").val());
        extraInfo = "";

        // Monta a String NameValue

        if (listEmailTo == "") {
            enviar = false;
            $('#indiqueEmailAmigoMsg').html(' * Indique pelo menos 1 E-mail!');
        }

        if (emailFrom != "") {
            if (!Util.isValidEmailAddress(emailFrom)) {
                enviar = false;
                $('#indiqueSeuEmailMsg').html(' * E-mail inválido!');
            }
        } else {
            enviar = false;
            $('#indiqueSeuEmailMsg').html(' * E-mail inválido!');
        }

        if (enviar) {
            nameValue += "nomeAmigo#|";
            nameValue += "seuAmigo#" + emailFrom + "|";
            nameValue += "mensagem#" + mensagem + "|";

            nameValue += "thumb#" + thumb + "|";
            nameValue += "nome#" + nome + "|";
            nameValue += "texto#" + texto + "|";
            nameValue += "preco#" + preco + "|";

            nameValue += "infoLojaThumb#" + infoLojaThumb + "|";
            nameValue += "infoLojaNome#" + infoLojaNome + "|";
            nameValue += "infoLojaSite#" + infoLojaSite + "|";
            nameValue += "infoLojaEmail#" + infoLojaEmail + "|";

            var linkOferta = new String(window.location);
            if (linkOferta.indexOf("|") > 0) {
                linkOferta = linkOferta.substring(0, linkOferta.indexOf("|"))
            }
            nameValue += "linkOferta#" + linkOferta + "|";

            Util.SendSimpleMail(emailFrom, listEmailTo, 'Site | ShopTour - Oferta Indicada', 'EmailIndicacaoSite.htm', nameValue, extraInfo);
        }

        $("#dhtmlIndiqueID").toggle();

        //this.SendSimpleMail = function(pFromEmail, pToEmail, pSubject, pFileTemplate, pNameValue, pExtraInfo)
    }

    this.IndiqueAddEmailTo = function() {
        var indiqueEmailAmigo = $.trim($('#indiqueEmailAmigo').val());
        var adicionar = true;

        // Verifica se o Email é valido
        if (Util.isValidEmailAddress(indiqueEmailAmigo)) {
            // Verifica se já nao existe
            $("#indiqueListaAmigos > option").each(function() {
                if ($.trim($(this).text()) == indiqueEmailAmigo) {
                    //alert($(this).text());
                    adicionar = false;
                }
            });

            // Se ja nao existir adiciona
            if (adicionar) {
                $("#indiqueListaAmigos").append("<option value='" + indiqueEmailAmigo + "' >" + indiqueEmailAmigo + "</option>");
                $('#indiqueEmailAmigo').val('');
            }
        } else {
            $('#indiqueEmailAmigoMsg').html(' * E-mail inválido!');
        }
    }
    this.IndiqueRemoveEmailTo = function() {
        $("#indiqueListaAmigos option:selected").remove();
    }
    //# INDIQUE

    this.ShowEnderecoMap = function(lat, lng, objEnderecoTxt) {
        //var imgMapa = "<iframe src=\"http://webservices.maplink2.com.br/ShopTour/print.aspx?subid=" + mapId + "\" width=\"332\" height=\"261\" frameborder=\"0\" vspace=\"0\" hspace=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"></iframe>";
        var imgMapa = "<iframe src=\"http://www.shoptour.com.br/gmapas.aspx?lat=" + lat + "&lng=" + lng + "\" width=\"332\" height=\"261\" frameborder=\"0\" vspace=\"0\" hspace=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"></iframe>";
        $('#cntEnderecoMapaImgMapaID').html(imgMapa);
        $('#cntEnderecoMapaTxtID').html($(objEnderecoTxt).parent().find('div').html());

        // Esconde o Div com os Enderecos
        $('#ctl00_footer_cntEnderecoListaID').fadeOut("fast", function() {
            // Mostra o DiV com o Mapa
            $('#cntEnderecoMapa').fadeIn("fast");
        });

        // Esconde o Div com os Enderecos
        $('#ctl00_content_cntEnderecoListaID').fadeOut("fast", function() {
            // Mostra o DiV com o Mapa
            $('#cntEnderecoMapa').fadeIn("fast");
        });
    }

    this.ShowEndereco = function() {
        $('#cntEnderecoMapa').fadeOut("fast", function() {
            $('#ctl00_footer_cntEnderecoListaID').fadeIn("fast");
        });
        $('#ctl00_content_cntEnderecoListaID').fadeOut("fast", function() {
            $('#ctl00_content_cntEnderecoListaID').fadeIn("fast");
        });
    }

    this.EnablePlaylist = function() {
        // Esconte todos os Divs e mostra apenas o com a Indicacao "Sendo Visto"
        var indexSendoVisto = 0;
        var totalContainer = $("#ctl00_footer_containerPlaylistID > .containerThumbTitInterno").length
        $('#ctl00_footer_containerPlaylistID > .containerThumbTitInterno').each(function(i) {
            // Verifica se esta indicado o "Sendo Visto"
            if ($(this).find(".boxVendo").html() != null) {
                $(this).css("display", "block");
                indexSendoVisto = i + 1;
            } else {
                $(this).css("display", "none");
            }
            $(this).css("width", "542px");
        });


        // Seta a Quantidade de Paginas
        $('#containerPlaylistPaginacaoID').html(indexSendoVisto + ' de ' + totalContainer);
        this.playerPlaylistClick = false;

        // Adiciona as Açoes ao Botoes
        $('#containerPlaylistProximoID').click(function(e) {
            $('#ctl00_footer_containerPlaylistID > .containerThumbTitInterno').each(function(i) {
                // Verifica se é o que esta mostrando
                if ($(this).css("display") == "block") {
                    if (i + 2 <= totalContainer) {
                        $(this).css("display", "none");
                        $(this).next().css("display", "block");
                        $('#containerPlaylistPaginacaoID').html(i + 2 + ' de ' + totalContainer);
                    }
                    return false;
                }
            });
        });
        $('#containerPlaylistAnteriorID').click(function(e) {

            $('#ctl00_footer_containerPlaylistID > .containerThumbTitInterno').each(function(i) {
                // Verifica se é o que esta mostrando
                if ($(this).css("display") == "block") {
                    if (i > 0) {
                        $(this).css("display", "none");
                        $(this).prev().css("display", "block");
                        $('#containerPlaylistPaginacaoID').html(i + ' de ' + totalContainer);
                    }
                    return false;
                }
            });
        });

    }

    this.Sleep = function(milliseconds) {
        var start = new Date().getTime();
        for (var i = 0; i < 1e7; i++) {
            if ((new Date().getTime() - start) > milliseconds) {
                break;
            }
        }
    }

}