/* ============================================================================== */
/* = Copyright © 2007 Wired Ground, LLC.										= */
/* =																			= */
/* =        Name : Exit Logger													= */
/* =																			= */
/* =   Developer : Wired Ground													= */
/* =        Date : December 12, 2007											= */
/* =																			= */
/* = Description : 																= */
/* ============================================================================== */

(function() {
		  
	wgExitLog = {
		
		linkId:					null,					// Insert Comment
		linkLocation:			window.location.host,	// Insert Comment
		
		
		// ====================================================================== //
		// =    function : addEvent												= //
		// = description : 														= //
		// ====================================================================== //
		addEvent: function(obj, type, fn, tmp) {
			
			tmp || (tmp = true);
			
			if( obj.attachEvent ) {
				
				obj["e"+type+fn]	= fn;
				obj[type+fn]		= function(){obj["e"+type+fn]( window.event );};
				obj.attachEvent( "on"+type, obj[type+fn] );
				
			}
			else {
				
				obj.addEventListener( type, fn, true );
				
			};
        },
        
		
		// ====================================================================== //
		// =    function : removeEvent											= //
		// = description : 														= //
		// ====================================================================== //
        removeEvent: function(obj, type, fn, tmp) {
			
			tmp || (tmp = true);
			
			try {
				
				if( obj.detachEvent ) {
					
					obj.detachEvent( "on"+type, obj[type+fn] );
					obj[type+fn] = null;
					
				}
				else {
					
					obj.removeEventListener( type, fn, true );
					
				};
			}
			catch(err) {};
			
        },


		// ====================================================================== //
		// =    function : stopEvent											= //
		// = description : 														= //
		// ====================================================================== //
        stopEvent: function(e) {
			
			e = e || window.event;
			
			if(e.stopPropagation) {
				
				e.stopPropagation();
				e.preventDefault();
				
			};
			
			/*@cc_on@*/
			/*@if(@_win32)
			e.cancelBubble = true;
			e.returnValue = false;
			/*@end@*/
			
			return false;
		},
		
		
		// ====================================================================== //
		// =    function : initEvt												= //
		// = description : 														= //
		// ====================================================================== //
		initEvt: function(e) {
			
			wgExitLog.init(false);
			
		},
		
		
		// ====================================================================== //
		// =    function : init													= //
		// = description : 														= //
		// ====================================================================== //
		init: function(linkId) {
			
			if (!document.getElementsByTagName || !document.createElement || !document.getElementById) return;
			
			var links = linkId && document.getElementById(linkId) ? [document.getElementById(linkId)] : document.getElementsByTagName("a");
			var exitlog;
			
			for(var k = 0, lnk; lnk = links[k]; k++) {
				
				exitlog = false;
				
				if(lnk.href.search(window.location.host) == -1) exitlog = true;
				
				if(!exitlog) continue;
				
				if((lnk.href.indexOf("javascript") == -1) && (lnk.href.indexOf("pdf") == -1) && (lnk.href.indexOf("flickr") == -1))
				{
					//lnk.onclick = wgExitLog.onClickEvt;
					lnk.href = "/act_exitlog.cfm?address_from=" + wgExitLog.linkLocation + "&address_to=" + lnk.href;
				}
			}
			
		},
		
		
		// ====================================================================== //
		// =    function : onClickEvt											= //
		// = description : 														= //
		// ====================================================================== //
		onClickEvt : function(e) {
			e = e || window.event;
			
			//alert ("You came from " + wgExitLog.linkLocation + ". And are going to " + e.target.href + ".");
			window.open("/act_exitlog.cfm?address_from=" + wgExitLog.linkLocation + "&address_to=" + e.target.href, "ResortInformation");
			
			return false;
			
		},
		
		
		// ====================================================================== //
		// =    function : onUnload												= //
		// = description : 														= //
		// ====================================================================== //
		onUnload: function() {
			
			wgExitLog.removeEvent(window, "load", wgExitLog.initEvt);
			wgExitLog.removeEvent(window, "unload", wgExitLog.onUnload);
		
		}
	};

})();


wgExitLog.addEvent(window, "load",   wgExitLog.initEvt);
wgExitLog.addEvent(window, "unload", wgExitLog.onUnload);
