/**********************************************************************************************************************************
 *
 * Menu Scrolling Script
 *
 * (C) 2008 KandyDesigns.com
 *
 **********************************************************************************************************************************/


	var wop = 900; // this is the width of the page
	var wom = 1320;	// this is the width of the menu image
	var mxl = wom - wop; // amount that is hidden
	
	var minX =  wop - wom; 
	var leftS = -15;
	var rightS = minX + 15;
	
	var woc = 240; // width of cell
	var sca = wom - ( 2 * woc ); // scroll area; for a 900px wide wom, 120px woc, = 660
	
	var mul = mxl/sca;
	
	/*
	 * Okay, ScrollRight is horribly misnamed, I give you that.
	 *
	 * Parameters: e (element), a (scroll difference)
	 *
	 */

    function scrollRight (e, a)
    {
    	if (!window.event) { e.stopPropagation(); };
    	if (window.event) { window.event.cancelBubble = true; }
		var o = document.getElementById("scroller");
    	if (o)
    	{
        	var tl = o.targetLeft - a;
        	if (tl > 0) { tl = 0; }
        	if (tl < minX) { tl = minX; };
        	o.targetLeft = Math.round(tl);
        }
    	return false;
	}
	
	/*
	 * This is the function that actually scrolls the menu; it checks to see if it has reached the
	 * target, and if not, continues to scroll there in half increments.
	 *
	 * It also controls the appearance of the glowing scroll icons :-)
	 */
	function goToTarget()
	{
    	var o = document.getElementById("scroller");
    	if (o)
    	{
        	var curLeft = o.offsetLeft; /* o.style.pixelLeft; */
        	var targetLeft = o.targetLeft;
        	
        	if ( Math.abs(curLeft - targetLeft ) > 5 );
        	{
        		curLeft = curLeft + (( targetLeft - curLeft ) / 2 );
        		o.style.left = curLeft + "px" ;
        		
        	}
    	}
    	
    	if ( curLeft < leftS )
    	{
    		document.getElementById("scroll_left").style.visibility="visible";
    	}
    	else
    	{
    		document.getElementById("scroll_left").style.visibility="hidden";
    	}
    	
    	if ( curLeft > rightS )
    	{
    		document.getElementById("scroll_right").style.visibility="visible";
    	}
    	else
    	{
    		document.getElementById("scroll_right").style.visibility="hidden";
    	}
    	
	}
	
	/*
	 * And the final piece - this gets the end user's mouse coordinates (X only), and
	 * calculates where the target /should/ be.
	 *
	 */
	
    function scrollTheMenu (evnt)
    {
    	// things get a little tricky here
    	// different browsers do some different things here!
    	//
    	// IE has window.event; FF/Safari have the event in (e).
    	//
    	if (!window.event) { evnt.stopPropagation(); };	// FF/S
    	if (!evnt) { var evnt = window.event; };		// IE
    	
    	if (evnt.currentTarget && evnt.offsetX)
    	{
    		return false;	// I can't support Safari at the moment... it is too inconsistent
    						// with regards to IE or Firefox (shock!)
    	}
    	
    	var x;

		// go find our scroller        
        var o = document.getElementById("scroller");

        // and our last mouse position - not sure this is really all that
        // important?
    	var lastX = o.lastX;
    	
    	 
    	if (!evnt.offsetX) 
    	{ 
    		x = evnt.layerX; 								// FF
    	} 
    	else 
    	{ 
   			x = evnt.offsetX; 								// IE 
    	};
    	
    	// by this point, X is the position I'm hovering over on the scrolling menu....
    	// NOT over its container. (grrr). 

    	x = x - woc;
    	x = x * mul;									// should be down to a left coord for the menu
    	

    	if (Math.abs(x-lastX) > 0) 
    	{
    	
        	var tl = -x;								// tl needs x to be negative
        	if (tl > 0) { tl = 0; }						// can't scroll too far left
        	if (tl < minX) { tl = minX; };				// or right
        	
        	o.targetLeft = Math.round(tl);				// round to get a nice even pixel
    	}
    	
    	evnt.cancelBubble = true;							// IE; apparently FF/S don't care
    	
    	return false;									// this is for FF/S.

    }
    

