var CursorTrailPreview = {};

CursorTrailPreview.GetXContent = function(RequestFile,RecordID){
     var request = new CHttpRequest();
    request.QueryString = "AjaxType=HTML&RequestFile="+RequestFile+"&MethodName=GetXContent";
    request.AsyncCall = true;   
    request.State = "";
    //alert(RecordID);
    request.AddProperty("Arguments[RecordID]",RecordID);
    request.OnResponse = CursorTrailPreview.ShowProductContent_Callback;
    request.Send();
}
CursorTrailPreview.ShowProductContent_Callback = function(request, state){	
	
	if(!document.getElementById("trailimageid")){	
	    Div = document.createElement("div");
	    Div.id = "trailimageid";
	    Div.style.position = "absolute";	
	    Div.style.zIndex = "2000";
	    //Div.style.border = "solid 1px #dfdfdf";
	    Div.style.left = '0px';
	    Div.style.top = -1000;
	    Div.style.width = "300px";
	    Div.style.height = "300px";
	    Div.style.display = "block";
	    
	    Div.innerHTML = request.responseText;
    	
	    document.getElementsByTagName("BODY")[0].appendChild(Div);	
	    document.onmousemove = CursorTrailPreview.FollowMouse;
	}
	state.disabled = false;
}

CursorTrailPreview.GetTrailObj = function(){
    if (document.getElementById("trailimageid")) 
        return document.getElementById("trailimageid").style
    else if (document.all) 
        return document.all.trailimagid.style
}

CursorTrailPreview.FollowMouse = function(e){    
    Elem = document.getElementById("trailimageid");
    if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1 && Elem) {
        var xcoord=20
        var ycoord=20
        //var w = CursorTrailPreview.GetTrailObj().width;
        //var h = CursorTrailPreview.GetTrailObj().height;
        
        if (typeof e != "undefined"){
            xcoord+=e.pageX
            ycoord+=e.pageY
        }else if (typeof window.event !="undefined"){
            xcoord+=CursorTrailPreview.TrueBody().scrollLeft+event.clientX
            ycoord+=CursorTrailPreview.TrueBody().scrollTop+event.clientY
        }

        var docwidth=document.all? CursorTrailPreview.TrueBody().scrollLeft+CursorTrailPreview.TrueBody().clientWidth : pageXOffset+window.innerWidth-15
        var docheight=document.all? Math.max(CursorTrailPreview.TrueBody().scrollHeight, CursorTrailPreview.TrueBody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
        
        if (xcoord+(Elem.style.width)+3>docwidth)
        xcoord=xcoord-(Elem.style.width)-(20*2)

        if (ycoord-CursorTrailPreview.TrueBody().scrollTop+(Elem.style.height)>CursorTrailPreview.TrueBody().clientHeight)
        ycoord=ycoord-(Elem.style.height)-20;
        
        Elem.style.left=xcoord+"px";
        Elem.style.top=ycoord+"px";
    }
}


CursorTrailPreview.TrueBody = function(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

CursorTrailPreview.HideTrail = function(){
   Elem = document.getElementById("trailimageid");
    if(Elem){
        Elem.style.display="none";
        Elem.style.left=-1000;
        Elem.style.top=0;
        Elem.innerHTML = '';
        document.getElementsByTagName("BODY")[0].removeChild(document.getElementById("trailimageid"));
    }
}