/* WebTrends ScrollDepth Plug-in
   Asset ID: 1361814098901
   Last Modified: 12/7/2015
*/

/*
This plugin will set a value of scroll depth by quartiles. It will use WT.z_scrdpth=25,50,75,95.

To use this plugin:
 In the inline html or webtrends.load.js file, add a call to the plugin:

        plugins:{
            scroll_depth:{src:"./Insert_Path_Here/webtrends.scroll_depth.js"}
        }
*/

(function() {
	ScrollDepthFunctions= {
		doWork:function(dcs, options) {
			if (ScrollDepthFunctions.jQueryVersion('1.4.3'))	{
				var tagSent = [false, false, false, false];
				jQuery(window).scroll([],function(){
				
				     //Figure out all the dimensions
				    var wintop = jQuery(window).scrollTop(), docheight = jQuery(document).height(), winheight = jQuery(window).height();
				           var percent = wintop/(docheight-winheight);
				
				    //Set the percentage where events should fire
				    var scrolltrigger = [0.25,0.50,0.75,0.95];
				    
				    for (x = 0; x < scrolltrigger.length; x++)  {
				                
				                if ((percent >= scrolltrigger[x]) && (!tagSent[x]))  {
				                     dcsMultiTrack("WT.z_scrdpth",scrolltrigger[x]*100,'WT.dl','60');
				                     tagSent[x] = true;
				                }
				    }
				});
			}
			else {
				console.log("jQuery not found, or version lower than '1.4.3'. Cannot track scroll depth.");
			}
		},
		jQueryVersion:function(v)	{
			var jv, varr = [], jvarr = [], len, i;
  		if (typeof(jQuery) !== 'undefined') {
    		if (typeof(v) === 'undefined') {
      		return true;
    		}
    		jv = jQuery.fn.jquery;
    		varr = v.split('.');
    		jvarr = jv.split('.');
    		len = varr.length;
    		if (jvarr.length < len) {
      		len = jvarr.length;
    		}
    		for (i = 0; i < len; i++) {
      		if (jvarr[i] < varr[i]) {
      	  	return false;
      		}
    		}
    		return true;
  		}
		}
	}
})();

Webtrends.registerPlugin("scroll_depth",ScrollDepthFunctions.doWork);