var oDivPlayer;
var iCuePNum=0;
var oDivLayer;
var oDivChat;


var iTabID=0;
function onLoadShowFlowPlayer()
{
    var sFlowPlayerRelativePath = "http://newwebsite.compulinkgroup.com/FlowPlayer/";//"FlowPlayer/";
    getTabID();
    
    var sFlvFileFullPath = getFlvFileFullPath(sFlowPlayerRelativePath);
    
    createPlayerDiv(sFlvFileFullPath);
    createChatDiv();
    
   var oPlayer=$f("player", {src: sFlowPlayerRelativePath + 'flowplayer.commercial-3.1.1.swf', wmode: 'transparent', play: null}, 
                   {		       
                          
                        key: '#$2ff3235299a49058814',
                        canvas:{
                                backgroundColor:'transparent',
                                backgroundGradient:'none'
                                },                               
                        clip:{
                                url: sFlvFileFullPath,
                                autoPlay: true,
                                autoBuffering: true,
                                onBegin: function () {this.getPlugin("play").css({opacity: 0});},
                                onFinish: function () { hidePlayer();},
                                onCuepoint: function() { cueP(); }
                            },
                        plugins:{
                                controls:null                                          
                                },
                        play: {opacity:0}
                    }
                );	
}

function createPlayerDiv(sFlvFileFullPath)
{
    oDivPlayer=document.createElement("DIV",true)
    oDivPlayer.id= "divPlayer";

    oDivPlayer.style.className="clsDivPlayer";
    oDivPlayer.style.backgroundColor="Transparent"

    oDivPlayer.style.overflow="hidden";

    setPlayerDivProperties();
    
    oDivPlayer.style.position="absolute";
    oDivPlayer.style.zIndex="5";
    
    var sHTML=new String();
    sHTML="<a href='" + sFlvFileFullPath;
    sHTML+= "' id='player' shape='circle' style='background-color:transparent;overflow:hidden;'></a>";

    oDivPlayer.innerHTML=sHTML;
        
    document.body.appendChild(oDivPlayer);   
}

function createChatDiv()
{
    oDivChat = document.createElement("DIV",true)
    oDivChat.id= "divChat";

    oDivChat.style.className="clsDivPlayer";
    oDivChat.style.backgroundColor="Transparent"

    oDivChat.style.overflow="hidden";
    
    var sHTML=new String();
    sHTML="<a href='http://www.salesprolive.com/Chat/chatstart.htm?domain=newwebsite.compulinkgroup.com'";
    sHTML+= " target='_blank' style='background-color:transparent;overflow:hidden;'><img width='159' height='57' src='http://newwebsite.compulinkgroup.com/Portals/0/images/chat_button.gif'> </a>";

    oDivChat.innerHTML=sHTML;
    
    setChatDivProperties();
    
    oDivChat.style.position="absolute";
    oDivChat.style.zIndex="5";
            
    document.body.appendChild(oDivChat);   
        
}

function cueP()
{
    iCuePNum+=1;
    if(iCuePNum==1)
    {
        oDivLayer=document.createElement("DIV",true)
        oDivLayer.id="divLayer";

        oDivLayer.className="clsDivLayer";

        oDivLayer.style.left="0px";
        oDivLayer.style.top="0px";
        oDivLayer.style.position="absolute";

        oDivLayer.style.zIndex="4";
        
         if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER')
	    {
	        oDivLayer.style.width=document.body.offsetWidth;	
            oDivLayer.style.height=document.body.offsetHeight;
        }
        else
        {
	        oDivLayer.style.width=window.innerWidth;
            oDivLayer.style.height=window.innerHeight;
        }
        document.body.appendChild(oDivLayer);       

    }
    else
    {
        oDivLayer.style.display="none";
    }
   
}
function hidePlayer()
{
    oDivPlayer.style.display="none";
}

  
function getChatButton()
{
    
    var arrImgs=document.getElementsByTagName("IMG");
    if(arrImgs !=null && arrImgs.length>0)
    {
        var iCounter=0, iLoop = arrImgs.length;
        var sSrc=new String();
        for (iCounter=0;iCounter<iLoop;iCounter++)
        {
            sSrc=arrImgs[iCounter].src;
            if (parseInt(sSrc.indexOf('chat_button.gif')) >= 0)
                return arrImgs[iCounter];
            sSrc='';
        }
    }
    
}

function getTabID()
{
    var sTabID;
    var iIndex=-1;
    iTabID = -1;
    var sPath= document.location.href;
    if (sPath=="http://newwebsite.compulinkgroup.com/")
        {iTabID=0;return;}
    iIndex = parseInt(sPath.indexOf('tabid'));
    if(iIndex>=0)
    {
        sTabID=sPath.substring(iIndex+6,iIndex+8);
        if (sTabID !=null)          
        {   
            try{iTabID=parseInt(sTabID);}
            catch(e){iTabID=-1;}
        }
    }
}

function getFlvFileFullPath(sRelativePath)
{
    var sFilePath=sRelativePath;
    switch (iTabID)
    {
        case 0:
                sFilePath +="Compulink-intro-half_1.flv";
                break;                
        case 97:
                sFilePath +="HCM-Half_2.flv";
                break;
        case 98:
                sFilePath +="SEM-Half.flv";
                break;
        default:
                throw new exception;
                break;
    }
    return sFilePath;
}

function setPlayerDivProperties()
{
 
    switch (iTabID)
    {

        case 0:
                oDivPlayer.style.width="400px";
                oDivPlayer.style.height="230px";

                oDivPlayer.style.left="375px";
                oDivPlayer.style.top="40px";
                break;

        case 97:
        case 98:
                oDivPlayer.style.width="300px";
                oDivPlayer.style.height="200px";

                oDivPlayer.style.left="400px";
                oDivPlayer.style.top="45px";
                break;
        default: break;
    } 
    
}

function setChatDivProperties()
{
    oDivChat.style.width="159px";
    oDivChat.style.height="57px";

    switch (iTabID)
    {

        case 0:            
                oDivChat.style.left="250px";
                oDivChat.style.top="50px";
                break;

        case 97:
        case 98:
                oDivChat.style.left="725px";
                oDivChat.style.top="45px";
                break;
        default: break;
    } 
    
}