var imageDivs = '';
var numberOfElements = 0;
var shown = 0;
var carousel = '';
var kwmap = '';
var kwmenu = '';


function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


window.addEvent('domready', function(){
  
	carousel = $('carousel');
	//cross = $('cross');
	kwmap = $('kwmap');
	kwmenu = $('kwmenu');
	//drop1 = $('drop1');
	imageDivs = carousel.getElementsByTagName("div"); 
	numberOfElements = imageDivs.length; 
	setInterval('startCarousel()',400);
	//kwmap.addEvent('mouseup', onMouseClick.bindWithEvent( kwmap )); 
	
});


function handleEvent(oEvent) {
	
                var oTextbox = document.getElementById("txt1");
				oEvent = oEvent || window.event;
	            var tgt = oEvent.target || oEvent.srcElement;
	            if (tgt)
	            {
					
					
				  if(tgt.id)
				  {
					  imageDivs = carousel.getElementsByTagName("div"); 
	                  numberOfElements = imageDivs.length; 
					  //alert("ahello " + numberOfElements);
					for(i=0; i < numberOfElements; i++)
					{
						
						imageDivsStyle = imageDivs[ i ].style;  
						imageDivsStyle.position='absolute'; 
						if(i == tgt.id)
						{
						  //alert("hello " + mx);
						  imageDivsStyle.zIndex = 1;
						}
						else
						{
						  imageDivsStyle.zIndex = 0;
						}
					}
				   //oTextbox.value += "\n>" + tgt.id;
				  }
				}

}

function startCarousel()
{
	     kwmenu = $('kwmenu');
		imageDivsStyle = kwmenu.style;  
		imageDivsStyle.position='absolute';
		mx = f_scrollLeft();
		if(mx == 0)
		{
		    if (window.pageYOffset)
                mx = window.pageXOffset;
            else
                mx = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
		}
		
		my = f_scrollTop();
		if(my == 0)
		{
			if (window.pageYOffset)
                my = window.pageYOffset;
            else
                my = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}

		if(mx != parseInt(imageDivsStyle.left) || my != parseInt(imageDivsStyle.top))
		{
			imageDivsStyle.left = mx + "px"; 
		    imageDivsStyle.top = my + "px";
		}
}


