// JB ThumbMainProductImageRollover, entire file is new

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

/**
 * 
 * @param string PhotoId the image src to update the product src preview with
 * @param string ContentId The product id the user has hovered over
 * @param Event event A javascript Event object
 */
function product_rollover(PhotoId, underimage_text, undertitle_text, event)
{

	// move the div

		if( !event ) { 
			event = window.event; 
		}
	
		var MouseYPos = getCursorPosition(event);
		
		document.getElementById('large_prodimage').style.left = "0";
		
		//var spaceAbove = 0;// amount of space above the visible space
		var spaceAbove = getScrollingPosition();	
		
		var spaceAbove = getScrollingPosition();// + 00 - 0*(getCursorPosition(event) - getScrollingPosition()) ;	
		
		var pos = parseInt(spaceAbove+50);
		
		if(pos>0)
		{
			document.getElementById('large_prodimage').style.top = pos + "px";
		}
		
		if(spaceAbove==0)
		{
			document.getElementById('large_prodimage').style.top = 0;
		}


	if(document.getElementById('prod_descr'))
	{
		document.getElementById('prod_descr').innerHTML = underimage_text;
	}
	
		if(document.getElementById('2prod'))
	{
		document.getElementById('2prod').innerHTML = undertitle_text;
	}

	
	if(PhotoId == "")
	{
		var PhotoId = "/images/prod_listing/prod_default.gif";
	}

	if (document.getElementById('product_photo')) document.getElementById('product_photo').src = 'image.php?type=P&' + PhotoId;

}

/*
//Safari Browser Check
//This should now be redundant! 17.04.2007 See trac ticket:27
function IsSafari()
{
	var agt=navigator.userAgent.toLowerCase();
   	var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    return is_safari;
}


//Konqueror Browser Check
//This should now be redundant! 17.04.2007 See trac ticket:27
function IsKhtml()
{
	var agt=navigator.userAgent.toLowerCase();
   	var is_khtml  = (is_safari || is_konq);
   	return is_khtml;
		
}*/

function getScrollingPosition()
{
	  //alert("getScrollingPosition");	
		
	 var position = [0, 0];
	
	 if (typeof window.pageYOffset != 'undefined')
	 {
	   position = window.pageYOffset;
	
	 }
	 else if (typeof document.documentElement.scrollTop
	     != 'undefined' && document.documentElement.scrollTop > 0)
	 {
	   position =  document.documentElement.scrollTop;
	 }
	
	 else if (typeof document.body.scrollTop != 'undefined')
	 {
	   position =  document.body.scrollTop;
	 }
//return 0;
	 return position;
}


/**
 *
 * @param Event e We are expecting here a javascipt model 'Event' object
 * @return int the Y coord for the mouse position
 */
function getCursorPosition(e)
{

	// JB all below patch for FF
	if ( navigator.userAgent.indexOf('Firefox') != -1 ) {
		if (!e)
			var e = window.event||window.Event;
		
		if( typeof e.pageX != "undefined")
		{
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
		else
		{
			mouseX = e.clientX + document.body.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop;
		}
		// end JB
        }
	else {
		if (!e || typeof e == "undefined") var e = window.event||window.Event;

		var mouseX = e.pageX,
	        mouseY = e.pageY; 
	}

	return mouseY; //we only want the Y coord for the mouse

}
