// get quick view photo clicks
// and send image request to Site Catalyst
// via OmnitureStandardTracking.jsp
// expand quick view data track in propertySearchScripts.js

// Please refer to eBusiness_Docs/Software_Development/Design/Web Analytics 
// for implementation guide and variables list SDR

var omniQuickViewTracking = {

	init : function() {
		
		if(document.getElementById("omniSiteTrackingOn") && document.getElementById("omniSiteTrackingOn").value == "true") {
		
			// attatch tracking event to quick view photo
			var quickViewPhotos = YAHOO.util.Dom.getElementsByClassName("carousel-component");
			YAHOO.util.Event.addListener(quickViewPhotos, "click", omniQuickViewTracking.quickViewPhotoClick);
		
		}
	},
			
	quickViewPhotoClick : function() {
	
		var code = this.id.substring(0,5);
		var siteSection = "";
		var MARSHA = "";
		var roomPool = "";
		var theURL = window.location.href;
		
		if(document.getElementById("omniCustomPages")) {
			if(document.getElementById("omniCustomPages").value.match("searchResults") != null || theURL.match("/meetings/group-travel/findHotels.mi") != null) {
				MARSHA = code;
				siteSection = "searchResults";
			} else if(document.getElementById("omniCustomPages").value.match("hws") != null) {
				roomPool = code;
				siteSection = "hws";
				if(document.getElementById("omniProduct") && document.getElementById("omniProduct").value != ";") {
					MARSHA = document.getElementById("omniProduct").value.substring(1);
				}
			}
		}
		
		// function exists in omniTrackSeparateRequests.js and sends to Omniture
		// data of the first quick view photo clicked only
		sendQuickViewPhoto(siteSection, MARSHA, roomPool);
	}
};

// add load event function to page
function addLoadEvent(func) {
  		var oldonload = window.onload;
  		if (typeof window.onload != 'function') {
    		window.onload = func;
  		} else {
    		window.onload = function() {
      		oldonload();
      		func();
    	}
  	}  	
}

addLoadEvent(omniQuickViewTracking.init);