

// ---------------------------- Omniture Class ---------------------------------------------------------------------------- //


	/**
	 * 
	 * Handles all data preparation and interaction with the Omniture reporting code (s_code.js)
	 * 
	 */
	function Omniture(){
		this.args = {};
		this.pageName = null;
		this.sEvents = null;
        this.products = null;
	};
	
	
	Omniture.prototype = {
		// handle basic ominture tracking events
		event : function(eventName, args){
			// Do nothing if Omniture is disabled
			
			propNum = 40;
			varNum = 20;
			
			this.args = args;
			var channel, n;
			
			// get the current user and site IDs - should eventually switch to having this set instead of retrieving them
			//this.prop8 = sys_userId;
			//this.eVar8 = sys_userId;
			
			//var site =  ide.user.getSite();
			//if (site) {
				//this.eVar9 = site.id;
			//}
			
			// call the specific method for the omniture event
			if (this[eventName]) {
				this[eventName]();
			}
			
			if (this.channel) {
				channel = this.channel;
				this.channel = null;
			} else {
				channel = 'Site Builder';
			}

			// set up extra reporting for internal testing systems
			var host = location.hostname;
			var re1 = /synthasite\.net|yola\.net/
			var re2 = /synthasite\.development|yola\.development/
			var re3 = /livetest\.synthasite\.net|livetest\.yola\.net/
			var test;
			
			if (host.match(re2)) {
				test = 'localEnv';
			
			// act like production if we're on livetest
			} else if (host.match(re3)) {
				test = null;
			
			// for any other dev environment, do console logging
			} else if (host.match(re1) ) {
				test = 'testEnv';
			}
				
			
			if (this.pageName) {
				// print extra data to the console if we're in a test environment and have Firebug
                                //test = true; //force logging on. NB: doesnt send data to omniture when logging
				if (window.console) {
					var str = 'pageName: ' + channel + ': ' + this.pageName + '\nchannel: ' + channel +'\n';
					if (this.sEvents) str+= 'sEvents: ' + this.sEvents + '\n';
					if (this.products) str+= 'products: ' + this.products + '\n';
					
					for (n=1; n <= propNum; n++) {
						if (this['prop' + n]) str += 'prop' + n + ': ' + this['prop' + n] + '\n';
					}
					for (n=1; n <= varNum; n++) {
						if (this['eVar' + n]) str += 'eVar' + n + ': ' + this['eVar' + n] + '\n';
					}
					
					console.log(str);
				}
				
				
				// set the actual omniture values
				if (! test || test == 'testEnv') {
					// set the basic event vars
					s.pageName = channel + ': ' + this.pageName;
					s.channel = channel;
					if (this.sEvents) s.events = this.sEvents;
					if (this.products) s.products = this.products;
					
					// set the props and eVars
					for (n=1; n <= propNum; n++) {
						if (this['prop' + n]) s['prop' +n] = this['prop' + n];
					}
					for (n=1; n <= varNum; n++) {
						if (this['eVar' + n]) s['eVar' + n ] = this['eVar' + n];
					}
					
					// invoke the actual omniture tracking
					s.t();
				}
			}
			
			// reset local vars
			this.pageName = null;
			this.sEvents = null;
			this.products = null;
			this.channel = null;
			
			for (n=1; n <= propNum; n++) {
				this['prop' + n] = null;
			}
			for (n=1; n <= varNum; n++) {
				this['eVar' + n] = null;
			}
			
			// reset omniture vars
			 s.clearVars("pageName,events,channel,products",1);
		},
		
		
		/****
		// methods to handle specific omniture events
		****/ 
		
		/*
		signup : function() {
			
		},
		*/

        domainRenewalLand: function() {

            this.pageName = "Domain Selection Page"
            this.channel  = "Renew Domains"
            this.eVar8    = this.args.userId
            this.prop8    = this.args.userId
            //this.eVar9    = this.args.siteId

        },

        domainRenewalClick: function() {

            this.pageName = "Domain Selection Page: Click Renew"
            this.channel  = "Renew Domains"
            this.eVar8    = this.args.userId
            this.prop8    = this.args.userId
            //this.eVar9    = this.args.siteId

        },

        domainRenewalSuccess: function() {

            this.pageName = "Purchase Success Page"
            this.channel  = "Renew Domains"
            this.eVar8    = this.args.userId
            this.prop8    = this.args.userId
            this.sEvents   = "event41,event39,purchase";
            this.products = this.args.products
            //this.eVar9    = this.args.siteId

        },
		
		upgradeDomainClicks : function() {
			this.pageName="My Sites: Your Sites: Click Upgrade Your Domain Name"
			this.channel="My Sites"
			this.eVar8=this.args.userId
			this.prop8=this.args.userId
		},
		
		billingInformation : function() {
			this.pageName="Domain Purchase Funnel: PG: Billing Information"
			this.channel="Site Builder"
			this.sEvents="event14"
			this.eVar9=this.args.siteId                                
			this.eVar8=this.args.userId
			this.prop8=this.args.userId
		},
		
		securityTag : function(){
			this.pageName="Domain Purchase Funnel: PG: Security Code Page"
			this.channel="Site Builder"			
			this.eVar9=this.args.siteId                                
			this.eVar8=this.args.userId
			this.prop8=this.args.userId
		},

		removeYolaLinkPaymentSuccess : function(){
			this.pageName="Remove Yola Link: Purchase Success Page"
			this.channel="My Sites"
                        this.sEvents="event25,event39,purchase"
                        this.products=this.args.products
			//this.eVar9=this.args.siteId
			this.eVar8=this.args.userId
                        this.prop6='Remove Yola Link Purchase Success Page'
			this.prop8=this.args.userId
		},
		yepClicked : function(){
			this.pageName="Click YEP Link on Website Footer"
			this.channel="YEP"
		},
		yepSignupSuccess : function(){
			this.pageName="Experts Program Submission"
			this.channel="YEP"
		},
		
		errorPage : function(){
			this.pageName="Domain Purchase Funnel: PG: Billing Information"
			this.channel="Site Builder"
			this.sEvents="event14"
			this.eVar14=this.args.errorType
			this.eVar9=this.args.siteId                                
			this.eVar8=this.args.userId
			this.prop8=this.args.userId
		},
		
		/****
		// helper methods for processing, retrieving or setting various bits of info
		****/ 
		// helper method to set site id
		setSiteID : function(siteID) {
			this.siteID = siteID;
			s.eVar9 = siteID;
		},
		
		// helper method to set user id
		setUserID : function(userID) {
			this.userID = userID;
			s.prop8 = userID;
		},
		
		// helper method to get page type
		getPageType : function() {
			var pageType = 'Unknown';
			
			if (this.args.pageType) {
				if(this.args.pageType == "b5f0891a-bf84-102b-a992-00163e000015") {
					pageType = 'Blog';
				} else {
					pageType = 'Web';
				}
			}
			
			return pageType;
		},
		
		// helper method to verify if we're tracking a particular widget
		getWidgetType : function() {
			var widgetID, widget;
			
			if (this.args) {
				widgetID = this.args.widgetID;
			}

			// only track the following widgets - if we shift to tracking all, we should probably remove this
			switch (widgetID) {
				case "1":
					widget = 'Image';
					break;
					
				case "14":
					widget = 'Text';
					break;
					
				case "24": //HTML widget
					widget = 'HTML';
					break;
					
				case "d8bc7de5-047b-4809-8f95-aba542a2ebe9":
					widget = 'WidgetBox';
					break;
					
				case "635e59a6-9ee7-102b-9124-001111414a2c":
					widget = 'WidgetBox Gallery';
					break;
					
				case "c94777ec-63e3-401d-a09f-ae1513579af7":
					widget = 'File';
					break;
					
				case "affe3150-e210-43ab-9492-7f47f89c3aba":
					widget = 'Google Gadget';
					break;
					
				case "df48ffa0-2a60-49a8-80ed-5482f74b5b7d":
					widget = 'Slide';
					break;
					
				case "424701b3-33cc-458d-a732-40b6bac7e440":
					widget = 'Spring';
					break;
					
				case "d7360c36-f252-4484-aaa4-3f8c73128d1a":
					widget = 'YourMinis';
					break;
					
				case "3a44cc23-1354-4d9c-aa46-382c826dba4f":
					widget = 'Genbook';
					break;
					
				case "601b3fba-aeda-4f7d-98c8-a1ce2258399d":
					widget = 'RSS Reader';
					break;
					
				case "1e75060e-90c1-4b58-b433-d0153ebbbf2f":
					widget = 'Skype Me';
					break;
					
				case "1dde0904-16b9-4676-8964-bfa759e1d207":
					widget = 'Countdown';
					break;
					
				case "ac4c24d6-a662-102b-a1f9-000f0148fd92":
					widget = 'Meebo Chat Room';
					break;
			}
			
			return widget;
		},
		
		// get the currently selected site style
		getStyle : function() {
			if (this.args) {
				return this.args.styleID;
			}
		}
	}

//attach events:
if (typeof(jQuery) != 'undefined') {
    jQuery(document).ready(function(){
    if($("a[href='http://yep.yola.com']")){
        $("a[href='http://yep.yola.com']").bind('click',function(){
            var omniture = new Omniture();
            omniture.event("yepClicked");
        });
    }});
}

