﻿/* env setup ======================== */
function setEnv() {
  var envDef = document.domain.toLowerCase();
  if (envDef.indexOf("dev1") != -1) return "dev";
  if (envDef.indexOf("77.220.84") != -1) return "stage";
  if (envDef.indexOf("ray-ban.com") != -1) return "prod";
}

/* ==============================================
Total Immersion Plug-in
============================================== */
function ar_LaunchTImmersion() {
    $('#container').empty().append('<div id="fl-1" class="span-10 last" style="position:relative;"><div id="leftStripe" style="float:left;background:#0c0c0c url(/_repository/_pages/_cutwater/images/rare-finds/stripes/StripesBW_147_470_Left.jpg) no-repeat;width:147px; height:470px;"></div><div id="plugin_dfusion" align="center" style="float:left;width:626px; height:470px;position:relative;display:inline;"></div> <div id="rightStripe" style="float:left;background:#0c0c0c url(/_repository/_pages/_cutwater/images/rare-finds/stripes/StripesBW_147_470_Right.jpg) no-repeat;width:147px; height:470px;"></div> </div>');
    var player = tiMacOSXSupported()?"DFusionWebPlayerFinalMacOSX/DFusionWebPlayer":"DFusionWebPlayerFinal/DFusionWebPlayer";
    tiGenerateDFusionWebHTML("plugin_dfusion_instance",626,470,player,"RB_scenario/project.dpd","ChooseCamera","ReadyToStart","true");
/* <asp:Literal ID="LtRareFinds" runat="server" />
                    <p>Unfortunately the Ray-Ban Augmented Reality Experience isn't currently supported by your web browser. <br />
                    If you're on a PC, please try Internet Explorer 7+ or Firefox 3+. If you're on a Mac, please try Safari 4 or Firefox 3+.</p>
                  </asp:Literal>*/
}

/* ==============================================
flv player
============================================== */
function ar_LaunchFLVPlayer(arg) {
    $('#container').empty().append('<div id="fl-1"><h1>Whoops!</h1><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>');

    //var pathSwf = "/_repository/_resources/_swf/360-view-v4.swf";
    //var params = { menu: false };
    //var attributes = {};
    //var flashvars = { pName: pName3d, pPath: path3d, controller: "true", controllerColor: "0xd70000" };
    //if (arg == "ANY codes")
        var src = '/_repository/_resources/_flv/events/rarefinds/BandofSkulls.flv';
    swfobject.embedSWF('/_repository/_resources/_swf/feature-container-rare-finds.swf', 'fl-1', '920', '470', '9.0.0', '/_repository/_ecma/2010/swfobject/expressInstall.swf', { source: src, lingua: 'en', region: 'us', country: 'usa', code: arg, env: setEnv() }, { menu: 'false', wmode: 'opaque' });
    //$('#jsoutput').empty().append('<br /><strong>Plugin display removed, FLV container displayed!</strong>');
    //alert(arg);
    //alert(setEnv());
}

/* ==============================================
flv player demo
============================================== */
function ar_LaunchFLVPlayer_demo() {
    $('#container').empty().append('<div id="fl-1"><h1>Whoops!</h1><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>');

    //var pathSwf = "/_repository/_resources/_swf/360-view-v4.swf";
    //var params = { menu: false };
    //var attributes = {};
    //var flashvars = { pName: pName3d, pPath: path3d, controller: "true", controllerColor: "0xd70000" };
    swfobject.embedSWF('/_repository/_resources/_swf/feature-container-v9.swf', 'fl-1', '920', '470', '9.0.0', '/_repository/_ecma/2010/swfobject/expressInstall.swf', { xmlPath: 'rarefinds.xml', lingua: 'en', region: 'us', country: 'usa' }, { menu: 'false', wmode: 'opaque' });
    //$('#jsoutput').empty().append('<br /><strong>Plugin display removed, FLV container displayed!</strong>');
    $('#noticeContainer').css("display", "none");
}

/* ==============================================
i-frame
============================================== */
function ar_LaunchIFrame(arg,stage) {
    var ep = (stage) ? "http://rayban.promo.eprize.com/rarefinds" : "http://rayban.promo.eprize.com/rarefinds";
    var $url = (arg == 0) ? ep : ep + "/open?entry=" + arg;
    var $frame = $('<iframe name="ifr1" id="ifr1" src="' + $url + '" frameborder="0" border="0" cellspacing="0" scrolling="no" style="border-style: none; width: 920px; height: 470px; overflow-x:hidden; overflow-y:auto;"></iframe>');
    $('#container').empty().append($frame);
    $('#startContainer').css("display", "none");
    $('#experienceContainer').css("display", "inline");
    $('#noticeContainer').css("display", "none");
    //$('#jsoutput').empty().append('<br /><strong>FLV container display removed, IFrame displayed calling following URL: ' + $url + '</strong>');
}

/* ==============================================
i-frame Official rules and FAQ
================================================*/
function ar_LaunchIFrameContent(content, stage) {
    var ep = (stage) ? "http://rayban.promo.eprize.com/rarefinds/" : "http://rayban.promo.eprize.com/rarefinds/";
    var $url = "";
    var $popup = false;
    switch (content) {
        case ("FAQ"): // should launch in popup
            $url = "faq";
            $popup = true;
            break;
        case ("PRIZE"):
            $url = "display_page?page=prizes";
            break;
        case ("CODE"):
            $url = "";
            break;
        default: // official rules -- should launch in popup
            $url = "display_page?page=rules";
            $popup = true;
    }
    $url = ep + $url;

    if (!$popup) {
        var $frame = $('<iframe name="ifr1" id="ifr1" src="' + $url + '" frameborder="0" border="0" cellspacing="0" scrolling="no" style="border-style: none; width: 920px; height: 470px; overflow-x:hidden; overflow-y:auto;"></iframe>');
        $('#container').empty().append($frame);
        $('#startContainer').css("display", "none");
        $('#experienceContainer').css("display", "inline");
        $('#noticeContainer').css("display", "none");
    } else {
        window.open($url, '_blank','width=800,height=600,toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
    } 
    //$('#jsoutput').empty().append('<br /><strong>IFrame displayed calling following URL: ' + $url + '</strong>');
}

/* ============================================
z-index fix for TI plugin
==============================================*/
function ar_FixZIndex() {
    $('#plugin_dfusion').css("z-index", 20);
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return document[movieName];
    } else {
        return document[movieName];
    }
}
function sendToActionScript(value, title) {
    thisMovie("flashcontent").sendToActionScript(value, title);
}
/* ===========================================
IE active-x notification
==============================================*/
function notifyActiveX() {
    $('#noticeContainer').css("display", "block");
    $('#noticeButton').click(function() {
        $('#noticeContainer').css("display", "none");
    });
}
$(document).ready(function() {
    if ($('#noticeContainer').length != 0) {
        ar_FixZIndex();
        //alert(betterdetectDFusionActiveXControl());
        if (tiWindowsSupported() && tiInternetExplorer() && !betterdetectDFusionActiveXControl())
            notifyActiveX();
    }
});

