var current_video = "";
var me;

var video_init = function()
{ 
	$("div.inject_container img.watch_how").click(pop_inject_video);
        $("div.pso_moa_video img.watch_how, div.pso_moa_video a.watch_how").click(pop_video);
        $("div.pso_moa_pic_101 img.watch_how, div.pso_moa_pic_101 a.watch_how").click(pop_video);
        $("div.small_video_container img.watch_how, div.small_video_container a.watch_how").click(pop_video);
        
        
        $("#supportVideoBox1, #supportVideoBox2, #watchfinancevideo").click(pop_video);
        
        
        // home page test
        $("#hp_flash_link,#hp_flash_button").click(pop_hp_video);
		
        $('#popupRaTalksVid li.outer').hover( function() {
            $(this).addClass('hover');
        }, function() {
            $(this).removeClass('hover');
        });    
        
        $('#popupRaTalksVid li.outer').click( function() {      
            if (!$(this).hasClass('active')) {
                $('#raTalksMenu div.menuText').hide();
                
                $('li.active').animate({
                    height: '42'
                }, 255, function() {
                    vertAlign($(this));                   
                });
                
                $('li.outer').removeClass('active');
                
                $(this).animate({
                    height: '100'
                }, 251, function() {
                    $(this).addClass('active');
                    $(this).find('div.menuText').show();
                    vertAlign($(this));                   
                });            
            }      
            
            var thisID = $(this).attr('id'); 
            var thisVid = thisID.substring(13,thisID.length);
            //alert(thisVid);            

            videoTrack('ratalks_video','menu','click','video' + thisVid);
            
            loadVideo(thisVid);                       
            //updateTitle($(this));

        });  
/*        
        $('div.raTalksVideoBox').hoverIntent(function() {
            $(this).find('div.raTalksVideoBoxInfo').animate({
                marginTop: '0'
            }, 450, function() {});
        }, function() {           
            $(this).find('div.raTalksVideoBoxInfo').animate({
                marginTop: '131'
            }, 450, function() {});
        });
*/        
        
        $('div.raTalksVideoISIBox div.thumbnail').hover( function() {
           $(this).find('a.ratalks_video').addClass('hover');
        }, function() {
           $(this).find('a.ratalks_video').removeClass('hover');            
        });
        
        $('div.raTalksVideoBox').hoverIntent({
            sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)
            interval: 50,   // number = milliseconds of polling interval
            over: rollUp,  // function = onMouseOver callback (required)
            timeout: 350,   // number = milliseconds delay before onMouseOut function call
            out: rollDown    // function = onMouseOut callback (required)
        });        

        $('div.scrollVideoBox').hoverIntent({
            sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)
            interval: 50,   // number = milliseconds of polling interval
            over: scrollUp,  // function = onMouseOver callback (required)
            timeout: 350,   // number = milliseconds delay before onMouseOut function call
            out: scrollDown    // function = onMouseOut callback (required)
        });        
        
        function rollUp() {            
            $(this).find('div.raTalksVideoBoxInfo').animate({
                marginTop: '0'
            }, 250, function() {});            
        }
        
        function rollDown() {    
            $(this).find('div.raTalksVideoBoxInfo').animate({
                marginTop: '81'
            }, 450, function() {});
        }
        
        function scrollUp() {            
            $(this).find('div.scrollVideoBoxInfo').animate({
                marginTop: '0'
            }, 250, function() {});            
        }
        
        function scrollDown() {    
            $(this).find('div.scrollVideoBoxInfo').animate({
                marginTop: '81'
            }, 450, function() {});
        }
        
        $('div.raTalksVideoBox, div.raTalksVideoISIBox').click( function() {
            var tid = $(this).attr('id');
            var tidNum = tid.substring(tid.length - 1);
            //alert(tidNum);
            videoTrack('ratalks_video','launch','click','video' + tidNum);
            pop_ratalks_video(tidNum - 1);
        });
        
}

var close_video = function(flash_cont, flash_cont_parent) {
    evokeModalDialog.hide(); 
    destroy_flash_element(flash_cont, flash_cont_parent);
}

var show_inject_video = function(mec_code, wt_track_playerName)
{
	mecTrack(mec_code);     // MEC tracking
    
	var flashvars = {
		configXml: file_path + "xml/data.xml",
		playerName: wt_track_playerName
	};
	var params = {};
	params.bgcolor = "#ffffff";
	var attributes = {};
	attributes.id = "flash_holder";
	swfobject.embedSWF(file_path + swf_filename, "flash_holder", wid, ht, "9.0.0", "fp_flash/expressInstall.swf", flashvars, params, attributes);
}

var show_video = function(mec_code, wt_track_videoGroupName, wt_track_videoName, isi_duration)
{
	mecTrack(mec_code);     // MEC tracking
        
        var flashvars = {
		
                // use following vars to load content hosted on streaming server
                serverUrl: "rtmp://cp31394.edgefcs.net/ondemand/amgen/docs-enbrel",
                movieUrl: flv_filename,
                
                // use following vars to load local flv's
                //serverUrl: "",            
                //movieUrl: file_path + flv_filename + '.flv',
                
                video_group_name: wt_track_videoGroupName,
		name_of_video: wt_track_videoName,
                isi_duration: isi_duration
	};

	var params = {};
	params.bgcolor = "#ffffff";
	var attributes = {};
	attributes.id = "flash_holder";
	swfobject.embedSWF(file_path + swf_filename, "flash_holder", wid, ht, "9.0.0", "fp_flash/expressInstall.swf", flashvars, params, attributes);
}

var show_hp_video = function(mec_code, wt_track_videoGroupName, wt_track_videoName, isi_duration)
{
	//mecTrack(mec_code);     // MEC tracking
        
        var flashvars = {
		serverUrl: "rtmp://cp31394.edgefcs.net/ondemand/amgen/docs-enbrel/PhilMIntegration",
                movieUrl: flv_filename,
                video_group_name: wt_track_videoGroupName,
		name_of_video: wt_track_videoName,
                isi_duration: isi_duration
	};

	var params = {};
	params.bgcolor = "#ffffff";
	var attributes = {};
	attributes.id = "flash_holder";
	swfobject.embedSWF(file_path + swf_filename, "flash_holder", wid, ht, "9.0.0", "fp_flash/expressInstall.swf", flashvars, params, attributes);
}

function currentVideo(vid) {
    //alert('currentVideo: ' + vid);
      
    $('#raTalksMenu li').each(function() {
        if ($(this).attr('id') == 'ratalks_video' + vid) {
            $(this).css('height','100px');
            $(this).addClass('active');
            $(this).find('div.menuText').show();
            updateTitle($(this));            
        } else {
            $(this).css('height','42px');
            $(this).removeClass('active');
            $(this).find('div.menuText').hide();  
        }
        
        vertAlign($(this));
    });
}

function vertAlign(el) {
    var inEl = el.find('div.inner');
    var outHt = el.height();
    var inHt = inEl.height();
    var inTop = (outHt - inHt) / 2;
    inEl.css('top', inTop+'px');     
}

function updateTitle(el) {
    var ttl = el.find('h2.menuTitle').html();
    $('#popupRaTalksVid #title').html(ttl);     
}

function getID( swfID ){
    me = $('#' + swfID)[0];
/*     
     if(navigator.appName.indexOf("Microsoft") != -1){
          me = window[swfID];
     }else{
          me = document[swfID];
     }    
*/
}

function loadVideo(id){
        getID('FlashContent');
        //alert('loadVideo: ' + id);
        me.loadVideoById(id);
}
                        
var show_ratalks_video = function(mec_code, defaultVid)
{
    //mecTrack(mec_code);     // MEC tracking
    
    var flashvars = {
            xmlLoc: file_path + "xml/vidconfig.xml",
            firstVideo: defaultVid
    };

    //flashvars.serverUrl = "rtmp://cp31394.edgefcs.net/ondemand/amgen/docs-enbrel";
    //flashvars.movieUrl = flv_filename;
    //flashvars.video_group_name = "Group";
    //flashvars.name_of_video = "Video";
    
    var params = {};
    params.bgcolor = "#ffffff";
    params.allowScriptAccess = "always";
    var attributes = {};
    attributes.id = "FlashContent";
    swfobject.embedSWF(file_path + swf_filename, "flash_holder", "640", "360", "9.0.0", false, flashvars, params, attributes);
    
    getID('FlashContent');
    //me.loadVideoById(0);
        
}

var pop_inject_video = function(event)
{
	switch(this.id)
	{
		case "sureclick":
			video_popup_title = "How to Use the Enbrel<sup>&reg;</sup> (etanercept) SureClick<sup>&reg;</sup> Autoinjector";
			job_code = "60071-R1-V1";
                        var bottom_text = "This overview contains only injection highlights. See your health care professional for formal injection training. Please see the<br/><a href='#isi' target='_blank'>Important Safety Information</a> below and refer to the full <a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_pi.pdf' target='_blank'>Prescribing Information</a>, or view the <a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_piu.pdf' target='_blank'>Patient Instructions for Use</a>.";                        
                        file_path = "injection-demos/sureclick/";
			swf_filename = "sureclick_video.swf";
                        wid = "850";
                        ht = "405";
                        footer_class="gray_footer";
                        cur_vid = "sureclick";
                        mec_track_code = "deienb_NEWEnbrelInjectionSureClickVideo_6";
                        wt_track_playerName = "sureclick";
			break;
		case "syringe":
			video_popup_title = "How to Use the Enbrel<sup>&reg;</sup> (etanercept) Single-use Prefilled Syringe";
			job_code = "MC47141-G";
                        var bottom_text = "This overview contains only injection highlights. See your health care professional for formal injection training. Please see the<br/><a href='#isi' target='_blank'>Important Safety Information</a> below and refer to the full <a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_pi.pdf' target='_blank'>Prescribing Information</a>, or view the <a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_piu.pdf' target='_blank'>Patient Instructions for Use</a>.";
                        file_path = "injection-demos/prefilled-syringe/";
			swf_filename = "prefilled_syringe_video.swf";
			wid = "850";
                        ht = "405";
                        footer_class="gray_footer";
                        cur_vid = "prefilled";
                        mec_track_code = "deienb_NEWEnbrelInjectionSingleUseSyringeVideo_6";
			wt_track_playerName = "syringe";
                        break;
		case "freehand":
			video_popup_title = "Steps for Taking Enbrel<sup>&reg;</sup> (etanercept) Using the 25-mg Multi-Use Vial Free-Hand Method";
			job_code = "MC47141-N";
                        var bottom_text = "Please see your health care professional for formal injection training. Please see the <a href='#isi' target='_blank'>Important Safety Information</a> below and refer to the full<br/><a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_pi.pdf' target='_blank'>Prescribing Information</a>, or view the <a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_piu.pdf' target='_blank'>Patient Instructions for Use</a>."
                        file_path = "injection-demos/free-hand/";
			swf_filename = "free_hand_video.swf";
			wid = "850";
                        ht = "405";
                        footer_class = "white_footer";
                        cur_vid = "free_hand_method";
                        mec_track_code = "deienb_NEWEnbrelInjectionVialFreeHandVideo_6";
			wt_track_playerName = "freehand";
                        break;
		case "vialadaptor":
			video_popup_title = "Steps for Taking Enbrel<sup>&reg;</sup> (etanercept) Using the 25-mg Vial Adapter Method";
			job_code = "MC47141-N";
                        var bottom_text = "Please see your health care professional for formal injection training. Please see the <a href='#isi' target='_blank'>Important Safety Information</a> below and refer to the full<br/><a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_pi.pdf' target='_blank'>Prescribing Information</a>, or view the <a href='http://pi.amgen.com/united_states/enbrel/derm/enbrel_piu.pdf' target='_blank'>Patient Instructions for Use</a>."
                        file_path = "injection-demos/vial-adapter/";
			swf_filename = "vial_adapter_video.swf";
			wid = "850";
                        ht = "405";
                        footer_class = "white_footer";
                        cur_vid = "vial_adapter_method";
                        mec_track_code = "deienb_NEWEnbrelInjectionVialAdapterVideo_6";
			wt_track_playerName = "vialadaptor";
                        break;                   
		default:
			video_popup_title = "";
			job_code = "";
                        var bottom_text = "";
                        file_path = "";
			swf_filename = "";
                        wid = "";
                        ht = "";
                        footer_class="";
                        cur_vid = "";
                        mec_track_code = "empty";
			wt_track_playerName = "";
	}

	evokeModalDialog.setBgColor("#ffffff");
	$("#video_title_text").html(video_popup_title);
        $("#jobcode_text").html(job_code);
        $("#bottom_text").html(bottom_text);
        $("#video_footer").removeClass();
        $("#video_footer").addClass(footer_class);
        evokeModalDialog.show("video_container");
	current_video = cur_vid;
        show_inject_video(mec_track_code, wt_track_playerName);
        event.preventDefault();
}

var pop_hp_video = function(event) {

        video_popup_title = "Phil Mickelson and Enbrel<sup>&reg;</sup> (etanercept)";
        file_path = SITEROOT + "/videos/";
        swf_filename = "EVK_Video_Player_Phil.swf";
        flv_filename = "MP4:PhilOnAir_FinalApproved_568x320_512Kb.f4v";
        wid = "568";
        ht = "320";
        cur_vid = "PhilMCommercialvideo";
        mec_track_code = "empty";
        wt_track_videoGroupName = "advocate_video";
        wt_track_videoName = "PhilM";
        isi_duration = 0;
        
        evokeModalDialog.setBgColor("#ffffff");
        $("#video_title_text").html(video_popup_title);
        evokeModalDialog.show("video_container_hp");
        current_video = cur_vid;
        show_hp_video(mec_track_code, wt_track_videoGroupName, wt_track_videoName, isi_duration);	
        event.preventDefault();            
            

}

var pop_video = function(event)
{ 
	if (this.id == "vp_howworks_psa" || this.id == "vp_howworks_psa_img") {  
            video_popup_title = "How ENBREL Works";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player_43.swf";
            flv_filename = "DrLeonardi_MOA_568x383_v1";
            wid = "568";
            ht = "383";
            cur_vid = "MOAvideo";
            mec_track_code = "deienb_NEWEnbrelHowEnbrelWorksVideo_6";
            wt_track_videoGroupName = "other_video";
            wt_track_videoName = "MOA";
            isi_duration = 78;
        } else if (this.id == "vp_moa_101" || this.id == "vp_moa_101_img") {  
            video_popup_title = "How ENBREL Works";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player_43.swf";
            flv_filename = "Enbrel_Shortened_MOA_568x383";
            wid = "568";
            ht = "383";
            cur_vid = "MOA_101video";
            mec_track_code = "";
            wt_track_videoGroupName = "other_video";
            wt_track_videoName = "MOA Abbreviated";
            isi_duration = 59;
        } else if (this.id == "vp_jack" || this.id == "vp_jack_img") {
            video_popup_title = "Jack S. ENBREL user since 2004";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player.swf";
            flv_filename = "Jack_568x320_v2";
            flv_url = "";
            wid = "568";
            ht = "320";
            cur_vid = "JackSAdvocatevideo";
            mec_track_code = "empty";
            wt_track_videoGroupName = "advocate_video";
            wt_track_videoName = "JackS";			
            isi_duration = 278;
        } else if (this.id == "vp_alex" || this.id == "vp_alex_img") {
            video_popup_title = "Alex R. ENBREL user since 2005";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player.swf";
            flv_filename = "Alex_568x320_v2";
            wid = "568";
            ht = "320";
            cur_vid = "AlexRAdvocatevideo";
            mec_track_code = "deienb_NEWEnbrelAlexVideo_6";
            wt_track_videoGroupName = "advocate_video";
            wt_track_videoName = "AlexR";
            isi_duration = 278;
        } else if (this.id == "vp_debra" || this.id == "vp_debra_img") {
            video_popup_title = "Debra J. ENBREL user since 2004";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player.swf";
            flv_filename = "Debra_568x320_v2";
            wid = "568";
            ht = "320";
            cur_vid = "DebraJAdvocatevideo";
            mec_track_code = "deienb_NEWEnbrelDebraVideo_6";
            wt_track_videoGroupName = "advocate_video";
            wt_track_videoName = "DebraJ";
            isi_duration = 278;
        } else if (this.id == "supportVideoBox1") {
            video_popup_title = "<em>ENBREL Support</em>&trade; Services";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player_568_320.swf";
            flv_filename = "Support_Karen_568x320";
            wid = "568";
            ht = "320";
            cur_vid = "SupportServicesVideo";
            mec_track_code = "";
            wt_track_videoGroupName = "services_video";
            wt_track_videoName = "SupportServices";
            isi_duration = 0;
        } else if (this.id == "supportVideoBox2" || this.id == "watchfinancevideo") {
            video_popup_title = "ENBREL Financial Services";
            file_path = SITEROOT + "/videos/";
            swf_filename = "EVK_Video_Player_568_320.swf";
            flv_filename = "Support_Brian_568x320";
            wid = "568";
            ht = "320";
            cur_vid = "FinancialServicesVideo";
            mec_track_code = "";
            wt_track_videoGroupName = "services_video";
            wt_track_videoName = "FinancialServices";
            isi_duration = 0;
        } else {
            video_popup_title = "";
            file_path = "";
            swf_filename = "";
            flv_filename = "";
            wid = "";
            ht = "";
            cur_vid = "";
            mec_track_code = "empty";
            wt_track_videoGroupName = "";
            wt_track_videoName = "";		
            isi_duration = 0;
        }

	evokeModalDialog.setBgColor("#ffffff");
	$("#video_title_text").html(video_popup_title);
        evokeModalDialog.show("video_container");
        current_video = cur_vid;
        show_video(mec_track_code, wt_track_videoGroupName, wt_track_videoName, isi_duration);	
        event.preventDefault();
}

function pop_ratalks_video(defaultVid) {
        numVids = $('#popupRaTalksVid li.outer').length;        
        if (defaultVid > numVids-1 || defaultVid < 0 || isNaN(defaultVid)) defaultVid = 0;
        
        currentVideo(defaultVid);
                
        evokeModalDialog.setBgColor("#ffffff");
        evokeModalDialog.show("popupRaTalksVid");

        file_path = SITEROOT + "/ratalks-videos/";
        swf_filename = "EVK_Video_Player_640_360.swf";

        $('#popupRaTalksVid li.outer').each( function() {
            vertAlign($(this));
        });

        show_ratalks_video('', defaultVid);	
        //event.preventDefault();
}


