﻿var interactiveCanvas = (function ($) {

    var popup_overlay = null;
    var xml = null;

    var PeerPerspectives = function (vid, chan) {

        var video = vid;
        var channel = "";
        if (chan) {
            channel = chan;
        }

        return {

            initFlashPopupPlayer: function () {

                $.getScript('/js/peer_perspectives.js', function () {

                    var flashvars = {};

                    flashvars.contentId = ""; //this is the contentId for the interactive canvas configuration file which tells the player what content to load
                    flashvars.debug = true;
                    flashvars.rootPath = "/flash/hcp/interactive_canvas/"
                    flashvars.moduleDefinitionsPath = "/flash/hcp/interactive_canvas/xml/peerperspectives_modules_" + video + ".xml"
                    flashvars.skinCSSPath = "css/peerperspectives.css"; //from root path
                    flashvars.skinSWFPath = "skin/peerperspectives_skin.swf";  //from root path
                    flashvars.textPath = "xml/text.xml"; //from root path
                    flashvars.prescribingInformationPath = "/pdf/pi.aspx";
                    flashvars.channel = channel;
                    flashvars.xmlBase = "/flash/hcp/interactive_canvas/xml/peerperspectives_content_" + video + ".xml";
                    flashvars.trackingPath = "xml/peerperspectives_tracking_" + video + ".xml";
                    flashvars.trackingXML = "/flash/hcp/interactive_canvas/xml/peerperspectives_tracking_" + video + ".xml";

                    var params = {};
                    params.play = false;
                    params.loop = false;
                    params.quality = "best";
                    params.allowscriptaccess = "sameDomain";
                    params.allowFullScreen = true;

                    var attributes = {};
                    attributes.scale = "noscale";
                    id = "videoPopupFlash";

                    var c = document.getElementById("bms_ic");
                    if (!c) {
                        var d = document.createElement("div");
                        d.setAttribute("id", "bms_ic");
                        $(d).html("<div><p><a href='http://www.adobe.com/go/EN_US-H-GET-FLASH' target='_blank'>You don't seem to have Flash installed on your computer. Click here to install a free version.</a></p><a href='http://www.adobe.com/go/EN_US-H-GET-FLASH' target='_blank'><img src='/images/annes/img-video-no-flash.jpg' alt='Get Adobe Flash Player'/></a><br/><br/><br/><a class='close' href='javascript:void(0);' onclick='interactiveCanvas.destroyIC();'>Close</a></div>");
                        document.getElementById("interacticeCanvasVideoLayer").appendChild(d);
                    }

                    swfobject.embedSWF("/flash/hcp/interactive_canvas/peerperspectives_interactive_canvas.swf", "bms_ic", "960", "600", "9.0.0", false, flashvars, params, attributes);
                });
            },

            videoLayerInit: function () {

                var xOffset = $("#divMain").offset().left - 24;
                popup_overlay =
				new YAHOO.widget.Panel("interacticeCanvasVideoLayer",
					{ width: "998px",
					    height: "637px",
					    fixedcenter: false,
					    constraintoviewport: true,
					    close: false,
					    draggable: false,
					    zindex: 1500,
					    modal: true,
					    visible: false,
					    iframe: false,
					    underlay: "none",
					    xy: [xOffset, 303]
					}
				);

                popup_overlay.bringToTop = function () { };

                popup_overlay.render(document.body);
            }
        };
    };

    var PlusStories = function () {
        return {
            initFlashPopupPlayer: function () {

                var flashvars = {};
                flashvars.contentId = ""; //this is the contentId for the interactive canvas configuration file which tells the player what content to load
                flashvars.debug = "true";
                flashvars.rootPath = "/flash/plus_stories/"; //this is the root path for resources/content loaded relative to the interactive canvas
                flashvars.moduleDefinitionsPath = "/flash/plus_stories/xml/plus_modules_kalene.xml"; //if this exists, use it instead of the web service call to ContentHandler.ashx

                //SERVICES
                flashvars.formControllerPath = ""; //"https://staging.abilify.com/service/Controller/FormController.ashx";//
                flashvars.userStateHandlerPath = ""; //"https://staging.abilify.com/service/UserStateHandler.ashx";//
                flashvars.contentHandlerPath = ""; //"https://staging.abilify.com/service/ContentHandler.ashx";//

                flashvars.sessionTimeout = "240"; //minutes before the user's session expires
                flashvars.sessionPing = "5"; //minutes between each request for the user's session state

                flashvars.skinCSSPath = "css/plus.css"; //from root path
                flashvars.skinSWFPath = "skin/plus_skin.swf";  //from root path
                flashvars.textPath = "xml/text.xml"; //from root path
                flashvars.trackingPath = "xml/plus_tracking_kalene.xml";
                flashvars.importantSafetyInformationPath = ""; //"https://staging.abilify.com/service/ContentHandler.ashx?get_isi=HCP";//
                flashvars.prescribingInformationPath = "/pdf/pi.aspx";

                flashvars.channel = "";
                flashvars.xmlDir = "/flash/plus_stories/xml/plus_content_kalene.xml";
                flashvars.baseDir = "";
                flashvars.videoNum = "";

                var params = {};
                params.play = "true";
                params.loop = "false";
                params.quality = "best";
                params.allowscriptaccess = "sameDomain";
                params.allowFullScreen = "true";
                params.wmode = "opaque";

                var attributes = {};
                attributes.scale = "noscale";

                id = "videoPopupFlash";

                var c = document.getElementById("bms_ic");
                if (!c) {
                    var d = document.createElement("div");
                    d.setAttribute("id", "bms_ic");
                    $(d).html("<div><p><a href='http://www.adobe.com/go/EN_US-H-GET-FLASH' target='_blank'>You don't seem to have Flash installed on your computer. Click here to install a free version.</a></p><a href='http://www.adobe.com/go/EN_US-H-GET-FLASH' target='_blank'><img src='/images/annes/img-video-no-flash.jpg' alt='Get Adobe Flash Player'/></a><br/><br/><br/><a class='close' href='javascript:void(0);' onclick='interactiveCanvas.destroyIC();'>Close</a></div>");
                    document.getElementById("interacticeCanvasVideoLayer").appendChild(d);
                }

                swfobject.embedSWF("/flash/plus_stories/shell.swf", "bms_ic", "960", "600", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
            },

            videoLayerInit: function () {

                var xOffset = $("#divMain").offset().left - 40;
                popup_overlay =
				new YAHOO.widget.Panel("interacticeCanvasVideoLayer",
					{ width: "998px",
					    height: "637px",
					    fixedcenter: false,
					    constraintoviewport: true,
					    close: false,
					    draggable: false,
					    zindex: 1500,
					    modal: true,
					    visible: false,
					    iframe: false,
					    underlay: "shadow",
					    xy: [xOffset, 250]
					}
				);

                popup_overlay.bringToTop = function () { };

                popup_overlay.render(document.body);
            }
        };
    };

    var calloutsMap = {
        "/images/HCP/callouts/img-pp-callout-1.png": PeerPerspectives("Quentzel", "syp"),
        "/images/HCP/callouts/img-pp-callout-2.png": PeerPerspectives("Quentzel"),
        "/images/HCP/callouts/img-pp-callout-4.png": PeerPerspectives("Quentzel"),
        "/images/HCP/callouts/img-pp-callout-3.png": PeerPerspectives("Quentzel"),
        "/images/HCP/callouts/img-pp-callout-4.png": PeerPerspectives("Quentzel"),
        "/images/HCP/callouts/img-pp-callout-5.png": PeerPerspectives("Quentzel"),
        "/images/HCP/callouts/img-pp-callout-6.png": PeerPerspectives("Quentzel"),
        "/images/HCP/callouts/img-pp-callout-7.png": PeerPerspectives("McIntosh"),
        "/images/HCP/callouts/img-pp-callout-8.png": PeerPerspectives("McIntosh"),
        "/images/HCP/callouts/img-pp-callout-9.png": PeerPerspectives("McIntosh"),
        "/images/HCP/callouts/img-pp-callout-10.png": PeerPerspectives("McIntosh"),
        "/images/HCP/callouts/img-pp-callout-11.png": PeerPerspectives("McIntosh")
    };

    return {

        init: function () {
            $(".interactiveCanvasVideo").live('click', function () {
                IntLinTracking("PeerPerspective_callout");
                var src = $(this).find("img").attr("src");
                interactiveCanvas.playVideo(calloutsMap[src]);
            });

            $(".QuentezelVideo").live('click', function () {
                interactiveCanvas.playVideo(PeerPerspectives("Quentzel"));
            });

            $(".McintoshVideo").live('click', function () {
                interactiveCanvas.playVideo(PeerPerspectives("McIntosh"));
            });

            $(".KalenesVideo").live('click', function () {
                interactiveCanvas.playPlusStories();
            });
        },

        playVideo: function (video) {
            if (popup_overlay == null) {
                loadCSS("/css/container.css");
                $.getScript('/js/json-min.js', function () {
                    loadCSS("/css/interactive_canvas.css");
                    video.videoLayerInit();
                    $.getScript("/js/swfobject_2.2.js", function () {
                        video.initFlashPopupPlayer();
                        popup_overlay.show();
                        $('#interacticeCanvasVideoLayer').css('display', 'block');
                        if ($('#interacticeCanvasVideoLayer_c').is('.shadow')) {
                            $('#interacticeCanvasVideoLayer_mask').addClass('shadow');
                        }
                    });
                });
            } else {
                video.initFlashPopupPlayer();
                popup_overlay.show();
                $('#interacticeCanvasVideoLayer').css('display', 'block');
            }
        },

        //For Peer Perspectives Direct Link
        playPeerPerspectives: function (video, channel) {
            interactiveCanvas.playVideo(PeerPerspectives(video, channel));
        },

        //For flash callouts
        playPlusStories: function () {
            interactiveCanvas.playVideo(PlusStories());
        },

        destroyIC: function () {
            $('#interacticeCanvasVideoLayer').css('display', 'none');
            popup_overlay.hide();
        }
    };
} (jQuery));

$(function () {
    interactiveCanvas.init();
});

function destroyIC() {
	interactiveCanvas.destroyIC();
}
