var me;

var video_init = function()
{	
        $('#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.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)
        });        
        
        function rollUp() {            
            $(this).find('div.raTalksVideoBoxInfo').animate({
                marginTop: '0'
            }, 250, function() {});            
        }
        
        function rollDown() {    
            $(this).find('div.raTalksVideoBoxInfo').animate({
                marginTop: '81'
            }, 450, function() {});
        }
        
        $('div.raTalksVideoBox, div.raTalksVideoISIBox').click( function() {
            var tid = $(this).attr('id');
            var tidNum = tid.substring(tid.length - 1);
            //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 destroy_flash_element = function(flash_cont, flash_cont_parent) {
    swfobject.removeSWF(flash_cont);
    $('#'+flash_cont_parent).html('<div id="'+ flash_cont +'"></div>'); //recreates the flash holder DOM object that was destroyed by removeSWF
}

function setCurrentVideo(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);
        
}

function pop_ratalks_video(defaultVid) {
        numVids = $('#popupRaTalksVid li.outer').length;        
        if (defaultVid > numVids-1 || defaultVid < 0 || isNaN(defaultVid)) defaultVid = 0;
        
        setCurrentVideo(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();
}


