﻿var containerDiv = "fancy_div";

$(document).ready(function() {
    $("a#commercial_link").fancybox({
        'frameWidth': 480,
        'frameHeight': 360,
        'zoomSpeedIn': 200,
        'zoomSpeedOut': 200,
        'overlayShow': true,
        'overlayOpacity': 0.75,
        'overlayColor': '#5F195E',
        'enableEscapeButton': true,
        'showCloseButton': true,
        'hideOnOverlayClick': false,
        'hideOnContentClick': false,
        'centerOnScroll': false,
        'callbackOnShow': function() {
            LoadCommercial();  
            AddDisclaimer();
            FixTranscriptLink();
        },
        'callbackOnClose': function() {
            $(containerDiv).empty();
            RemoveDisclaimer();
        }          
    });    
});

function LoadCommercial()
{
    $f(containerDiv, 
        { 
            src: "/flash/flowplayer.commercial-3.1.5.swf",
            cachebusting: true,
            onFail: function() {
                var flashMessage = '<div class="flash_message">' +
                                   '<h2>Flash is required to view this video</h2><br />' +
                                   '<h3>You have no Flash plugin installed</h3><br /> ' +
                                   '<p>Download latest version from <a href="http://www.adobe.com/go/getflashplayer">here</a></p>' +
                                   '</div>';                
            
                document.getElementById(containerDiv).innerHTML = flashMessage;
                
            }
        },
        {
        key: "#@6061824ae5d1e829932",
        clip: {
            url: 'sensiva_spot_1',
            provider: 'rtmp',
            onStart: function(clip)
                { 
                    pageTracker._trackEvent("Videos", "Play", clip.url); 
                },
            onPause: function(clip) 
                { 
                    pageTracker._trackEvent("Videos", "Pause", clip.url, parseInt(this.getTime())); 
                },
            onStop: function(clip)
                { 
                    pageTracker._trackEvent("Videos", "Stop", clip.url, parseInt(this.getTime())); 
                }, 
            onFinish: function(clip) 
                {
                    pageTracker._trackEvent("Videos", "Finish", clip.url);                        
                },
            onClose: function(clip)
                {
                   pageTracker._trackEvent("Videos", "Close", clip.url, parseInt(this.getTime()));
                },
            onSeek: function(clip) 
                {
                    pageTracker._trackEvent("Videos", "Seek", clip.url, parseInt(this.getTime()));
                }
        },
        
        plugins: {
            rtmp: {
                url: '/flash/flowplayer.rtmp-3.1.3.swf',
                netConnectionUrl: 'rtmpt://abbott.fcod.llnwd.net/a1915/o18/sensiva/'
            },
              
            controls: { 
                backgroundColor: '#e8cadd', 
                backgroundGradient: 'none',             
                all: false, 
                play: true,
                scrubber: true,
                volume: true, 
                mute: true, 
                height: 30, 
                progressColor: '#bb559c', 
                bufferColor: '#56004e'  
            }
                  
        }
    });
}

function AddDisclaimer()
{
    var disclaimer = "<div id=\"video_disclaimer\">Sensiva is a medical food for the dietary management of Fibrocystic Breast Changes.<br />Please talk to your OB/GYN about using Sensiva.</div>";
    
    $("body").append(disclaimer);
    
    var newDivID = "div#video_disclaimer";
    var popupBackgroundID = "div#fancy_bg";
    var titleID = "div#fancy_title";
    
    var width = $(popupBackgroundID).outerWidth();
    var popupOffset = $(popupBackgroundID).offset();
    var titleOffset = $("div#fancy_title").offset();
    var titleHeight = $(titleID).outerHeight();
    
    var newWidth = width - 16; // subtract padding/border
    var newLeft = popupOffset.left;
    var newTop = titleOffset.top + titleHeight + 4;
    
    $(newDivID).css("width", newWidth + "px");
    $(newDivID).css("left", newLeft + "px");
    $(newDivID).css("top", newTop + "px");
}

function RemoveDisclaimer()
{
    $("div#video_disclaimer").remove();
}

function FixTranscriptLink()
{
    var linkContainerID = "td#fancy_title_main > div";

    var url = "/pdf/Commercial1_Transcript.pdf";
    var target = "_transcript";
    var linkText = $(linkContainerID).text();

    var linkHtml = "<a href=\"" + url + "\" target=\"" + target + "\">" + linkText + "</a>";
    
    $(linkContainerID).html(linkHtml);    
}


