 //
 // Tv JS Framework starts here
 // Dependency: YUI framework, Base TV class
 // 

 // Namespace declaration
 if (typeof Tv == "undefined") {
	 
	 var Tv = function() {};
	
	 // Class declaration
	 Tv.Campaign 	= function() {};
	 Tv.Session	 	= function() {};
	 Tv.Event		= function() {};
	 Tv.Page		= function() {};
	 Tv.Meeting		= function() {};
	 Tv.Tag			= function() {};
 };
 
 //
 // Tv.Event class definition
 //
 (function() {
/*	 
	 var camp = Tv.Campaign;
	 camp.Id = 0;
	 camp.Type = '';
	 
	 var ses = Tv.Session;
	 ses.VisitorId = 0;
	 ses.Id = 0;
	 ses.UserId = 0;
	 
	 var p = Tv.Page;
	 p.Id = 0;
	 
	 var m = Tv.Meeting;
	 m.Id = 0;
	 m.Type = 0;
*/	 
	 
	 var evt = Tv.Event;
	 
	 // static members 
	 evt.Logging 		= true;
	 evt.CallType		= 'pixel';  // ajax / pixel
	 evt.PageContext 	= 'Page';
	 evt.MeetingContext	= 'Meeting';
	 evt.TagContext		= 'Tag';
	 
	 // static methods
	 evt.Log = function(context, eventId, params) {

		if (Tv.Event.Logging == false)  // Not intereseted in logging events
			return;
		 
		var defaultParams = Tv.Session.VisitorId + '/' +
							Tv.Session.Id + '/' +
							Tv.Session.UserId + '/' +
							Tv.Page.Id + '/' +
							eventId;
						
		if (context === Tv.Event.MeetingContext) {
			 defaultParams += Tv.Meeting.Id + '/' + Tv.Meeting.Type;
		} else if (context === Tv.Event.PageContext) {
			 defaultParams +=  Tv.Campaign.Id + '/' + Tv.Campaign.Type + '/' + Tv.Meeting.Id + '/' + Tv.Meeting.Type;
		} else if (context === Tv.Event.TagContext) {
			// NO-OP
		}
		
		if (params) {
			params = defaultParams + '/' + params + '/';
		} else {
			params = defaultParams + '/';
		}
	    
		evt.LogURL 		= 'http://' + Tv.Event.Host + '/trk/log';

		var logURI = evt.LogURL + context + 'Event' + '/' + params;
		
		if (evt.CallType == 'ajax') {
			evt.FireAjax(logURI);
		} else if (evt.CallType == 'pixel') {
			evt.FirePixel(logURI);
		} 
	};
	 
	 evt.FireAjax = function(logURI) {

		var eventCallBack = {
			success:OnLogEventSuccess,
			failure:OnLogEventFailure,
			argument:logURI
		};
		
		var _qs = "ct=ajax";
		YAHOO.util.Connect.asyncRequest("GET", logURI + '?' + _qs, eventCallBack)
		
		function OnLogEventSuccess(e) {};
		function OnLogEventFailure(e) {};
	};
	 
	 evt.FirePixel = function(logURI) {
		try {
			var _pix = document.createElement("img");

			if(_pix) {
				var _qs = "ct=pixel&magicid=" + (new Date()).getTime() + Math.ceil(Math.random() * 1000);

				_pix.width  = 1;
				_pix.height = 1;
				_pix.src = logURI + '?' + _qs;

				document.body.appendChild(_pix);
			}
		} catch(e) {};
	};

})();

// Tv.Tag class definition goes here
(function() {
	tag = Tv.Tag;
	
	PREFIX = '_t';
	SEPERATOR = ':';

	tag.Tagger = function(scope, name, value) {
		tns = PREFIX + SEPERATOR + escape ( scope ) + SEPERATOR + escape ( name ) + '=' + escape ( value );
		Tv.Event.Log(Tv.Event.TagContext, Tv.Event.Names['TAGGING'], tns);
	};
})();

 // Tv framework ends here 

