﻿<?xml version="1.0" encoding="utf-8" ?> 

<!--

///////////////////////////////////////////////////////////////////////
//     This script was designed by Erik Arvidsson for WebFX          //
//                                                                   //
//     For more info and examples see: http://webfx.eae.net          //
//     or send mail to erik@eae.net                                  //
//                                                                   //
//     Feel free to use this code as lomg as this disclaimer is      //
//     intact.                                                       //
///////////////////////////////////////////////////////////////////////

This behavior can be used to mirror the scrolling of another element

-->

<public:component lightWeight="true">
<public:property name="syncTo" put="setSyncTo" get="getSyncTo" />
<public:property name="syncDirection" />
<script language="JScript">
//<[[CDATA[

// declare two private variables
var sSyncTo;
var oSyncTo;

// set syncTo
function setSyncTo(sToElementId) {
	// remove old sync to
	if (oSyncTo != null)
		oSyncTo.detachEvent("onscroll", onScroll);

	sSyncTo = sToElementId;
	// look up the element with sToElementId in the real html document
	oSyncTo = element.document.getElementById(sToElementId);
	
	if (oSyncTo != null)
		oSyncTo.attachEvent("onscroll", onScroll);
}

// get syncTo
function getSyncTo() {
	return sSyncTo;
}


// This is a function that returns a function that is used
// in the event listener
function onScroll() {
	if (syncDirection == "horizontal" || syncDirection == "both")
		element.scrollLeft = event.srcElement.scrollLeft;
	if (syncDirection == "vertical" || syncDirection == "both")
		element.scrollTop = event.srcElement.scrollTop;
}

//]]>
</script>
</public:component>
