var trackItTracking = {
	Init: function() {
		
		/* trackIt instance */
		var options = {
			XmlUrl: "/assets/xml/trackItData.xml",
			Plugins: [ 
				$.TrackItPlugins.CheckUrlMapping,
				$.TrackItPlugins.CssSelector
			],
			Holders: { 
				'productFlavor': function() { return $(this).closest('li').attr('class'); },
				'addThisService':  function() { return $(this).attr('id').substr(5); },
				'selectedVideo': function() { 
					 var theSeason = $(this).closest('div').attr('id');
					 var theTitle = $(this).attr('title').match(/[^-]+/i).toString();
					 theTitle = $.trim(theTitle);
					 return (theSeason + ' ' + theTitle);
				 },
				 'formOrComplete' : function() {
					 //var thankYou = $('.thankyou');
					 if ( $('.thankyou').length > 0 ) {
						 return "Complete";
					 }
					 else { return "Form"; }
				 }
			},
			Settings: {
				//TestMode: true,
				//ShowDebugInfo: true,
				//ShowMissingHolderWarnings: true
				//SanityCheckMissingOnly: true
			}
		};
		raisinetsTracker = new $.TrackIt("omniture", options);
		
		/* trackItTracking.formTracking(); */
	},
    
    handleYouTubeStateChange: function(state) {
		if ($('div.webisodesPage').length > 0) {
			var youtubeControl;
			var season = $('.sMove ul li a.active').closest('div').attr('id');
			vidName = vidName.match(/[^-]+/i).toString();
			vidName = $.trim(vidName);
			var webisodeName = season + ' ' + vidName;
			switch(state) {
				case 0: 
					youtubeControl = 'end';
					break;
				case 1: 
					if (videoPaused) {
						youtubeControl = 'restart';
						videoPaused = false;
					}
					else {
						youtubeControl = 'start';  //YT 'playing' event
					}
					break;
				case 2: 
					youtubeControl = 'pause';
					videoPaused = true;
					break;
				case 5: //YT 'cued' event
					youtubeControl = 'load';
					videoPaused = false;
					break;
			
			}
			
			if ( (state == 0) || (state == 1) || (state == 2) || (state == 5) ){
				raisinetsTracker.track("YoutubeEvent", { 
					"youtubeControl": youtubeControl,
					"webisodeName": webisodeName
				});
				//console.info('state ' + state + videoPaused + webisodeName);
			}
		}
		
	    
    },
    starStruckSweepsSteps: function(){
        if ($('body.registration-step1').length){
            raisinetsTracker.track("SweepsStep1Load");
        }
        if ($('body.registration-step2').length){
            raisinetsTracker.track("SweepsStep2Load");
        }
        if ($('body.registration-step3').length){
            if ($('.mainContainer.not_eligible').length){
                raisinetsTracker.track("SweepsNotEligible");
            }
            else if($('.mainContainer.once_day').length){
                raisinetsTracker.track("SweepsEnterOnce");
            }
            else {
                raisinetsTracker.track("SweepsStep3Load");
            }
        }
        if ($('body.registration-step4').length){
            raisinetsTracker.track("SweepsStep4Load");
        }

    }
    

	
}

$(trackItTracking.Init);
$(trackItTracking.starStruckSweepsSteps);

