
window.addEvent('domready', function() {


	logIt('Ga code loded ');
	logIt(' sGaUserName ' + sGaUserName );
	logIt(' sGaUserType ' + sGaUserType );

	//console.log('   gaq  '  +     _gaq );


});


/**
 * right we will have links in many pages that might
 * be slides or tabs or whatever so we will  need  to attach 
 * listeners to them 
 * 
 * the array is created in the main php file and inout as a  comma seperated param list
 *  
 */



window.addEvent('domready', function() {

	//console.log(aryOfClassesToBeTracked );

	for(var k = 0;  k < aryOfClassesToBeTracked.length; k++)
	{




		$$(aryOfClassesToBeTracked[k]).each(function(el){

			el.addEvents({
				'mouseover' : function() {
				//console.log(el);
				// fireClicked(el);

			},
			'mouseout' : function() {
			},
			'click' : function() {
				fireClicked(el);
			}
			});
		});

	}
});


/**
 * record what we can from the item
 * @param objClicked
 */

function  fireClicked(objClicked)
{ 
	//alert('test');
	/**logIt('id  '  +   objClicked.id);
	logIt('href  '  +   objClicked.href);
	 **/
	var obj = getRecordObject(objClicked);

	//console.log( objClicked.id);
	//console.log(obj);

	recordAjax(obj);


	/**
	 * do add an ajax post for the click
	 * 
	 */


	return false; 


}


function recordAjax(objToRecord)
{
	//console.log(objToRecord);

	window.addEvent('domready', function() {
		// send to this url 

		var url = document.location.href ;
		/**
		console.log('sm_base_url  '  + sm_base_url);
		console.log(' url  '  +  url);
		 */
/**
 * here we send an ajax post to the current page
 * this is picked up by the system plaugin and then 
 * we record the tab or lside in the data base
 */

		 
		//  url   +=  '&track_mode=ajax&tab_title=' + objToRecord.title  + "&origin=record_ajax";
		
		// console.log(' url  '  +  url);
		
		
		var x = new Request({
			url: url, 
			method: 'post',
			data :{'track_mode': 'ajax' , 'slide':  objToRecord.slide ,  'tab' :objToRecord.tab  , 'do' : objToRecord.cssClass   },
			onRequest: function(){
		},
		onSuccess: function(responseText){
		},
		onFailure: function(){
			//alert('error');

		}                
		}).send();;
	});


}

function getRecordObject(objClicked)
{

	var objRecord = {};
	objRecord.id    = objClicked.get('id');
	if(objRecord.id == undefined  ||  objRecord.id == '' )
	{
		objRecord.id  = 'random-track-id-' + Math.floor(Math.random()*500000);
	}
	objRecord.href    = objClicked.href;
	/**
	 * we need to sort out here what is a tab title
	 * and what is a slide title 
	 */
	
	objRecord.title    = objClicked.innerHTML;
	//objRecord.tab    = objClicked.innerHTML;
	objRecord.slide    = 	'none';  // objClicked.innerHTML;
	objRecord.tab    	= 'none';  // objClicked.innerHTML;
	objRecord.cssClass    = objClicked.get('class');


	return  objRecord ;


}

