// JQuery Mouse Tracker by 33Delivered
// This function tracks the mouse cursor and manipulates the carousels its attached to accordingly 
// Sets direction, acceleration, etc, based on mouse position over parent container item
// Version 1.0 

jQuery.fn.setMouseListener = function() {
    w = $(".scrollWrapper").width();	
	cl = Math.round(w / 4); //left hotspot limit
	cr = w-cl;				//right hostspot limit
	a = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollStep");
	ai = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollInterval");
	
	
	var defaulta = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollStep");
	var defaultai = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollInterval");
	
	var defaulta2 = $(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollStep");
	var defaultai2 = $(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollInterval");
	
	
	$(this).hover(function(){ 

	$(this).mousemove(function(e){
	mypos = $(this).offset();
	var x = e.pageX - mypos.left;
    var y = e.pageY - mypos.top;

	 
    if(x>cr) {
	  	dir = "endlessloopright";
		//a = (x-c) * accel;	//no longer changing acceleration based on position 		
	  	a=defaulta;
		cursor = "e-resize";
    }	  
    else if(x<cl) {
	  	dir = "endlessloopleft";
		//a = Math.abs( (x-c) * accel);	  	//no longer changing acceleration based on position 		
	  	a=defaulta;
		cursor = "w-resize";
    }    	
    else if(x<cr && x>cl)
    {
    		a=0;
    		dir="";    		
    }
	 
	 
	 var as = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollStep");
	 var ais = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollInterval");
	 var aid = $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollDirection");
	 
	 
	 if(as != a) {
		//console.log("Setting Carousel autoScrollStep -> "+as);
	  	$(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollStep",a); 
		$(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollStep",a);  
	 }
	 
	 if(ais!=ai) {
		// console.log("Setting Carousel autoScrollInterval -> "+ais);
	  	$(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollInterval",ai);	
		$(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollInterval",ai);	  
	 }
	 if(dir && aid != dir) { 
	 	//console.log("Setting Carousel Direction -> "+dir);
	  	$(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollDirection",dir);
		$(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollDirection",dir);
		
	 }
	  
   }); 
},function() {	
	  $(this).find('img').css('cursor','auto');
	  $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollStep",defaulta);
	  $(this).find("div#makeMeScrollable").smoothDivScroll("option","autoScrollInterval",defaultai);
	  $(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollStep",defaulta2);
	  $(this).find("div#makeMeScrollable2").smoothDivScroll("option","autoScrollInterval",defaultai2);
  });



};
