/**
 * 
 * DeepStatTracker JS API used to implement many tracking systems through a single
 * interface.
 */
function _hbPageView( pageName , contentCategory ) {
	var iLength     = (contentCategory.length - 1);
	var iLastSlash  = contentCategory.lastIndexOf( '/' );
	
	if ( iLength > iLastSlash ) {
		contentCategory += '/';
	}
	var sPagePath = contentCategory + pageName;
	var oParams = { sUrl: sPagePath };
	DSTAPI_Proxy.call( oParams );
}

function _hbLink( pageName , contentCategory ) {
	var iLength     = (contentCategory.length - 1);
	var iLastSlash  = contentCategory.lastIndexOf( '/' );
	
	if ( iLength > iLastSlash ) {
		contentCategory += '/';
	}
	var sPagePath = contentCategory + pageName;
	var oParams = { sUrl: sPagePath };
	DSTAPI_Proxy.call( oParams );
}

/**
 * DSTAPI_Proxy.call Function
 * 
 * Function that allows for calls to be permitted based on object based
 * parameter options.
 * 
 * When you send a parameter through the oParams object it actually
 * overrides the defaultSettings parameters which are sent to the 
 * vendor api thus allowing for calls to be made with only one function call 
 * throughout the entire codebase this also allows for extendability for
 * future functionality requirements.
 * 
 * Valid parameters include:
 * {
 *   sType: '',
 *   sUrl: '', // Faking a url value.. format: turbonick/nickpicks (NOTE: no prefixed /)
 * }
 * 
 * EXAMPLES 
 * --------
 * 
 * Normal: DSTAPI_Proxy.call();
 * 
 */

var DSTAPI_Proxy = {
	defaultSettings: {
		sType: 'page', // Valid strings
		sUrl:  ''     // Optional (fakeUrl Functionality)
	},
	call: function(oParams) {
		DSTAPI_Proxy.defaultSettings = DSTAPI_Proxy.extend( DSTAPI_Proxy.defaultSettings , oParams );
		DSTAPI_Proxy.callVendors();
	},
	callVendors: function() {
		var sLocation = window.location.toString();
		// Turns of calls for the stats when on the deepend domain
		//if( sLocation.indexOf( 'deepend.com.au' ) == -1 ) {
			/**
			 * Vendor Calls Go Below Here
			 */
			DSTAPI_Omniture.call( DSTAPI_Proxy.defaultSettings );
		//}
	},

// Not being used as of yet but there for future expandability
// in case of a system that requires there be a file called a
// specific name
	include: function( sFile ) {
		var script  = document.createElement('script');  
		script.src  = file;
		script.type = 'text/javascript';
		script.defer = true;
		document.getElementsByTagName('head').item(0).appendChild(script);
	},
	extend: function( destination , source ) {
		for (var property in source) {
			destination[property] = source[property];
		}
		return destination;
	}
}

/**
 * Included Vendor API's
 * 
 * Include using the DSTAPI_Proxy.include( fileName ); command.
 */

/**
 * 
 * VENDOR API's
 * 
 * Every vendor api must have a call function from here 
 * you can then decide where you want to go based on the 
 * options set in oParams
 * 
 * Customisable functionality goes into the vendor api's 
 * unless its something generic which can go into the
 * global, but for the most part i suggest putting all 
 * logic into the vendor api
 * 
 */

var DSTAPI_Omniture = {
	call: function(oParams) {
		if ( oParams.sType == 'page' ) {
			var sChannelCall = '';
			var sPageCall    = '';
			if ( oParams.sUrl != '' ) {
				sPageCall    = oParams.sUrl;
				var aUrl = oParams.sUrl.split( '/' );
				if ( aUrl.length > 0 ) {
					sChannelCall = aUrl[0];
				}
			}
			DSTAPI_Omniture.callPage( sChannelCall, sPageCall );
			//alert( 'callPage' );
		}
	},
	callPage: function( sChannel , sPage ) {
		com.mtvi.reporting.Account={
			name:'vianickaustralia',
			dynamicAccountSelection:'true',
			dynamicAccountList:'vianickaustraliadev=mtv-d,mtv-q'
		};
		com.mtvi.reporting.Controller.initialize();		
		
		if ( sChannel == '' ) {
			sChannel = com.mtvi.metadata.getDefaultChannel();
		}
		if ( sPage == '' ) {
			sPage = com.mtvi.metadata.getDefaultPageName();
		}
		if ( sChannel == '/' ) {
			sChannel = '/home';
		}
		if ( sPage == '/' ) {
			sPage = '/home';
		}
		
		com.mtvi.reporting.Controller.sendCall(
			{
				pageName: sPage,
				channel: sChannel,
				hier1:	sPage
			}
		);
	}
}