// JavaScript Document

//Define s_gi
function s_gi(accountname){
};

//Define YWATracker
function YWATracker(accountname){
};

var s = s_gi(accountname)
var _gaq = _gaq || [];
var YWATracker = YWATracker(accountname);

/*OMNITURE CONFIGURATIONS */
var internalfilterurl = ",jamesomalley.net";
var visitornamespace  = "client";
var trackingserver    = "pretendclient";
var campaignparam     = "cid";
/* ACTION TRACKING */

/* Track Asset Prints */

$('a.print_button').bind('click', function () {
	var interactiontype = "print";
	
	if ($(this).attr('title')){
			var linkname = $(this).attr('title');
		}else{
			console.log("linkname not set -- will not be tracked");
		}
		
	if (typeof SITE_ANALYTICS == 'undefined' || typeof linkname == 'undefined'){
		console.log(interactiontype + " didnt work");
	}else if(SITE_ANALYTICS == 'OMTR'){
		
			s.linkTrackVars = "events,eVar10,products,prop30";
			s.linkTrackEvents = "event5";
			s.events = "event5";
			s.eVar10 = linkname;
			s.prop30 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
		
	}else if (SITE_ANALYTICS == 'GA'){
		
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
		
	}else if (SITE_ANALYTICS == 'YWA'){
				
			YWA.setAction("05");
			YWA.setCF(10, linkname);
			YWA.setCF(30, linkname);
			YWATracker.submit_action();
		
	}else if (SITE_ANALYTICS == 'OMTR,GA' || SITE_ANALYTICS == 'GA,OMTR'){
		
		    s.linkTrackVars = "events,eVar10,products,prop30";
			s.linkTrackEvents = "event5";
			s.events = "event5";
			s.eVar10 = linkname;
			s.prop30 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
		
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);	
	}
});

/* Track Asset Downloads */

$('a.download_button').bind('click', function () {
	
	var interactiontype = "download";
	if ($(this).attr('title')){
			var linkname = $(this).attr('title');
		}else{
			console.log("linkname not set -- will not be tracked");
		}
		
	if (typeof SITE_ANALYTICS == 'undefined'|| typeof linkname == 'undefined'){
		console.log(interactiontype + " didnt work");	
	}else if(SITE_ANALYTICS == 'OMTR'){

			s.linkTrackVars = "events,eVar11,products,prop31";
			s.linkTrackEvents = "event6";
			s.events = "event6";
			s.eVar11 = linkname;
			s.prop31 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
		
	}else if (SITE_ANALYTICS == 'GA'){
		
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
		
	}else if (SITE_ANALYTICS == 'YWA'){
		
			YWA.setAction("06");
			YWA.setCF(11, linkname);
			YWA.setCF(31, linkname);
			YWATracker.submit_action();
		
	}else if (SITE_ANALYTICS == 'OMTR,GA' || SITE_ANALYTICS == 'GA,OMTR'){
		
			/*OMTR CODE */
			s.linkTrackVars = "events,eVar11,products,prop31";
			s.linkTrackEvents = "event6";
			s.events = "event6";
			s.eVar11 = linkname;
			s.prop31 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
		
			/*GA CODE*/
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
	}
});

/* Track Clicks to Social Media */

$('a.social-media').bind('click', function () {
	
	var interactiontype = "social-media";
	if ($(this).attr('title')){
			var linkname = $(this).attr('title');
		}else{
			console.log("linkname not set -- will not be tracked");
		}
	
	if (typeof SITE_ANALYTICS == 'undefined'|| typeof linkname == 'undefined'){
		console.log(interactiontype + " didnt work");	
	}else if (SITE_ANALYTICS == 'OMTR'){
	
			s.linkTrackVars = "events,eVar14,products,prop33";
			s.linkTrackEvents = "event8";
			s.events = "event8";
			s.eVar14 = linkname;
			s.prop33 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
		
	}else if (SITE_ANALYTICS == 'GA'){
	
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
		
	}else if (SITE_ANALYTICS == 'YWA'){
		
			YWA.setAction("08");
			YWA.setCF(14, linkname);
			YWA.setCF(33, linkname);
			YWATracker.submit_action();
		
	}else if (SITE_ANALYTICS == 'OMTR,GA' || SITE_ANALYTICS == 'GA,OMTR'){
		
			s.linkTrackVars = "events,eVar14,products,prop33";
			s.linkTrackEvents = "event8";
			s.events = "event8";
			s.eVar14 = linkname;
			s.prop33 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
			
			
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
	}	
});
/* Track Asset Interactions */

$('a.interact_element').bind('click', function () {
	
	var interactiontype = "interaction";
	if ($(this).attr('title')){
			var linkname = $(this).attr('title');
		}else{
			console.log("linkname not set -- will not be tracked");
		}
	
	if (typeof SITE_ANALYTICS == 'undefined'|| typeof linkname == 'undefined'){
		console.log(interactiontype + " didnt work");	
	}else if (SITE_ANALYTICS == 'OMTR'){
	
			s.linkTrackVars = "events,eVar12,products,prop32";
			s.linkTrackEvents = "event7";
			s.events = "event7";
			s.eVar12 = linkname;
			s.prop32 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
		
	}else if (SITE_ANALYTICS == 'GA'){
	
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
		
	}else if (SITE_ANALYTICS == 'YWA'){
		
			YWA.setAction("07");
			YWA.setCF(12, linkname);
			YWA.setCF(32, linkname);
			YWATracker.submit_action();
		
	}else if (SITE_ANALYTICS == 'OMTR,GA' || SITE_ANALYTICS == 'GA,OMTR'){
		
			s.linkTrackVars = "events,eVar12,products,prop32";
			s.linkTrackEvents = "event7";
			s.events = "event7";
			s.eVar12 = linkname;
			s.prop32 = linkname;
			s.products = ";" + linkname;
			s.tl(this, 'o', interactiontype + ' clicks');
			
			
			_gaq.push(['setAccount', accountname]);
			_gaq.push(['_trackEvent', interactiontype, linkname]);
	}	
});

/* Track Page Name */

function buildPageName() {
	
	var interactiontype = "pagetracking";
	
	if (typeof SITE_ANALYTICS == 'undefined'){
		
		console.log(interactiontype + " didnt work");	
	
	}else{
		 
		pagename = window.location.href.replace(/http:/g,'').replace(/\.net/g,'').replace(/www\./g,'').replace(/\.html/g,'').replace(/#/g,'').replace(/\//g,':').replace(/::/g,'').replace(/_/g,'-');
		channel  = pagename.split(':')[0] + ':' + pagename.split(':')[1];
	}
};

buildPageName();

/* Execute Page Code */
	
if (SITE_ANALYTICS == 'OMTR'){
	var s = s_gi(accountname)
	var scripts= []
	scripts.push('/js/sample_s_code.js');
	for(src in scripts)
	document.write('<scri'+'pt src="'+scripts[src]+'" type="text/javascript"></sc'+'ript>');
	
}else if (SITE_ANALYTICS == 'GA'){
	var _gaq = _gaq || [];
  	_gaq.push(['_setAccount', accountname]);
  	_gaq.push(['_trackPageview', pagename.replace(/%20/g, ' ')]);

  		(function() {
    		var ga = document.createElement('script'); 
			ga.type = 'text/javascript'; 
			ga.async = true;
    		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  		})();

}else if (SITE_ANALYTICS == 'YWA'){
 	
	var scripts= []
	scripts.push('http://d.yimg.com/mi/ywa.js');
	for(src in scripts)
	document.write('<scri'+'pt src="'+scripts[src]+'" type="text/javascript"></sc'+'ript>');
	    
	YWATracker.setDocumentName(pagename);
	YWATracker.setDocumentGroup(channel);
	YWATracker.submit();

}else if (SITE_ANALYTICS == 'OMTR,GA' || SITE_ANALYTICS == 'GA,OMTR'){
	/* OMTR CODE */
	var s = s_gi(accountname)
	var scripts= []
	scripts.push('/js/sample_s_code.js');
	for(src in scripts)
	document.write('<scri'+'pt src="'+scripts[src]+'" type="text/javascript"></sc'+'ript>');
	
	// document.write( '<script language="javascript" src="/js/sample_s_code.js" />' );

	
	/*GA CODE */
	var _gaq = _gaq || [];
  	_gaq.push(['_setAccount', accountname]);
  	_gaq.push(['_trackPageview', pagename.replace(/%20/g, ' ')]);

  		(function() {
    		var ga = document.createElement('script'); 
			ga.type = 'text/javascript'; 
			ga.async = true;
    		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  		})();
};
