//max number of times to create custom invite before aborting
var LP_CUSTOM_INVITE_MAX_LOOPS = 5;
var lpLineCt = 0;

//image path, MUST end with '/'
var lpInviteImagePath = "/webapp/wcs/stores/jcwhitney/jcw/include/lp/chat_deployment_local-jcwhitney/images/jcw_product/alt_invitation/";

function lpCreateCustomInvitation(){
    var lpCustomInnerInvitationHtml = "";
    var lpForceInviteCreate = false;
    
    //Wait for the Monitor tag to create the original "mylayer" DIV (that's where the standard invitation is created)
    if (!document.getElementById("mylayer")){
     
        //Loop no more than LP_CUSTOM_INVITE_MAX_LOOPS times, to avoid endless loop in case
        //the DIV is not found
        if(LP_CUSTOM_INVITE_MAX_LOOPS > 0){
            LP_CUSTOM_INVITE_MAX_LOOPS--;
            setTimeout('lpCreateCustomInvitation()', 1000);
            return;
        }
        else{
            //Max loops has passed, so mark we need to create the invitation
            lpForceInviteCreate = true;
        }
    }
    
    //set the invitation content into the lpCustomInnerInvitationHtml variable(WITHOUT THE WRAPPING DIV)
  lpCustomInnerInvitationHtml = '';
    lpCustomInnerInvitationHtml += '<div style="background-image: url(' + lpInviteImagePath + 'jcwhitney_bg.gif); background-repeat: no-repeat; width: 238px; height: 333px;">';
    lpCustomInnerInvitationHtml += '<div style="position: absolute; left: 150px; top: 15px; z-index: 200;"><a onclick="return hcRejectCall();" href="#"><img src="' + lpInviteImagePath + 'nothanks_off.gif" name="nt" width="79" height="16" border="0" id="nt" onmouseover="javascript:this.src=\'' + lpInviteImagePath + 'nothanks_on.gif\';" onmouseout="javascript:this.src=\'' + lpInviteImagePath + 'nothanks_off.gif\';"/></a></div>';
    lpCustomInnerInvitationHtml += '<div style="position: absolute; top: 167px; left: 21px; width: 200px; height: 97px; text-align:center;">';
    lpCustomInnerInvitationHtml += '<p><span style="font-family: Arial; font-size: 12px; color: rgb(0, 0, 0); font-weight: bold; visibility: hidden;" id="l1b">Welcome to JC Whitney!</span></p>';
    lpCustomInnerInvitationHtml += '<p><span style="font-family: Arial; font-size: 12px; color: rgb(0, 0, 0);font-weight: normal; visibility: hidden;" id="l2b">I can help you find what you\'re looking for.</span></p></div>';
    lpCustomInnerInvitationHtml += '<div style="position: absolute; top: 282px; left: 68px; width: 108px; height: 35px;"><a id="needRef" name="needRef" onclick="return hcAcceptCall();" href="#"><img src="' + lpInviteImagePath + 'chatnow_transparent.gif" width="108" height="35" border="0"/></a></div></div>';



    //if need to create the DIV
    if(lpForceInviteCreate){
        //call a method of the Monitor tag to create the div with our own content
        lpCreateGenericDiv('mylayer', 200, 170, 90, lpInnerInvitationHtml, null, null, false);
    }
    else{
         //replace current invitation content with custom one
         document.getElementById("mylayer").innerHTML = lpCustomInnerInvitationHtml;
    }
    
    //mark the invitation has loaded
     hcFloatIconLoaded();
    //If needed, modify any styling details of the invitation DIV now (e.g, change width and height)
    //document.getElementById("mylayer").style.backgroundColor = "#fff";
    document.getElementById("mylayer").style.zIndex = "2000";
}

//call method to create custom invite
lpCreateCustomInvitation();

// Override this Monitor method in order to start the text timer
function hcShowTheImage(){
	visitorStatus = "ENGAGE_STATUS";
	setTimeout("inviteShown()", 5000);
	hcShowImage = true;
	hcAnimate = true;
	hcPreload();
	hcAnimateStart();
	startLines();
}
//override so we hide the rolling text
function hcHideTheImage(){

	hcShowImage = false;
    lpVoiceEngageFlag = false;
    document.getElementById("l1b").style.visibility = "hidden";
    document.getElementById("l2b").style.visibility = "hidden";
    hcGetObj("mylayer").style.visibility = "hidden";
}

function startLines(){
    switch(lpLineCt){
        case 0: lpLineCt += 1;setTimeout('startLines()', 1000); break;
        case 1: 
                document.getElementById("l1b").style.visibility = "visible";
                lpLineCt += 1;
                setTimeout('startLines()', 1000);
                break;
        case 2: 
                document.getElementById("l2b").style.visibility = "visible";
                lpLineCt = 0;
                break;
    };
}


/*********************** 
The following was copied from the current customizations JCWhitney added to fix the drop-down bug 
I renamed lpCreateCustomInvitation to  lpRepositionInvitation so it doesn't override our method above
******************/


//Specify iframe to display. Change src and other attributes except "position" and "left/top":
var iframetag='<iframe id="myiframe" src="/webapp/wcs/stores/jcwhitney/jcw/include/lp/chat_deployment_global/lp/blank.html" width="239px" height="329px" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" visibility="hidden" scrolling="no" style="position: absolute; left: 50px; top: 50px;"></iframe>'
	
//specify x coordinates of iframe ("right" for right corner, or a pixel number (ie: "20px")):
var masterdivleft="52px"

//specify y coordinates of iframe ("bottom" for bottom of page, or a pixel number (ie: "20px")):
var masterdivtop="52px"

var ie=(document.all || window.opera) && document.getElementById
var iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
var IfrRef;

//Setup the IFrame
if(ie){
	document.write(iframetag)
	IfrRef = document.getElementById("myiframe");
	IfrRef.style.visibility = "hidden";
}

function lpRepositionInvitation(){
    var browserIE = (document.all) ? true : false;
    	
    if(browserIE){
      	var InviteRef = document.getElementById("mylayer");
		
		//display iframe visibility to same as invite
        if (InviteRef.style.visibility == "visible") 
     		IfrRef.style.visibility = "visible";
     	else if(InviteRef.style.visibility == "hidden") 
    		IfrRef.style.visibility = "hidden";
    	else
    		IfrRef.style.visibility = "hidden";
    		
        }
}

function positionit(){
	masterdivobj=document.getElementById("myiframe")
	var window_width=ie && !window.opera? iebody.clientWidth : window.innerWidth-20
	window_height=ie && !window.opera? iebody.clientHeight : window.innerHeight
	var dsocleft=ie? iebody.scrollLeft : pageXOffset
	var masterdivwidth=masterdivobj.width
	masterdivheight=masterdivobj.height
	masterdivobj.style.left=(masterdivleft=="right")? window_width-masterdivwidth-20 : masterdivleft
	setInterval("repositionit()", 100)
}

function repositionit(){
	if (ie){
		dsoctop=ie? iebody.scrollTop : pageYOffset
		masterdivobj.style.top=(masterdivtop=="bottom")? window_height-masterdivheight-14+dsoctop : parseInt(masterdivtop)+dsoctop
		lpRepositionInvitation();
	}
}

if (window.attachEvent)
    window.attachEvent("onload", positionit)
