/*                                                                  
* Copyright © 1999-2008 TeaLeaf Technology, Inc.  
* All rights reserved.
*
* THIS SOFTWARE IS PROVIDED BY TEALEAF ``AS IS'' 
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE DISCLAIMED.  
* IN NO EVENT SHALL TEALEAF BE LIABLE FOR ANY DIRECT, INDIRECT, 
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
* @fileoverview 
* This is the configuration file for capturing Client Events that 
* happen on the rendered Flash movie. 
*
* @version 2009.07.09.1
*
* StubHub fix/enhancement
* 4/5/2010: added test in tlFlushXML to prevent errors on pages that do not contain a flash movie object
*                                                                   
*/

if(typeof TeaLeafFlashCfg == "undefined"){
	var TeaLeafFlashCfg = {};

   	if(typeof TeaLeafFlashCfg.Configuration == "undefined"){
	    	TeaLeafFlashCfg.Configuration = {
		 	    "tlversion"                 : "2009.07.09.1",
		    	"tlurl"                     : "/TeaLeafTarget.html",
            	"tlqueueevents"             : false,
            	"tlqueueeventstimer"        : 30000,
            	"tlqueueeventsmaxsz"        : 8192,	    
           		"tlrepalay"		            : false,
           		"tlflashname"               : "FlashNameHere",	    
	 
			tlFlashCaptureEvents:[
				// mouse events
				{"tlcaptureflashevent": "click",	    "tlattach": true},
				{"tlcaptureflashevent": "doubleClick", 	"tlattach": false},
				{"tlcaptureflashevent": "mouseDown", 	"tlattach": false},
				{"tlcaptureflashevent": "mouseMove", 	"tlattach": false},
				{"tlcaptureflashevent": "mouseOut", 	"tlattach": false},
				{"tlcaptureflashevent": "mouseOver", 	"tlattach": false},
				{"tlcaptureflashevent": "mouseUp", 	    "tlattach": false},
				{"tlcaptureflashevent": "mouseWheel", 	"tlattach": false},
				{"tlcaptureflashevent": "rollOut", 	    "tlattach": false},
				{"tlcaptureflashevent": "rollOver", 	"tlattach": false},
				
				//keyboard events
				{"tlcaptureflashevent": "keyDown", 	"tlattach": true},
				{"tlcaptureflashevent": "keyUp", 	"tlattach": false},
				
				//context menu event
				{"tlcaptureflashevent": "menuItemSelect",   "tlattach": false},
				{"tlcaptureflashevent": "menuSelect", 	    "tlattach": false},
				
				//text input event
				{"tlcaptureflashevent": "link",		    "tlattach": false},
				{"tlcaptureflashevent": "textInput", 	"tlattach": true},

				//state change event
				{"tlcaptureflashevent": "currentStateChange",	"tlattach": true},
				{"tlcaptureflashevent": "currentStateChanging", "tlattach": true},
				
				//focus events
				{"tlcaptureflashevent": "focusIn", 	        "tlattach": false},
				{"tlcaptureflashevent": "focusOut",         "tlattach": false},
				{"tlcaptureflashevent": "keyFocusChange", 	"tlattach": false},
				{"tlcaptureflashevent": "mouseFocusChange", "tlattach": false}
		    ],
		    tlSingleAttach:[
			    {"tlcaptureflashevent": "click",	"domelementName": "update4"},
			    {"tlcaptureflashevent": "click",     "domelementName": "update5"},
			    {"tlcaptureflashevent": "mouseDown",	"domelementName": "update4"},
			    {"tlcaptureflashevent": "mouseDown",	"domelementName": "update5"}
		    ],

			tlHTTPRequestHeaders:[
				{"tlreqhttpheadername": "Content-Type",		"tlsethttpheader": true,    "tlreqhttpheadervalue": "text/xml"},
				{"tlreqhttpheadername": "X_TEALEAFTYPE", 	"tlsethttpheader": true,    "tlreqhttpheadervalue": "GUI"},
				{"tlreqhttpheadername": "X_TEALEAF", 		"tlsethttpheader": true,    "tlreqhttpheadervalue": "ClientEvent"}
		    	]
	    	};
    	}

	TeaLeafFlashCfg.tlreturnCfg = function(){
        	return TeaLeafFlashCfg.Configuration.tlFlashCaptureEvents;
	}	

	TeaLeafFlashCfg.tlgetHTTPRequestHeaders = function(){
        	return TeaLeafFlashCfg.Configuration.tlHTTPRequestHeaders;
	}

	TeaLeafFlashCfg.tlgetUrl = function(){
		return TeaLeafFlashCfg.Configuration.tlurl;	
	}	

	TeaLeafFlashCfg.tlQueueEvents = function(){
		return TeaLeafFlashCfg.Configuration.tlqueueevents;	
	}	

	TeaLeafFlashCfg.tlQueueTimer = function(){
		return TeaLeafFlashCfg.Configuration.tlqueueeventstimer;	
	}
	
	TeaLeafFlashCfg.tlQueueSize = function(){
		return TeaLeafFlashCfg.Configuration.tlqueueeventsmaxsz;	
	}	

	TeaLeafFlashCfg.tlReplay = function(){
		return TeaLeafFlashCfg.Configuration.tlrepalay;	
	}

	TeaLeafFlashCfg.tlalert = function(tlvar){
		alert("tl: "+tlvar);	
	}
	
	TeaLeafFlashCfg.tlreturnSingleCfg= function(){
		return TeaLeafFlashCfg.Configuration.tlSingleAttach;
	}
    
    TeaLeafFlashCfg.tlAddHandler = function(tlitem, tlevt, tlhandler, tlcapture) {		
		try {
			    if( tlitem.addEventListener ) {
					if(navigator.userAgent.toLowerCase().indexOf('safari')!=-1){
						    tlitem.addEventListener('on'+tlevt, tlhandler, tlcapture);                                          
					}
					else{
						    tlitem.addEventListener(tlevt, tlhandler, tlcapture);
					}
			    }
			    else if( tlitem.attachEvent ) {
					tlitem.attachEvent('on'+tlevt, tlhandler);
			    }
		}
		catch(exc) {
		}
	}	
	

    TeaLeafFlashCfg.tlFlashMovie = function (movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName];
        } else {
            return document[movieName];
        }
    }

	TeaLeafFlashCfg.tlFlushXML = function(){
		/* Stubhub fix to prevent errors on pages that do not contain a flash movie */
		var tlFlashMovie = TeaLeafFlashCfg.tlFlashMovie(TeaLeafFlashCfg.Configuration.tlflashname);
	    if (typeof tlFlashMovie !== "undefined") {
	    	tlFlashMovie.tlFlushXML();
	    }
	}
}

TeaLeafFlashCfg.tlAddHandler(window, "beforeunload", TeaLeafFlashCfg.tlFlushXML, false);
TeaLeafFlashCfg.tlAddHandler(window, "unload", TeaLeafFlashCfg.tlFlushXML, false);

